[PATCH 1/3] sysprep: Replace --user-accounts option with --{remove, keep}-user-accounts.
by Richard W.M. Jones
The --user-accounts option, with its double-negative '-' prefix on
user names, is confusing. Replace it with '--remove-user-accounts'
and '--keep-user-accounts' options.
This updates commit 128d474095bfabc2d724d0181155e364f1afbabf.
---
sysprep/sysprep_operation_user_account.ml | 60 ++++++++++++++++---------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/sysprep/sysprep_operation_user_account.ml b/sysprep/sysprep_operation_user_account.ml
index 3ed1b6e..c514286 100644
--- a/sysprep/sysprep_operation_user_account.ml
+++ b/sysprep/sysprep_operation_user_account.ml
@@ -28,38 +28,26 @@ module G = Guestfs
module StringSet = Set.Make (String)
-let users_included = ref StringSet.empty
-let users_excluded = ref StringSet.empty
-let set_users users =
+let remove_users = ref StringSet.empty
+let keep_users = ref StringSet.empty
+let add_users set users =
let users = string_nsplit "," users in
List.iter (
- fun user ->
- let op =
- if string_prefix user "-" then
- `Exclude (String.sub user 1 (String.length user - 1))
- else
- `Include user in
- match op with
- | `Include "" | `Exclude "" ->
- eprintf (f_"%s: --user-accounts: empty user name\n")
- prog;
- exit 1
- | `Include n ->
- users_included := StringSet.add n !users_included;
- users_excluded := StringSet.remove n !users_excluded
- | `Exclude n ->
- users_included := StringSet.remove n !users_included;
- users_excluded := StringSet.add n !users_excluded
+ function
+ | "" ->
+ error ~prog (f_"user-accounts: empty user name")
+ | user ->
+ set := StringSet.add user !set
) users
let check_remove_user user =
(* If an user is explicitly excluded, keep it. *)
- if StringSet.mem user !users_excluded then
+ if StringSet.mem user !keep_users then
false
(* If the list of included users is empty (thus no users were explicitly
* included), or an user is explicitly included, remove it. *)
- else if StringSet.is_empty !users_included
- or StringSet.mem user !users_included then
+ else if StringSet.is_empty !remove_users
+ || StringSet.mem user !remove_users then
true
(* Any other case, not a reason to remove it. *)
else
@@ -112,24 +100,38 @@ let op = {
By default remove all the user accounts and their home directories.
The \"root\" account is not removed.
-See the I<--user-accounts> parameter for a way to specify
+See the I<--remove-user-accounts> parameter for a way to specify
how to remove only some users, or to not remove some others.");
extra_args = [
- { extra_argspec = "--user-accounts", Arg.String set_users, s_"users" ^ " " ^ s_"Users to remove/keep";
+ { extra_argspec = "--remove-user-accounts", Arg.String (add_users remove_users), s_"users" ^ " " ^ s_"Users to remove";
extra_pod_argval = Some "USERS";
extra_pod_description = s_"\
-The user accounts to be removed (or not) from the guest.
+The user accounts to be removed from the guest.
The value of this option is a list of user names separated by comma,
-where specifying an user means it is going to be removed,
-while prepending C<-> in front of it name means it is not removed.
+where specifying an user means it is going to be removed.
For example:
- --user-accounts bob,eve
+ --remove-user-accounts bob,eve
would only remove the user accounts C<bob> and C<eve>.
This option can be specified multiple times."
};
+
+ { extra_argspec = "--keep-user-accounts", Arg.String (add_users keep_users), s_"users" ^ " " ^ s_"Users to keep";
+ extra_pod_argval = Some "USERS";
+ extra_pod_description = s_"\
+The user accounts to be kept in the guest.
+The value of this option is a list of user names separated by comma,
+where specifying an user means it is going to be kept.
+For example:
+
+ --keep-user-accounts mary
+
+would keep the user account C<mary>.
+
+This option can be specified multiple times."
+ };
];
perform_on_filesystems = Some user_account_perform;
}
--
2.0.4
10 years, 3 months
Scaling virt-df performance
by Dan Ryder (daryder)
Hello,
I have been looking at the "virt-df" libguestfs tool to get guest-level disk used/free statistics - specifically with Qemu-KVM/Openstack. This works great for a few Openstack instances, but when I begin to scale (even to ~30 instances/guests) the performance really takes a hit. The time it takes for the command to complete seems to scale linearly with the amount of guests/domains running on the hypervisor (note - I am using "virt-df" for all guests, not specifying one at a time; although I've tried that, too).
For ~30 guests, the "virt-df" command takes around 90 seconds to complete. We are looking to support a scale of 3,000-30,000 guests disk used/free. It looks like this won't be remotely possible using "virt-df".
Has anyone run into this same problem or something similar and can give me some suggestions to find a workaround?
Thanks,
Dan Ryder
10 years, 3 months
[PATCH] test-charset-fidelity: set iocharset in vfat/msdos FSes
by Pino Toscano
The default charset for these filesystems depends on how the kernel was
configured with, so explicitly set the default one (as specified in
Linux sources), eventually setting later a new one for the tests.
---
tests/charsets/test-charset-fidelity.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/charsets/test-charset-fidelity.c b/tests/charsets/test-charset-fidelity.c
index d149a3f..4b34b0e 100644
--- a/tests/charsets/test-charset-fidelity.c
+++ b/tests/charsets/test-charset-fidelity.c
@@ -55,8 +55,8 @@ static struct filesystem filesystems[] = {
{ "ext3", 0, 0, NULL, NULL, 0, 0 },
{ "ext4", 0, 0, NULL, NULL, 0, 0 },
{ "btrfs", 0, 0, NULL, "btrfs", 0, 0 },
- { "vfat", 1, 0, "utf8", NULL, 1, 1 },
- { "msdos", 1, 1, NULL, NULL, 0, 0 },
+ { "vfat", 1, 0, "iocharset=iso8859-1,utf8", NULL, 1, 1 },
+ { "msdos", 1, 1, "iocharset=iso8859-1", NULL, 0, 0 },
/* In reality NTFS is case insensitive, but the ntfs-3g driver isn't. */
{ "ntfs", 0, 0, NULL, "ntfs3g", 0, 0 },
};
--
1.9.3
10 years, 3 months
[PATCH] daemon: free the string on stringsbuf add failure
by Pino Toscano
If add_string_nodup fails free the passed string instead of leaking it,
as that string would have been owned by the stringbuf.
Adapt devsparts/list-disk-labels to this behaviour.
---
daemon/devsparts.c | 8 ++++----
daemon/guestfsd.c | 1 +
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 70d4ba5..d71a3b3 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -312,7 +312,6 @@ do_list_disk_labels (void)
{
DIR *dir = NULL;
struct dirent *d;
- char *rawdev = NULL;
DECLARE_STRINGSBUF (ret);
dir = opendir (GUESTFSDIR);
@@ -324,6 +323,7 @@ do_list_disk_labels (void)
errno = 0;
while ((d = readdir (dir)) != NULL) {
CLEANUP_FREE char *path = NULL;
+ char *rawdev = NULL;
if (d->d_name[0] == '.')
continue;
@@ -341,12 +341,13 @@ do_list_disk_labels (void)
goto error;
}
- if (add_string (&ret, d->d_name) == -1)
+ if (add_string (&ret, d->d_name) == -1) {
+ free (rawdev);
goto error;
+ }
if (add_string_nodup (&ret, rawdev) == -1)
goto error;
- rawdev = NULL; /* buffer now owned by the stringsbuf */
}
/* Check readdir didn't fail */
@@ -374,6 +375,5 @@ do_list_disk_labels (void)
error:
if (dir)
closedir (dir);
- free (rawdev);
return NULL;
}
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 3616f3a..4a24557 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -532,6 +532,7 @@ add_string_nodup (struct stringsbuf *sb, char *str)
reply_with_perror ("realloc");
free_stringslen (sb->argv, sb->size);
sb->argv = NULL;
+ free (str);
return -1;
}
sb->argv = new_argv;
--
1.9.3
10 years, 3 months
[PATCH] fish: fix small memory leak in completion
by Pino Toscano
Do not leak the small memory buffer with the path.
---
fish/destpaths.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fish/destpaths.c b/fish/destpaths.c
index 9c97bf0..f224106 100644
--- a/fish/destpaths.c
+++ b/fish/destpaths.c
@@ -154,7 +154,8 @@ complete_dest_paths_generator (const char *text, int state)
/* If we've got a partial path already, we need to list everything
* in that directory, otherwise list everything in /
*/
- char *p, *dir;
+ CLEANUP_FREE char *dir = NULL;
+ char *p;
struct guestfs_dirent_list *dirents;
p = strrchr (text, '/');
--
1.9.3
10 years, 3 months
[PATCH] lua: improve handle closing
by Pino Toscano
Swap guestfs_close and free_per_handle_table, so first the handle is
removed from the table and then freed. This avoids passing a stale
pointer to free_per_handle_table (which right now is not an issue, but
better make sure it is never so).
---
Maybe this could also fix the case described by the comment there,
as when a new 'g' with the address of an old 'g' would be created,
the old 'g' is now already gone from the per-handle table.
generator/lua.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/generator/lua.ml b/generator/lua.ml
index 5d5619c..fa6e9f2 100644
--- a/generator/lua.ml
+++ b/generator/lua.ml
@@ -168,13 +168,13 @@ guestfs_lua_create (lua_State *L)
static void
close_handle (lua_State *L, guestfs_h *g)
{
- guestfs_close (g);
/* There is a potential and hard-to-solve race here: If another
* thread allocates another 'g' at the same address, then
* get_per_handle_table might be called with the same address
* before we call free_per_handle_table here. XXX
*/
free_per_handle_table (L, g);
+ guestfs_close (g);
}
/* Finalizer. */
--
1.9.3
10 years, 3 months
[PATCH] resize: print FSes which cannot be expanded
by Pino Toscano
Should ease a bit the discovery of a filesystem which cannot be
expanded.
---
Maybe it would be worth to be printed in any case, even if not being
verbose?
resize/resize.ml | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 78ec81e..0485db0 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -558,7 +558,11 @@ read the man page virt-resize(1).
| ContentFS (("ntfs"), _) when !ntfs_available -> true
| ContentFS (("btrfs"), _) when !btrfs_available -> true
| ContentFS (("xfs"), _) when !xfs_available -> true
- | ContentFS (_, _) -> false
+ | ContentFS (fs, _) ->
+ if verbose then
+ eprintf "Unknown/unavailable method for expanding filesystem %s\n"
+ fs;
+ false
| ContentExtendedPartition -> false
else
fun _ -> false
--
1.9.3
10 years, 3 months
[PATCH] v2v: -o rhev: Don't break if image/metadata directory exists
by Richard W.M. Jones
As explained in the commit summary, if VDSM is going to create
metadata and image directories, then virt-v2v should not mkdir those
same directories (and hence fail).
I'm not really convinced this is the right approach.
I think instead of adding more and more hacks on top of '-o rhev'
which should split this output mode into two sub modes, one for
outputting to the RHEV Export Storage Domain (ie. "traditional"
imports) and one which can handle the --rhev* parameters and the Data
domain ('-o vdsm' perhaps?)
Rich.
10 years, 3 months
CoreOS support
by Keresztes Péter-Zoltán
Hello,
is CoreOS supported by libguestfs?
I was trying to run several commands some were successful others ended up with an error:
for example virt-df was OK but when I tried to do virt-resize I got the following error message:
root@ny2proxd03:/var/lib/vz/images/100# virt-resize --expand /dev/sda3 vm-100-disk-1.qcow2 vm-100-disk-1.qcow2.resized
Examining vm-100-disk-1.qcow2 ...
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
Fatal error: exception Guestfs.Error("lvs: call launch before using this function\n(in guestfish, don't forget to use the 'run' command)")
regards,
Peter
10 years, 3 months
[PATCH] ext2: fix small memory leak on error
by Pino Toscano
When failing to read the output of `readlink -f`, free the memory buffer
used for it.
---
src/ext2fs-c.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/ext2fs-c.c b/src/ext2fs-c.c
index 9e0770a..f3ca7dc 100644
--- a/src/ext2fs-c.c
+++ b/src/ext2fs-c.c
@@ -631,6 +631,7 @@ ext2_copy_file (struct ext2_data *data, const char *src, const char *dest)
}
if (fgets (new_dirname, PATH_MAX, fp) == NULL) {
pclose (fp);
+ free (new_dirname);
goto cont;
}
pclose (fp);
--
1.9.3
10 years, 3 months