btrfs: Modify mkfs-btrfs API so it takes a list of devices.

btrfs filesystems can span multiple filesystems.

Note this changes the API, but this API has not yet been released in a
stable version of libguestfs.
This commit is contained in:
Richard W.M. Jones
2012-04-25 16:33:31 +01:00
parent bd1a699c15
commit 3cc9703f90
2 changed files with 20 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/* libguestfs - the guestfsd daemon
* Copyright (C) 2011 Red Hat Inc.
* Copyright (C) 2011-2012 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,8 +28,6 @@
#include "actions.h"
#include "optgroups.h"
#define MAX_ARGS 64
int
optgroup_btrfs_available (void)
{
@@ -40,6 +38,7 @@ optgroup_btrfs_available (void)
int
do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
{
const size_t MAX_ARGS = 64;
char *buf;
char *err;
int r;
@@ -87,13 +86,21 @@ do_btrfs_filesystem_resize (const char *filesystem, int64_t size)
/* Takes optional arguments, consult optargs_bitmask. */
int
do_mkfs_btrfs (const char *device,
do_mkfs_btrfs (char *const *devices,
int64_t allocstart, int64_t bytecount, const char *datatype,
int leafsize, const char *label, const char *metadata,
int nodesize, int sectorsize)
{
size_t nr_devices = count_strings (devices);
if (nr_devices == 0) {
reply_with_error ("list of devices must be non-empty");
return -1;
}
size_t MAX_ARGS = nr_devices + 64;
const char *argv[MAX_ARGS];
size_t i = 0;
size_t i = 0, j;
int r;
char *err;
char allocstart_s[64];
@@ -180,12 +187,14 @@ do_mkfs_btrfs (const char *device,
ADD_ARG (argv, i, sectorsize_s);
}
ADD_ARG (argv, i, device);
for (j = 0; j < nr_devices; ++j)
ADD_ARG (argv, i, devices[j]);
ADD_ARG (argv, i, NULL);
r = commandv (NULL, &err, argv);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
reply_with_error ("%s: %s", devices[0], err);
free (err);
return -1;
}

View File

@@ -6929,7 +6929,7 @@ replacement
=back");
("mkfs_btrfs", (RErr, [Device "device"], [OInt64 "allocstart"; OInt64 "bytecount"; OString "datatype"; OInt "leafsize"; OString "label"; OString "metadata"; OInt "nodesize"; OInt "sectorsize"]), 317, [Optional "btrfs"],
("mkfs_btrfs", (RErr, [DeviceList "devices"], [OInt64 "allocstart"; OInt64 "bytecount"; OString "datatype"; OInt "leafsize"; OString "label"; OString "metadata"; OInt "nodesize"; OInt "sectorsize"]), 317, [Optional "btrfs"],
[InitEmpty, Always, TestRun (
[["part_disk"; "/dev/sda"; "mbr"];
["mkfs_btrfs"; "/dev/sda1"; "0"; "268435456"; "single"; "4096"; "test"; "single"; "4096"; "512"]])],
@@ -6938,6 +6938,9 @@ replacement
Create a btrfs filesystem, allowing all configurables to be set.
For more information on the optional arguments, see L<mkfs.btrfs(8)>.
Since btrfs filesystems can span multiple devices, this takes a
non-empty list of devices.
To create general filesystems, use C<guestfs_mkfs_opts>.");
("get_e2attrs", (RString "attrs", [Pathname "file"], []), 318, [],