diff options
author | Richard Jones <rjones@redhat.com> | 2009-04-07 10:25:46 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2009-04-07 10:25:46 +0100 |
commit | 6085137e65cb63aaf725207f2929a571d1149420 (patch) | |
tree | 95b1346a4be550a8c18c8123986fe549390618a0 /src | |
parent | 7ea56c8d0bca01a602df8e87e52d90c5b44e2cc2 (diff) | |
download | libguestfs-6085137e65cb63aaf725207f2929a571d1149420.tar.gz libguestfs-6085137e65cb63aaf725207f2929a571d1149420.tar.xz libguestfs-6085137e65cb63aaf725207f2929a571d1149420.zip |
Implement simple lvs/vgs/pvs commands.
Diffstat (limited to 'src')
-rwxr-xr-x | src/generator.ml | 35 | ||||
-rw-r--r-- | src/guestfs-actions.c | 219 | ||||
-rw-r--r-- | src/guestfs-actions.h | 3 | ||||
-rw-r--r-- | src/guestfs_protocol.c | 33 | ||||
-rw-r--r-- | src/guestfs_protocol.h | 33 | ||||
-rw-r--r-- | src/guestfs_protocol.x | 21 |
6 files changed, 333 insertions, 11 deletions
diff --git a/src/generator.ml b/src/generator.ml index 69981f04..d5989754 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -135,43 +135,56 @@ The full partition device names are returned, eg. C</dev/sda1> This does not return logical volumes. For that you will need to call C<guestfs_lvs>."); -(* - ("pvs", (RPVList "physvols", P0), 9, [], + ("pvs", (RStringList "physvols", P0), 9, [], "list the LVM physical volumes (PVs)", "\ List all the physical volumes detected. This is the equivalent -of the L<pvs(8)> command."); +of the L<pvs(8)> command. - ("vgs", (RVGList "volgroups", P0), 10, [], +This returns a list of just the device names that contain +PVs (eg. C</dev/sda2>). + +See also C<guestfs_pvs_full>."); + + ("vgs", (RStringList "volgroups", P0), 10, [], "list the LVM volume groups (VGs)", "\ List all the volumes groups detected. This is the equivalent -of the L<vgs(8)> command."); +of the L<vgs(8)> command. + +This returns a list of just the volume group names that were +detected (eg. C<VolGroup00>). + +See also C<guestfs_vgs_full>."); - ("lvs", (RLVList "logvols", P0), 11, [], + ("lvs", (RStringList "logvols", P0), 11, [], "list the LVM logical volumes (LVs)", "\ List all the logical volumes detected. This is the equivalent -of the L<lvs(8)> command."); -*) +of the L<lvs(8)> command. + +This returns a list of the logical volume device names +(eg. C</dev/VolGroup00/LogVol00>). + +See also C<guestfs_lvs_full>."); ("pvs_full", (RPVList "physvols", P0), 12, [], "list the LVM physical volumes (PVs)", "\ List all the physical volumes detected. This is the equivalent -of the L<pvs(8)> command."); +of the L<pvs(8)> command. The \"full\" version includes all fields."); ("vgs_full", (RVGList "volgroups", P0), 13, [], "list the LVM volume groups (VGs)", "\ List all the volumes groups detected. This is the equivalent -of the L<vgs(8)> command."); +of the L<vgs(8)> command. The \"full\" version includes all fields."); ("lvs_full", (RLVList "logvols", P0), 14, [], "list the LVM logical volumes (LVs)", "\ List all the logical volumes detected. This is the equivalent -of the L<lvs(8)> command."); +of the L<lvs(8)> command. The \"full\" version includes all fields."); ] (* Column names and types from LVM PVs/VGs/LVs. *) diff --git a/src/guestfs-actions.c b/src/guestfs-actions.c index e3598eb5..3446a2d2 100644 --- a/src/guestfs-actions.c +++ b/src/guestfs-actions.c @@ -595,6 +595,225 @@ char **guestfs_list_partitions (guestfs_h *g) return rv.ret.partitions.partitions_val; } +struct pvs_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_pvs_ret ret; +}; + +static void pvs_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct pvs_rv *rv = (struct pvs_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_pvs: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_pvs: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_pvs_ret (xdr, &rv->ret)) { + error (g, "guestfs_pvs: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +char **guestfs_pvs (guestfs_h *g) +{ + struct pvs_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_pvs called from the wrong state, %d != READY", + g->state); + return NULL; + } + + memset (&rv, 0, sizeof rv); + + serial = dispatch (g, GUESTFS_PROC_PVS, NULL, NULL); + if (serial == -1) + return NULL; + + rv.cb_done = 0; + g->reply_cb_internal = pvs_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_pvs failed, see earlier error messages"); + return NULL; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_PVS, serial) == -1) + return NULL; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return NULL; + } + + /* caller will free this, but we need to add a NULL entry */ + rv.ret.physvols.physvols_val = safe_realloc (g, rv.ret.physvols.physvols_val, rv.ret.physvols.physvols_len + 1); + rv.ret.physvols.physvols_val[rv.ret.physvols.physvols_len] = NULL; + return rv.ret.physvols.physvols_val; +} + +struct vgs_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_vgs_ret ret; +}; + +static void vgs_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct vgs_rv *rv = (struct vgs_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_vgs: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_vgs: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_vgs_ret (xdr, &rv->ret)) { + error (g, "guestfs_vgs: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +char **guestfs_vgs (guestfs_h *g) +{ + struct vgs_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_vgs called from the wrong state, %d != READY", + g->state); + return NULL; + } + + memset (&rv, 0, sizeof rv); + + serial = dispatch (g, GUESTFS_PROC_VGS, NULL, NULL); + if (serial == -1) + return NULL; + + rv.cb_done = 0; + g->reply_cb_internal = vgs_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_vgs failed, see earlier error messages"); + return NULL; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_VGS, serial) == -1) + return NULL; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return NULL; + } + + /* caller will free this, but we need to add a NULL entry */ + rv.ret.volgroups.volgroups_val = safe_realloc (g, rv.ret.volgroups.volgroups_val, rv.ret.volgroups.volgroups_len + 1); + rv.ret.volgroups.volgroups_val[rv.ret.volgroups.volgroups_len] = NULL; + return rv.ret.volgroups.volgroups_val; +} + +struct lvs_rv { + int cb_done; /* flag to indicate callback was called */ + struct guestfs_message_header hdr; + struct guestfs_message_error err; + struct guestfs_lvs_ret ret; +}; + +static void lvs_cb (guestfs_h *g, void *data, XDR *xdr) +{ + struct lvs_rv *rv = (struct lvs_rv *) data; + + if (!xdr_guestfs_message_header (xdr, &rv->hdr)) { + error (g, "guestfs_lvs: failed to parse reply header"); + return; + } + if (rv->hdr.status == GUESTFS_STATUS_ERROR) { + if (!xdr_guestfs_message_error (xdr, &rv->err)) { + error (g, "guestfs_lvs: failed to parse reply error"); + return; + } + goto done; + } + if (!xdr_guestfs_lvs_ret (xdr, &rv->ret)) { + error (g, "guestfs_lvs: failed to parse reply"); + return; + } + done: + rv->cb_done = 1; + main_loop.main_loop_quit (g); +} + +char **guestfs_lvs (guestfs_h *g) +{ + struct lvs_rv rv; + int serial; + + if (g->state != READY) { + error (g, "guestfs_lvs called from the wrong state, %d != READY", + g->state); + return NULL; + } + + memset (&rv, 0, sizeof rv); + + serial = dispatch (g, GUESTFS_PROC_LVS, NULL, NULL); + if (serial == -1) + return NULL; + + rv.cb_done = 0; + g->reply_cb_internal = lvs_cb; + g->reply_cb_internal_data = &rv; + main_loop.main_loop_run (g); + g->reply_cb_internal = NULL; + g->reply_cb_internal_data = NULL; + if (!rv.cb_done) { + error (g, "guestfs_lvs failed, see earlier error messages"); + return NULL; + } + + if (check_reply_header (g, &rv.hdr, GUESTFS_PROC_LVS, serial) == -1) + return NULL; + + if (rv.hdr.status == GUESTFS_STATUS_ERROR) { + error (g, "%s", rv.err.error); + return NULL; + } + + /* caller will free this, but we need to add a NULL entry */ + rv.ret.logvols.logvols_val = safe_realloc (g, rv.ret.logvols.logvols_val, rv.ret.logvols.logvols_len + 1); + rv.ret.logvols.logvols_val[rv.ret.logvols.logvols_len] = NULL; + return rv.ret.logvols.logvols_val; +} + struct pvs_full_rv { int cb_done; /* flag to indicate callback was called */ struct guestfs_message_header hdr; diff --git a/src/guestfs-actions.h b/src/guestfs-actions.h index 8e73a5ea..61eedd36 100644 --- a/src/guestfs-actions.h +++ b/src/guestfs-actions.h @@ -27,6 +27,9 @@ extern char *guestfs_ll (guestfs_h *handle, const char *directory); extern char **guestfs_ls (guestfs_h *handle, const char *directory); extern char **guestfs_list_devices (guestfs_h *handle); extern char **guestfs_list_partitions (guestfs_h *handle); +extern char **guestfs_pvs (guestfs_h *handle); +extern char **guestfs_vgs (guestfs_h *handle); +extern char **guestfs_lvs (guestfs_h *handle); extern struct guestfs_lvm_pv_list *guestfs_pvs_full (guestfs_h *handle); extern struct guestfs_lvm_vg_list *guestfs_vgs_full (guestfs_h *handle); extern struct guestfs_lvm_lv_list *guestfs_lvs_full (guestfs_h *handle); diff --git a/src/guestfs_protocol.c b/src/guestfs_protocol.c index a19d7a12..2a194a71 100644 --- a/src/guestfs_protocol.c +++ b/src/guestfs_protocol.c @@ -279,6 +279,39 @@ xdr_guestfs_list_partitions_ret (XDR *xdrs, guestfs_list_partitions_ret *objp) } bool_t +xdr_guestfs_pvs_ret (XDR *xdrs, guestfs_pvs_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->physvols.physvols_val, (u_int *) &objp->physvols.physvols_len, ~0, + sizeof (str), (xdrproc_t) xdr_str)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_vgs_ret (XDR *xdrs, guestfs_vgs_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->volgroups.volgroups_val, (u_int *) &objp->volgroups.volgroups_len, ~0, + sizeof (str), (xdrproc_t) xdr_str)) + return FALSE; + return TRUE; +} + +bool_t +xdr_guestfs_lvs_ret (XDR *xdrs, guestfs_lvs_ret *objp) +{ + register int32_t *buf; + + if (!xdr_array (xdrs, (char **)&objp->logvols.logvols_val, (u_int *) &objp->logvols.logvols_len, ~0, + sizeof (str), (xdrproc_t) xdr_str)) + return FALSE; + return TRUE; +} + +bool_t xdr_guestfs_pvs_full_ret (XDR *xdrs, guestfs_pvs_full_ret *objp) { register int32_t *buf; diff --git a/src/guestfs_protocol.h b/src/guestfs_protocol.h index 55faa85e..9a7187dd 100644 --- a/src/guestfs_protocol.h +++ b/src/guestfs_protocol.h @@ -152,6 +152,30 @@ struct guestfs_list_partitions_ret { }; typedef struct guestfs_list_partitions_ret guestfs_list_partitions_ret; +struct guestfs_pvs_ret { + struct { + u_int physvols_len; + str *physvols_val; + } physvols; +}; +typedef struct guestfs_pvs_ret guestfs_pvs_ret; + +struct guestfs_vgs_ret { + struct { + u_int volgroups_len; + str *volgroups_val; + } volgroups; +}; +typedef struct guestfs_vgs_ret guestfs_vgs_ret; + +struct guestfs_lvs_ret { + struct { + u_int logvols_len; + str *logvols_val; + } logvols; +}; +typedef struct guestfs_lvs_ret guestfs_lvs_ret; + struct guestfs_pvs_full_ret { guestfs_lvm_int_pv_list physvols; }; @@ -176,6 +200,9 @@ enum guestfs_procedure { GUESTFS_PROC_LS = 6, GUESTFS_PROC_LIST_DEVICES = 7, GUESTFS_PROC_LIST_PARTITIONS = 8, + GUESTFS_PROC_PVS = 9, + GUESTFS_PROC_VGS = 10, + GUESTFS_PROC_LVS = 11, GUESTFS_PROC_PVS_FULL = 12, GUESTFS_PROC_VGS_FULL = 13, GUESTFS_PROC_LVS_FULL = 14, @@ -234,6 +261,9 @@ extern bool_t xdr_guestfs_ls_args (XDR *, guestfs_ls_args*); extern bool_t xdr_guestfs_ls_ret (XDR *, guestfs_ls_ret*); extern bool_t xdr_guestfs_list_devices_ret (XDR *, guestfs_list_devices_ret*); extern bool_t xdr_guestfs_list_partitions_ret (XDR *, guestfs_list_partitions_ret*); +extern bool_t xdr_guestfs_pvs_ret (XDR *, guestfs_pvs_ret*); +extern bool_t xdr_guestfs_vgs_ret (XDR *, guestfs_vgs_ret*); +extern bool_t xdr_guestfs_lvs_ret (XDR *, guestfs_lvs_ret*); extern bool_t xdr_guestfs_pvs_full_ret (XDR *, guestfs_pvs_full_ret*); extern bool_t xdr_guestfs_vgs_full_ret (XDR *, guestfs_vgs_full_ret*); extern bool_t xdr_guestfs_lvs_full_ret (XDR *, guestfs_lvs_full_ret*); @@ -261,6 +291,9 @@ extern bool_t xdr_guestfs_ls_args (); extern bool_t xdr_guestfs_ls_ret (); extern bool_t xdr_guestfs_list_devices_ret (); extern bool_t xdr_guestfs_list_partitions_ret (); +extern bool_t xdr_guestfs_pvs_ret (); +extern bool_t xdr_guestfs_vgs_ret (); +extern bool_t xdr_guestfs_lvs_ret (); extern bool_t xdr_guestfs_pvs_full_ret (); extern bool_t xdr_guestfs_vgs_full_ret (); extern bool_t xdr_guestfs_lvs_full_ret (); diff --git a/src/guestfs_protocol.x b/src/guestfs_protocol.x index 9bc556ba..b2fe5351 100644 --- a/src/guestfs_protocol.x +++ b/src/guestfs_protocol.x @@ -142,6 +142,24 @@ struct guestfs_list_partitions_ret { str partitions<>; }; +/* guestfs_pvs */ + +struct guestfs_pvs_ret { + str physvols<>; +}; + +/* guestfs_vgs */ + +struct guestfs_vgs_ret { + str volgroups<>; +}; + +/* guestfs_lvs */ + +struct guestfs_lvs_ret { + str logvols<>; +}; + /* guestfs_pvs_full */ struct guestfs_pvs_full_ret { @@ -169,6 +187,9 @@ enum guestfs_procedure { GUESTFS_PROC_LS = 6, GUESTFS_PROC_LIST_DEVICES = 7, GUESTFS_PROC_LIST_PARTITIONS = 8, + GUESTFS_PROC_PVS = 9, + GUESTFS_PROC_VGS = 10, + GUESTFS_PROC_LVS = 11, GUESTFS_PROC_PVS_FULL = 12, GUESTFS_PROC_VGS_FULL = 13, GUESTFS_PROC_LVS_FULL = 14, |