Nikos Skalkotos
2017-Jul-29 17:51 UTC
[Libguestfs] [PATCH 1/1] New partition API: part_resize
This can be used to enlarge or shrink an existing partition. --- daemon/parted.c | 31 +++++++++++++++++++++++++++++++ generator/actions_core.ml | 22 ++++++++++++++++++++++ generator/proc_nr.ml | 1 + lib/MAX_PROC_NR | 2 +- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/daemon/parted.c b/daemon/parted.c index 72e1b8420..f1205cadf 100644 --- a/daemon/parted.c +++ b/daemon/parted.c @@ -178,6 +178,37 @@ do_part_del (const char *device, int partnum) } int +do_part_resize (const char *device, int partnum, int64_t endsect) +{ + int r; + CLEANUP_FREE char *err = NULL; + char endstr[32]; + char partnum_str[16]; + + if (partnum <= 0) { + reply_with_error ("partition number must be >= 1"); + return -1; + } + + snprintf (partnum_str, sizeof partnum_str, "%d", partnum); + snprintf (endstr, sizeof endstr, "%" PRIi64 "s", endsect); + + udev_settle (); + + r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, + "parted", "-s", "--", device, "resizepart", partnum_str, + endstr, NULL); + if (r == -1) { + reply_with_error ("parted: %s: %s:", device, err); + return -1; + } + + udev_settle(); + + return 0; +} + +int do_part_disk (const char *device, const char *parttype) { int r; diff --git a/generator/actions_core.ml b/generator/actions_core.ml index ea0735676..939aec7ee 100644 --- a/generator/actions_core.ml +++ b/generator/actions_core.ml @@ -9646,4 +9646,26 @@ be mountable but require special options. Filesystems may not all belong to a single logical operating system (use C<guestfs_inspect_os> to look for OSes)." }; + { defaults with + name = "part_resize"; added = (1, 37, 20); + style = RErr, [String (Device, "device"); Int "partnum"; Int64 "endsect"], []; + tests = [ + InitEmpty, Always, TestRun ( + [["part_init"; "/dev/sda"; "mbr"]; + ["part_add"; "/dev/sda"; "primary"; "1"; "-1025"]; + ["part_resize"; "/dev/sda"; "1"; "-1"]]), [] + ]; + shortdesc = "resize a partition"; + longdesc = "\ +This command resizes the partition numbered C<partnum> on C<device> +by moving the end position. + +Note that this does not modify any filesystem present in the partition. +If you wish to do this, you will need to use filesystem resizing +commands like C<guestfs_resize2fs>. + +When growing a partition you will want to grow the filesystem +afterwards, but when shrinking, you need to shrink the filesystem +before the partition." }; + ] diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml index dec02f5fa..7895063b6 100644 --- a/generator/proc_nr.ml +++ b/generator/proc_nr.ml @@ -484,6 +484,7 @@ let proc_nr = [ 474, "internal_yara_scan"; 475, "file_architecture"; 476, "list_filesystems"; +477, "part_resize"; ] (* End of list. If adding a new entry, add it at the end of the list diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR index b86395733..bf2c10d23 100644 --- a/lib/MAX_PROC_NR +++ b/lib/MAX_PROC_NR @@ -1 +1 @@ -476 +477 -- 2.13.3
Richard W.M. Jones
2017-Jul-30 15:42 UTC
Re: [Libguestfs] [PATCH 1/1] New partition API: part_resize
On Sat, Jul 29, 2017 at 08:51:04PM +0300, Nikos Skalkotos wrote:> This can be used to enlarge or shrink an existing partition. > --- > daemon/parted.c | 31 +++++++++++++++++++++++++++++++ > generator/actions_core.ml | 22 ++++++++++++++++++++++ > generator/proc_nr.ml | 1 + > lib/MAX_PROC_NR | 2 +- > 4 files changed, 55 insertions(+), 1 deletion(-) > > diff --git a/daemon/parted.c b/daemon/parted.c > index 72e1b8420..f1205cadf 100644 > --- a/daemon/parted.c > +++ b/daemon/parted.c > @@ -178,6 +178,37 @@ do_part_del (const char *device, int partnum) > } > > int > +do_part_resize (const char *device, int partnum, int64_t endsect) > +{ > + int r; > + CLEANUP_FREE char *err = NULL; > + char endstr[32]; > + char partnum_str[16]; > + > + if (partnum <= 0) { > + reply_with_error ("partition number must be >= 1"); > + return -1; > + } > + > + snprintf (partnum_str, sizeof partnum_str, "%d", partnum); > + snprintf (endstr, sizeof endstr, "%" PRIi64 "s", endsect); > + > + udev_settle (); > + > + r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, > + "parted", "-s", "--", device, "resizepart", partnum_str, > + endstr, NULL); > + if (r == -1) { > + reply_with_error ("parted: %s: %s:", device, err); > + return -1; > + } > + > + udev_settle(); > + > + return 0; > +} > + > +int > do_part_disk (const char *device, const char *parttype) > { > int r; > diff --git a/generator/actions_core.ml b/generator/actions_core.ml > index ea0735676..939aec7ee 100644 > --- a/generator/actions_core.ml > +++ b/generator/actions_core.ml > @@ -9646,4 +9646,26 @@ be mountable but require special options. Filesystems may > not all belong to a single logical operating system > (use C<guestfs_inspect_os> to look for OSes)." }; > > + { defaults with > + name = "part_resize"; added = (1, 37, 20); > + style = RErr, [String (Device, "device"); Int "partnum"; Int64 "endsect"], []; > + tests = [ > + InitEmpty, Always, TestRun ( > + [["part_init"; "/dev/sda"; "mbr"]; > + ["part_add"; "/dev/sda"; "primary"; "1"; "-1025"]; > + ["part_resize"; "/dev/sda"; "1"; "-1"]]), [] > + ]; > + shortdesc = "resize a partition"; > + longdesc = "\ > +This command resizes the partition numbered C<partnum> on C<device> > +by moving the end position. > + > +Note that this does not modify any filesystem present in the partition. > +If you wish to do this, you will need to use filesystem resizing > +commands like C<guestfs_resize2fs>. > + > +When growing a partition you will want to grow the filesystem > +afterwards, but when shrinking, you need to shrink the filesystem > +before the partition." }; > + > ] > diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml > index dec02f5fa..7895063b6 100644 > --- a/generator/proc_nr.ml > +++ b/generator/proc_nr.ml > @@ -484,6 +484,7 @@ let proc_nr = [ > 474, "internal_yara_scan"; > 475, "file_architecture"; > 476, "list_filesystems"; > +477, "part_resize"; > ] > > (* End of list. If adding a new entry, add it at the end of the list > diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR > index b86395733..bf2c10d23 100644 > --- a/lib/MAX_PROC_NR > +++ b/lib/MAX_PROC_NR > @@ -1 +1 @@ > -476 > +477Looks fine to me, ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Pino Toscano
2017-Jul-31 09:06 UTC
Re: [Libguestfs] [PATCH 1/1] New partition API: part_resize
On Sunday, 30 July 2017 17:42:07 CEST Richard W.M. Jones wrote:> On Sat, Jul 29, 2017 at 08:51:04PM +0300, Nikos Skalkotos wrote: > > This can be used to enlarge or shrink an existing partition. > > --- > > daemon/parted.c | 31 +++++++++++++++++++++++++++++++ > > generator/actions_core.ml | 22 ++++++++++++++++++++++ > > generator/proc_nr.ml | 1 + > > lib/MAX_PROC_NR | 2 +- > > 4 files changed, 55 insertions(+), 1 deletion(-) > > > > diff --git a/daemon/parted.c b/daemon/parted.c > > index 72e1b8420..f1205cadf 100644 > > --- a/daemon/parted.c > > +++ b/daemon/parted.c > > @@ -178,6 +178,37 @@ do_part_del (const char *device, int partnum) > > } > > > > int > > +do_part_resize (const char *device, int partnum, int64_t endsect) > > +{ > > + int r; > > + CLEANUP_FREE char *err = NULL; > > + char endstr[32]; > > + char partnum_str[16]; > > + > > + if (partnum <= 0) { > > + reply_with_error ("partition number must be >= 1"); > > + return -1; > > + } > > + > > + snprintf (partnum_str, sizeof partnum_str, "%d", partnum); > > + snprintf (endstr, sizeof endstr, "%" PRIi64 "s", endsect); > > + > > + udev_settle (); > > + > > + r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, > > + "parted", "-s", "--", device, "resizepart", partnum_str, > > + endstr, NULL); > > + if (r == -1) { > > + reply_with_error ("parted: %s: %s:", device, err); > > + return -1; > > + } > > + > > + udev_settle(); > > + > > + return 0; > > +} > > + > > +int > > do_part_disk (const char *device, const char *parttype) > > { > > int r; > > diff --git a/generator/actions_core.ml b/generator/actions_core.ml > > index ea0735676..939aec7ee 100644 > > --- a/generator/actions_core.ml > > +++ b/generator/actions_core.ml > > @@ -9646,4 +9646,26 @@ be mountable but require special options. Filesystems may > > not all belong to a single logical operating system > > (use C<guestfs_inspect_os> to look for OSes)." }; > > > > + { defaults with > > + name = "part_resize"; added = (1, 37, 20); > > + style = RErr, [String (Device, "device"); Int "partnum"; Int64 "endsect"], []; > > + tests = [ > > + InitEmpty, Always, TestRun ( > > + [["part_init"; "/dev/sda"; "mbr"]; > > + ["part_add"; "/dev/sda"; "primary"; "1"; "-1025"]; > > + ["part_resize"; "/dev/sda"; "1"; "-1"]]), [] > > + ]; > > + shortdesc = "resize a partition"; > > + longdesc = "\ > > +This command resizes the partition numbered C<partnum> on C<device> > > +by moving the end position. > > + > > +Note that this does not modify any filesystem present in the partition. > > +If you wish to do this, you will need to use filesystem resizing > > +commands like C<guestfs_resize2fs>. > > + > > +When growing a partition you will want to grow the filesystem > > +afterwards, but when shrinking, you need to shrink the filesystem > > +before the partition." }; > > + > > ] > > diff --git a/generator/proc_nr.ml b/generator/proc_nr.ml > > index dec02f5fa..7895063b6 100644 > > --- a/generator/proc_nr.ml > > +++ b/generator/proc_nr.ml > > @@ -484,6 +484,7 @@ let proc_nr = [ > > 474, "internal_yara_scan"; > > 475, "file_architecture"; > > 476, "list_filesystems"; > > +477, "part_resize"; > > ] > > > > (* End of list. If adding a new entry, add it at the end of the list > > diff --git a/lib/MAX_PROC_NR b/lib/MAX_PROC_NR > > index b86395733..bf2c10d23 100644 > > --- a/lib/MAX_PROC_NR > > +++ b/lib/MAX_PROC_NR > > @@ -1 +1 @@ > > -476 > > +477 > > Looks fine to me, ACK.Idem -- hence pushed. Thanks, -- Pino Toscano
Richard Jones
2017-Jul-31 15:58 UTC
[Libguestfs] check-syntax FAILED (was: Re: [PATCH 1/1] New partition API: part_resize)
Checking out sources from https://github.com/libguestfs/libguestfs ... /var/tmp/tmpO3AAV7/libguestfs /var/tmp/tmpO3AAV7 Reset branch 'master' Branch master set up to track remote branch master from origin. Your branch is up-to-date with 'origin/master'.>From github.com:libguestfs/libguestfs70b6f3356..c73f0a667 master -> origin/master * [new tag] v1.37.19 -> v1.37.19 Updating 70b6f3356..c73f0a667 Fast-forward BUGS | 26 +- RELEASES | 1 + configure.ac | 2 +- daemon/ntfs.c | 4 +- daemon/parted.c | 31 + docs/guestfs-building.pod | 6 +- generator/actions_core.ml | 22 + generator/proc_nr.ml | 1 + gobject/run-live-tests | 2 +- gobject/run-tests | 2 +- gobject/run-tests-retvalues | 2 +- lib/MAX_PROC_NR | 2 +- m4/guestfs_ocaml.m4 | 8 + po-docs/cs.po | 2570 ++++++++++++++++++++-------------------- po-docs/de.po | 2570 ++++++++++++++++++++-------------------- po-docs/en_GB.po | 2707 ++++++++++++++++++++++--------------------- po-docs/es.po | 2570 ++++++++++++++++++++-------------------- po-docs/eu.po | 2570 ++++++++++++++++++++-------------------- po-docs/fr.po | 2622 ++++++++++++++++++++--------------------- po-docs/ja.po | 2570 ++++++++++++++++++++-------------------- po-docs/libguestfs-docs.pot | 2479 +++++++++++++++++++-------------------- po-docs/nl.po | 2570 ++++++++++++++++++++-------------------- po-docs/pt_BR.po | 2570 ++++++++++++++++++++-------------------- po-docs/tg.po | 2570 ++++++++++++++++++++-------------------- po-docs/uk.po | 2700 +++++++++++++++++++++--------------------- po-docs/zh_CN.po | 2570 ++++++++++++++++++++-------------------- po/POTFILES | 7 +- po/ca.po | 67 +- po/de.po | 67 +- po/en_GB.po | 67 +- po/es.po | 70 +- po/eu.po | 67 +- po/fr.po | 70 +- po/gu.po | 67 +- po/hi.po | 67 +- po/ja.po | 70 +- po/kn.po | 67 +- po/libguestfs.pot | 69 +- po/ml.po | 67 +- po/mr.po | 70 +- po/nl.po | 70 +- po/or.po | 67 +- po/pa.po | 70 +- po/pl.po | 70 +- po/pt_BR.po | 67 +- po/ru.po | 67 +- po/ta.po | 67 +- po/te.po | 67 +- po/tg.po | 67 +- po/uk.po | 70 +- po/zh_CN.po | 67 +- po/zh_TW.po | 67 +- 52 files changed, 17727 insertions(+), 17728 deletions(-) /var/tmp/tmpO3AAV7 Applying patches ... /var/tmp/tmpO3AAV7/libguestfs /var/tmp/tmpO3AAV7 error: patch failed: generator/actions_core.ml:9646 error: generator/actions_core.ml: patch does not apply error: patch failed: generator/proc_nr.ml:484 error: generator/proc_nr.ml: patch does not apply error: patch failed: lib/MAX_PROC_NR:1 error: lib/MAX_PROC_NR: patch does not apply Applying: New partition API: part_resize Patch failed at 0001 New partition API: part_resize The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Richard Jones
2017-Jul-31 15:58 UTC
[Libguestfs] check-release FAILED (was: Re: [PATCH 1/1] New partition API: part_resize)
Checking out sources from https://github.com/libguestfs/libguestfs ... /var/tmp/tmpCmhm7s/libguestfs /var/tmp/tmpCmhm7s Reset branch 'master' Branch master set up to track remote branch master from origin. Your branch is up-to-date with 'origin/master'.>From github.com:libguestfs/libguestfs70b6f3356..c73f0a667 master -> origin/master * [new tag] v1.37.19 -> v1.37.19 Updating 70b6f3356..c73f0a667 Fast-forward BUGS | 26 +- RELEASES | 1 + configure.ac | 2 +- daemon/ntfs.c | 4 +- daemon/parted.c | 31 + docs/guestfs-building.pod | 6 +- generator/actions_core.ml | 22 + generator/proc_nr.ml | 1 + gobject/run-live-tests | 2 +- gobject/run-tests | 2 +- gobject/run-tests-retvalues | 2 +- lib/MAX_PROC_NR | 2 +- m4/guestfs_ocaml.m4 | 8 + po-docs/cs.po | 2570 ++++++++++++++++++++-------------------- po-docs/de.po | 2570 ++++++++++++++++++++-------------------- po-docs/en_GB.po | 2707 ++++++++++++++++++++++--------------------- po-docs/es.po | 2570 ++++++++++++++++++++-------------------- po-docs/eu.po | 2570 ++++++++++++++++++++-------------------- po-docs/fr.po | 2622 ++++++++++++++++++++--------------------- po-docs/ja.po | 2570 ++++++++++++++++++++-------------------- po-docs/libguestfs-docs.pot | 2479 +++++++++++++++++++-------------------- po-docs/nl.po | 2570 ++++++++++++++++++++-------------------- po-docs/pt_BR.po | 2570 ++++++++++++++++++++-------------------- po-docs/tg.po | 2570 ++++++++++++++++++++-------------------- po-docs/uk.po | 2700 +++++++++++++++++++++--------------------- po-docs/zh_CN.po | 2570 ++++++++++++++++++++-------------------- po/POTFILES | 7 +- po/ca.po | 67 +- po/de.po | 67 +- po/en_GB.po | 67 +- po/es.po | 70 +- po/eu.po | 67 +- po/fr.po | 70 +- po/gu.po | 67 +- po/hi.po | 67 +- po/ja.po | 70 +- po/kn.po | 67 +- po/libguestfs.pot | 69 +- po/ml.po | 67 +- po/mr.po | 70 +- po/nl.po | 70 +- po/or.po | 67 +- po/pa.po | 70 +- po/pl.po | 70 +- po/pt_BR.po | 67 +- po/ru.po | 67 +- po/ta.po | 67 +- po/te.po | 67 +- po/tg.po | 67 +- po/uk.po | 70 +- po/zh_CN.po | 67 +- po/zh_TW.po | 67 +- 52 files changed, 17727 insertions(+), 17728 deletions(-) /var/tmp/tmpCmhm7s Applying patches ... /var/tmp/tmpCmhm7s/libguestfs /var/tmp/tmpCmhm7s error: patch failed: generator/actions_core.ml:9646 error: generator/actions_core.ml: patch does not apply error: patch failed: generator/proc_nr.ml:484 error: generator/proc_nr.ml: patch does not apply error: patch failed: lib/MAX_PROC_NR:1 error: lib/MAX_PROC_NR: patch does not apply Applying: New partition API: part_resize Patch failed at 0001 New partition API: part_resize The copy of the patch that failed is found in: .git/rebase-apply/patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
Richard W.M. Jones
2017-Jul-31 16:27 UTC
Re: [Libguestfs] check-release FAILED (was: Re: [PATCH 1/1] New partition API: part_resize)
These emails are not real failures. The commit went upstream just before the test ran, so the test thought that the commit didn't apply cleanly ... Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Apparently Analagous Threads
- [PATCH] build: require ocaml-hivex for the daemon
- check-release FAILED (was: Re: [PATCH 1/1] New partition API: part_resize)
- Re: [PATCH 1/1] New partition API: part_resize
- [PATCH 1/2] Revert "daemon: Run udev_settle after pwrite-device finishes."
- [PATCH 0/1] New partition API: part_resize