[PATCH] New API: part_get_part_type for showing partition type
by Chen Hanxiao
This patch will add support for getting partition type
of a partiton numbered device.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/parted.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 18 +++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 131 insertions(+), 1 deletion(-)
diff --git a/daemon/parted.c b/daemon/parted.c
index a7bcb99..0ae6e5c 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -33,6 +33,10 @@ GUESTFSD_EXT_CMD(str_parted, parted);
GUESTFSD_EXT_CMD(str_sfdisk, sfdisk);
GUESTFSD_EXT_CMD(str_sgdisk, sgdisk);
+#ifndef PARTED_NO_M
+# define PARTED_NO_M 0
+#endif
+
/* Notes:
*
* Parted 1.9 sends error messages to stdout, hence use of the
@@ -1022,3 +1026,111 @@ do_part_get_name (const char *device, int partnum)
reply_with_error ("cannot get the partition name from '%s' layouts", parttype);
return NULL;
}
+
+char *
+do_part_get_part_type (const char *device, int partnum)
+{
+ CLEANUP_FREE char *parttype;
+ char *part_type;
+
+ if (partnum <= 0) {
+ reply_with_error ("partition number must be >= 1");
+ return NULL;
+ }
+
+ parttype = do_part_get_parttype (device);
+ if (parttype == NULL)
+ return NULL;
+
+ if (STREQ (parttype, "gpt")) {
+ part_type = strdup("primary");
+ if (part_type == NULL) {
+ reply_with_error ("strdup failed");
+ return NULL;
+ }
+ return part_type;
+ }
+
+ /* machine parseable output by 'parted -m' did not provide
+ * partition type info.
+ * Use traditional style.
+ */
+ CLEANUP_FREE char *out = print_partition_table (device, PARTED_NO_M);
+ if (!out)
+ return NULL;
+
+ CLEANUP_FREE_STRING_LIST char **lines = split_lines (out);
+
+ if (!lines)
+ return NULL;
+
+ size_t start = 0, end = 0, row;
+
+ for (row = 0; lines[row] != NULL; ++row)
+ if (STRPREFIX (lines[row], "Number")) {
+ start = row + 1;
+ break;
+ }
+
+ if (start == 0) {
+ reply_with_error ("parted output has no \"Number\" line");
+ return NULL;
+ }
+
+ for (row = start; lines[row] != NULL; ++row)
+ if (STREQ (lines[row], "")) {
+ end = row;
+ break;
+ }
+
+ if (end == 0) {
+ reply_with_error ("parted output has no blank after end of table");
+ return NULL;
+ }
+
+ /* Now parse the lines. */
+ size_t i;
+ int64_t temp_int64;
+ int part_num;
+ char temp_type[16];
+ for (i = 0, row = start; row < end; ++i, ++row) {
+ if (sscanf (lines[row], "%d%" SCNi64 "B%" SCNi64 "B%" SCNi64 "B" "%s",
+ &part_num,
+ &temp_int64,
+ &temp_int64,
+ &temp_int64,
+ temp_type) != 5) {
+ reply_with_error ("could not parse row from output of parted print command: %s", lines[row]);
+ return NULL;
+ }
+
+ if (part_num != partnum)
+ continue;
+
+ if (STRPREFIX (temp_type, "primary")) {
+ part_type = strdup("primary");
+ if (part_type == NULL)
+ goto error;
+ } else if (STRPREFIX (temp_type, "logical")) {
+ part_type = strdup("logical");
+ if (part_type == NULL)
+ goto error;
+ } else if (STRPREFIX (temp_type, "extended")) {
+ part_type = strdup("extended");
+ if (part_type == NULL)
+ goto error;
+ } else
+ goto error;
+
+ return part_type;
+ }
+
+ if (row == end) {
+ reply_with_error ("could not find partnum: %d", partnum);
+ return NULL;
+ }
+
+ error:
+ reply_with_error ("strdup failed");
+ return NULL;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index fb971d3..72418b0 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12522,6 +12522,24 @@ This will Enable extended inode refs." };
longdesc = "\
This enable skinny metadata extent refs." };
+ { defaults with
+ name = "part_get_part_type";
+ style = RString "partitiontype", [Device "device"; Int "partnum"], [];
+ proc_nr = Some 453;
+ tests = [
+ InitEmpty, Always, TestResultString (
+ [["part_init"; "/dev/sda"; "mbr"];
+ ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+ ["part_add"; "/dev/sda"; "e"; "204800"; "614400"];
+ ["part_add"; "/dev/sda"; "l"; "204864"; "205988"];
+ ["part_get_part_type"; "/dev/sda"; "5"]], "logical"), []
+ ];
+
+ shortdesc = "get the partition type";
+ longdesc = "\
+This could get the partition type, such as primary, logical,
+on partition numbered C<partnum> on device C<device>." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 8670c73..534b992 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-452
+453
--
2.1.0
9 years, 9 months
[PATCH v2] New API: btrfs-image
by Chen Hanxiao
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
v2: add optargs_bitmask check
daemon/btrfs.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
generator/actions.ml | 22 ++++++++++++++++++++++
src/MAX_PROC_NR | 2 +-
3 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index d4b3207..340b548 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -37,6 +37,7 @@ GUESTFSD_EXT_CMD(str_btrfstune, btrfstune);
GUESTFSD_EXT_CMD(str_btrfsck, btrfsck);
GUESTFSD_EXT_CMD(str_mkfs_btrfs, mkfs.btrfs);
GUESTFSD_EXT_CMD(str_umount, umount);
+GUESTFSD_EXT_CMD(str_btrfsimage, btrfs-image);
int
optgroup_btrfs_available (void)
@@ -2005,3 +2006,54 @@ do_btrfstune_enable_skinny_metadata_extent_refs (const char *device)
return 0;
}
+
+int
+do_btrfs_image (char *const *sources, const char *image,
+ int compresslevel, int numthreads)
+{
+ size_t nr_sources = count_strings (sources);
+ const size_t MAX_ARGS = 64 + nr_sources;
+ const char *argv[MAX_ARGS];
+ size_t i = 0, j;
+ CLEANUP_FREE char *err = NULL;
+ CLEANUP_FREE char *out = NULL;
+ char compresslevel_s[64];
+ char numthreads_s[64];
+ int r;
+
+ if (nr_sources == 0) {
+ reply_with_error ("list of sources must be non-empty");
+ return -1;
+ }
+
+ ADD_ARG (argv, i, str_btrfsimage);
+
+ if ((optargs_bitmask & GUESTFS_BTRFS_IMAGE_COMPRESSLEVEL_BITMASK)
+ && compresslevel >= 0) {
+ snprintf (compresslevel_s, sizeof compresslevel_s, "%d", compresslevel);
+ ADD_ARG (argv, i, "-c");
+ ADD_ARG (argv, i, compresslevel_s);
+ }
+
+ /* btrfs-progs will valid numtheads and choose the right one for us */
+ if ((optargs_bitmask & GUESTFS_BTRFS_IMAGE_NUMTHREADS_BITMASK)
+ && numthreads) {
+ snprintf (numthreads_s, sizeof numthreads_s, "%d", numthreads);
+ ADD_ARG (argv, i, "-t");
+ ADD_ARG (argv, i, numthreads_s);
+ }
+
+ for (j = 0; j < nr_sources; ++j)
+ ADD_ARG (argv, i, sources[j]);
+
+ ADD_ARG (argv, i, image);
+ ADD_ARG (argv, i, NULL);
+
+ r = commandv (&out, &err, argv);
+ if (r == -1) {
+ reply_with_error ("%s %s: %s", sources[0], image, err);
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index fb971d3..8effc0e 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -12522,6 +12522,28 @@ This will Enable extended inode refs." };
longdesc = "\
This enable skinny metadata extent refs." };
+ { defaults with
+ name = "btrfs_image";
+ style = RErr, [DeviceList "source"; Pathname "image"], [OInt "compresslevel"; OInt "numthreads"];
+ proc_nr = Some 454;
+ optional = Some "btrfs"; camel_name = "BTRFSImage";
+ tests = [
+ InitPartition, Always, TestRun (
+ [["part_init"; "/dev/sda"; "mbr"];
+ ["part_add"; "/dev/sda"; "p"; "64"; "204799"];
+ ["part_add"; "/dev/sda"; "p"; "204800"; "409599"];
+ ["mkfs_btrfs"; "/dev/sda1"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+ ["mkfs_btrfs"; "/dev/sda2"; ""; ""; "NOARG"; ""; "NOARG"; "NOARG"; ""; ""];
+ ["mount"; "/dev/sda1"; "/"];
+ ["btrfs_image"; "/dev/sda2"; "/1.img"; ""; ""];
+ ["btrfs_image"; "/dev/sda2"; "/2.img"; "2"; "3"]]), []
+ ];
+
+ shortdesc = "create an image of a btrfs filesystem";
+ longdesc = "\
+This is used to create an image of a btrfs filesystem.
+All data will be zeroed, but metadata and the like is preserved." };
+
]
(* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 8670c73..534b992 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-453
+454
--
2.1.0
9 years, 9 months
[PATCH] customize: add --copy
by Maros Zatko
From: Maros Zatko <hacxman(a)gmail.com>
This adds --copy SOURCE:DEST, equivalent of calling g#cp_a src dst.
RFE: RHBZ#1203817
Maros Zatko (1):
customize: add --copy
builder/cmdline.ml | 2 +-
customize/customize_run.ml | 4 ++++
generator/customize.ml | 10 ++++++++++
3 files changed, 15 insertions(+), 1 deletion(-)
--
1.9.3
9 years, 9 months
[PATCH v4] [RFE] virt-builder should support download resume
by Maros Zatko
This adds support for resuming downloads in virt-builder.
Partially downloaded image is not deleted on exit anymore.
There is a check for partially downloaded image in cache directory
based on its name. When found, download_to crafts appropriate
options to continue its download.
Fixes RHBZ#1198344
Ammended for forgotten unlink_on_exit and fixed call with optional
aguments.
Maros Zatko (1):
builder: support for download resume
builder/downloader.ml | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
--
1.9.3
9 years, 9 months
[PATCH v3] [RFE] virt-builder should support download resume
by Maros Zatko
This adds support for resuming downloads in virt-builder.
Partially downloaded file is not deleted on exit anymore.
There is a check for partially downloaded image in cache directory
based on its name. When found, download_to crafts appropriate
options to continue its download.
Fixes RHBZ#1198344
Ammended for forgotten unlink_on_exit.
Maros Zatko (1):
builder: support for download resume
builder/downloader.ml | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
--
1.9.3
9 years, 9 months
[PATCH 0/2] [RFE] virt-builder should support download resume
by Maros Zatko
This patchset adds support for resuming downloads in virt-builder.
Partially downloaded file is not deleted on exit anymore.
There is a check for partially downloaded image in cache directory
based on its name. When found, download_to crafts appropriate
options to continue its download.
Maros Zatko (2):
mllib: allow external_command to return [] on nonzero return value
builder: support for download resume
builder/downloader.ml | 16 ++++++++++++----
mllib/common_utils.ml | 15 ++++++++++-----
mllib/common_utils.mli | 2 +-
3 files changed, 23 insertions(+), 10 deletions(-)
--
1.9.3
9 years, 9 months
[PATCH] fuse: resolve absolute links to relative ones
by Maros Zatko
First it strips /sysroot and then finds common prefix aligned
on slashes. Next it produces ../ for each slash found in common
prefix and concatenates them with the rest of resolved link.
Fixes RHBZ#604041
Maros Zatko (1):
fuse: resolve absolute links to relative ones
src/fuse.c | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
--
1.9.3
9 years, 9 months
[PATCH] RFE: support Windows drive letters in virt-ls
by Maros Zatko
It is modelled after virt-cat.
Fixes RHBZ#845234
Maros Zatko (1):
virt-ls: support drive letters on Windows
cat/ls.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
--
1.9.3
9 years, 9 months
[PATCH] RFE: Inspection should support systemd mount units
by Maros Zatko
Adds support for systemd .mount files, uses Augeas to extract mount points.
Fixes RHBZ#1113153.
Maros Zatko (1):
inspection: add support for systemd .mount files
src/inspect-fs-unix.c | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 240 insertions(+)
--
1.9.3
9 years, 9 months
[PATCH] builder: handle empty lines in indexes before first section (RHBZ#1201526)
by Pino Toscano
Properly skip empty lines before the first section, otherwise they will
trigger a syntax error in parsing.
Add a simple test for it, so it doesn't regress.
---
builder/index-parse.y | 8 ++++----
builder/test-virt-index-validate-good-3 | 4 ++++
builder/test-virt-index-validate.sh | 1 +
3 files changed, 9 insertions(+), 4 deletions(-)
create mode 100644 builder/test-virt-index-validate-good-3
diff --git a/builder/index-parse.y b/builder/index-parse.y
index 8ea2d73..82ea9d2 100644
--- a/builder/index-parse.y
+++ b/builder/index-parse.y
@@ -104,10 +104,10 @@ index:
{ context->parsed_index = $2; }
sections:
- section emptylines
- { $$ = $1; }
- | section EMPTY_LINE emptylines sections
- { $$ = $1; $$->next = $4; }
+ emptylines section emptylines
+ { $$ = $2; }
+ | emptylines section EMPTY_LINE emptylines sections
+ { $$ = $2; $$->next = $5; }
| emptylines
{ $$ = NULL; }
diff --git a/builder/test-virt-index-validate-good-3 b/builder/test-virt-index-validate-good-3
new file mode 100644
index 0000000..f10adf0
--- /dev/null
+++ b/builder/test-virt-index-validate-good-3
@@ -0,0 +1,4 @@
+# Empty lines before the first section
+
+[foo]
+key=value
diff --git a/builder/test-virt-index-validate.sh b/builder/test-virt-index-validate.sh
index c66929d..b00a086 100755
--- a/builder/test-virt-index-validate.sh
+++ b/builder/test-virt-index-validate.sh
@@ -22,3 +22,4 @@ set -e
! $VG virt-index-validate test-virt-index-validate-bad-1
$VG virt-index-validate test-virt-index-validate-good-1
$VG virt-index-validate test-virt-index-validate-good-2
+$VG virt-index-validate test-virt-index-validate-good-3
--
2.1.0
9 years, 9 months