New API: lvcreate-free: Create logical volume as % of free space.

This commit is contained in:
Richard W.M. Jones
2012-03-15 10:25:26 +00:00
parent 03d4345c8c
commit 79c4ecc0f3
3 changed files with 49 additions and 1 deletions

View File

@@ -262,6 +262,36 @@ do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
return 0;
}
int
do_lvcreate_free (const char *logvol, const char *volgroup, 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", "lvcreate",
"-L", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
return -1;
}
free (err);
udev_settle ();
return 0;
}
int
do_lvresize (const char *logvol, int mbytes)
{

View File

@@ -6762,6 +6762,24 @@ in the filesystem is freed.
In future (but not currently) these zeroed blocks will be
\"sparsified\" - that is, given back to the host.");
("lvcreate_free", (RErr, [String "logvol"; String "volgroup"; Int "percent"], []), 312, [Optional "lvm2"],
[InitEmpty, Always, TestOutputList (
[["part_disk"; "/dev/sda"; "mbr"];
["pvcreate"; "/dev/sda1"];
["vgcreate"; "VG"; "/dev/sda1"];
["lvcreate_free"; "LV1"; "VG"; "50"];
["lvcreate_free"; "LV2"; "VG"; "50"];
["lvcreate_free"; "LV3"; "VG"; "50"];
["lvcreate_free"; "LV4"; "VG"; "100"];
["lvs"]],
["/dev/VG/LV1"; "/dev/VG/LV2"; "/dev/VG/LV3"; "/dev/VG/LV4"])],
"create an LVM logical volume in % remaining free space",
"\
Create an LVM logical volume called C</dev/volgroup/logvol>,
using approximately C<percent> % of the free space remaining
in the volume group. Most usefully, when C<percent> is C<100>
this will create the largest possible LV.");
]
let all_functions = non_daemon_functions @ daemon_functions

View File

@@ -1 +1 @@
311
312