New API: lvresize-free to extend LVs into percentage of free space.
authorRichard Jones <rjones@redhat.com>
Mon, 12 Apr 2010 15:33:46 +0000 (16:33 +0100)
committerRichard Jones <rjones@redhat.com>
Mon, 12 Apr 2010 17:55:18 +0000 (18:55 +0100)
daemon/lvm.c
src/MAX_PROC_NR
src/generator.ml

index 20f2fb3..e44f4c2 100644 (file)
@@ -278,6 +278,32 @@ do_lvresize (const char *logvol, int mbytes)
   return 0;
 }
 
   return 0;
 }
 
+int
+do_lvresize_free (const char *logvol, int percent)
+{
+  char *err;
+  int r;
+
+  if (percent < 0 || percent > 100) {
+    reply_with_error ("percentage must be [0..100] (was %d)", percent);
+    return -1;
+  }
+
+  char size[64];
+  snprintf (size, sizeof size, "+%d%%FREE", percent);
+
+  r = command (NULL, &err,
+               "lvm", "lvresize", "-l", size, logvol, NULL);
+  if (r == -1) {
+    reply_with_error ("%s", err);
+    free (err);
+    return -1;
+  }
+
+  free (err);
+  return 0;
+}
+
 /* Super-dangerous command used for testing.  It removes all
  * LVs, VGs and PVs permanently.
  */
 /* Super-dangerous command used for testing.  It removes all
  * LVs, VGs and PVs permanently.
  */
index 997def4..1cf253f 100644 (file)
@@ -1 +1 @@
-237
+238
index 535c412..532aba9 100755 (executable)
@@ -4453,6 +4453,21 @@ This call computes the MD5, SHAx or CRC checksum of the
 contents of the device named C<device>.  For the types of
 checksums supported see the C<guestfs_checksum> command.");
 
 contents of the device named C<device>.  For the types of
 checksums supported see the C<guestfs_checksum> command.");
 
+  ("lvresize_free", (RErr, [Device "lv"; Int "percent"]), 238, [Optional "lvm2"],
+   [InitNone, Always, TestRun (
+      [["part_disk"; "/dev/sda"; "mbr"];
+       ["pvcreate"; "/dev/sda1"];
+       ["vgcreate"; "VG"; "/dev/sda1"];
+       ["lvcreate"; "LV"; "VG"; "10"];
+       ["lvresize_free"; "/dev/VG/LV"; "100"]])],
+   "expand an LV to fill free space",
+   "\
+This expands an existing logical volume C<lv> so that it fills
+C<pc>% of the remaining free space in the volume group.  Commonly
+you would call this with pc = 100 which expands the logical volume
+as much as possible, using all remaining free space in the volume
+group.");
+
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions
 ]
 
 let all_functions = non_daemon_functions @ daemon_functions