[PATCH] btrfs: fix leak in btrfs_scrub_status
by Pino Toscano
Properly free the output buffer.
---
daemon/btrfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 2f875ae..050bf18 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -1814,7 +1814,7 @@ do_btrfs_scrub_status (const char *path)
CLEANUP_FREE char *path_buf = NULL;
CLEANUP_FREE char *err = NULL;
CLEANUP_FREE_STRING_LIST char **lines = NULL;
- char *out;
+ CLEANUP_FREE char *out = NULL;
int r;
guestfs_int_btrfsscrub *ret;
--
2.1.0
9 years, 6 months
[PATCH v4 0/3] btrfs: use CLEANUP_FREE_STRING_LIST for list free
by Chen Hanxiao
As Pino's comment, we should take advantage of
macro CLEANUP_FREE_STRING_LIST
v4: remove some redundant strdup
v3: fix test case failure
v2: properly initialize lines
Chen Hanxiao (3):
do_btrfs_qgroup_show: fix a bad return value
do_btrfs_subvolume_list: fix a bad return value
btrfs: use CLEANUP_FREE_STRING_LIST for list free
daemon/btrfs.c | 70 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 33 deletions(-)
--
2.1.0
9 years, 6 months
[PATCH] error log: keep more calloc and its error messages match
by Chen Hanxiao
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
cat/cat.c | 4 ++--
cat/ls.c | 4 ++--
daemon/md.c | 2 +-
daemon/stat.c | 2 +-
daemon/xattr.c | 2 +-
df/main.c | 4 ++--
edit/edit.c | 4 ++--
fish/fish.c | 6 +++---
fish/options.c | 4 ++--
inspector/inspector.c | 4 ++--
rescue/rescue.c | 6 +++---
11 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/cat/cat.c b/cat/cat.c
index 5a438ce..82f0055 100644
--- a/cat/cat.c
+++ b/cat/cat.c
@@ -191,7 +191,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -205,7 +205,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/cat/ls.c b/cat/ls.c
index 9161fb6..3bced54 100644
--- a/cat/ls.c
+++ b/cat/ls.c
@@ -293,7 +293,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -307,7 +307,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/daemon/md.c b/daemon/md.c
index 941d05d..08a17e3 100644
--- a/daemon/md.c
+++ b/daemon/md.c
@@ -394,7 +394,7 @@ parse_md_stat_line (char *line)
ret->guestfs_int_mdstat_list_val =
calloc (spaces+1, sizeof (struct guestfs_int_mdstat));
if (ret->guestfs_int_mdstat_list_val == NULL) {
- reply_with_perror ("malloc");
+ reply_with_perror ("calloc");
free (ret);
return NULL;
}
diff --git a/daemon/stat.c b/daemon/stat.c
index a784914..73f1922 100644
--- a/daemon/stat.c
+++ b/daemon/stat.c
@@ -138,7 +138,7 @@ do_internal_lstatnslist (const char *path, char *const *names)
ret->guestfs_int_statns_list_val =
calloc (nr_names, sizeof (guestfs_int_statns));
if (ret->guestfs_int_statns_list_val == NULL) {
- reply_with_perror ("malloc");
+ reply_with_perror ("calloc");
free (ret);
return NULL;
}
diff --git a/daemon/xattr.c b/daemon/xattr.c
index c32e1a7..8aa28d1 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -120,7 +120,7 @@ getxattrs (const char *path,
r = calloc (1, sizeof (*r));
if (r == NULL) {
- reply_with_perror ("malloc");
+ reply_with_perror ("calloc");
goto error;
}
diff --git a/df/main.c b/df/main.c
index a43c11f..517bd45 100644
--- a/df/main.c
+++ b/df/main.c
@@ -217,7 +217,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -231,7 +231,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/edit/edit.c b/edit/edit.c
index 775170b..b874492 100644
--- a/edit/edit.c
+++ b/edit/edit.c
@@ -226,7 +226,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -240,7 +240,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/fish/fish.c b/fish/fish.c
index 714a13c..c37368e 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -361,7 +361,7 @@ main (int argc, char *argv[])
}
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_N;
@@ -449,7 +449,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -463,7 +463,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/fish/options.c b/fish/options.c
index b1be711..da5015d 100644
--- a/fish/options.c
+++ b/fish/options.c
@@ -38,7 +38,7 @@ option_a (const char *arg, const char *format, struct drv **drvsp)
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
@@ -84,7 +84,7 @@ option_d (const char *arg, struct drv **drvsp)
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
diff --git a/inspector/inspector.c b/inspector/inspector.c
index 412384a..70b7cd3 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -196,7 +196,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -210,7 +210,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
diff --git a/rescue/rescue.c b/rescue/rescue.c
index 8c0b507..9e0a516 100644
--- a/rescue/rescue.c
+++ b/rescue/rescue.c
@@ -253,7 +253,7 @@ main (int argc, char *argv[])
access (argv[optind], F_OK) == 0) { /* simulate -a option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_a;
@@ -267,7 +267,7 @@ main (int argc, char *argv[])
} else { /* simulate -d option */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_d;
@@ -530,7 +530,7 @@ add_scratch_disk (struct drv **drvs)
/* Add the scratch disk to the drives list. */
drv = calloc (1, sizeof (struct drv));
if (!drv) {
- perror ("malloc");
+ perror ("calloc");
exit (EXIT_FAILURE);
}
drv->type = drv_scratch;
--
2.1.0
9 years, 6 months
[PATCH] daemon: parted: Always use -s option even with -m.
by Richard W.M. Jones
See: https://bugzilla.redhat.com/show_bug.cgi?id=1232241#c3
---
daemon/parted.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/daemon/parted.c b/daemon/parted.c
index a36e4e7..59760b4 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -356,7 +356,7 @@ print_partition_table (const char *device,
int r;
if (PARTED_OPT_HAS_M == parted_has_m_opt)
- r = command (&out, &err, str_parted, "-m", "--", device,
+ r = command (&out, &err, str_parted, "-m", "-s", "--", device,
"unit", "b",
"print", NULL);
else
--
2.3.1
9 years, 6 months
[PATCH v2 1/2] Modify public function: analyze_line, make it more flexible
by Cao jin
Mofify the function from fixed dilemiter to variabler. So,
it could be used in more APIs later. Also modified the existed caller
Signed-off-by: Cao jin <caoj.fnst(a)cn.fujitsu.com>
---
daemon/btrfs.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 39392f7..caa28ca 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -853,11 +853,10 @@ do_btrfs_fsck (const char *device, int64_t superblock, int repair)
* returns the next position following \n.
*/
static char *
-analyze_line (char *line, char **key, char **value)
+analyze_line (char *line, char **key, char **value, char delimiter)
{
char *p = line;
char *next = NULL;
- char delimiter = ':';
char *del_pos = NULL;
if (!line || *line == '\0') {
@@ -964,7 +963,7 @@ do_btrfs_subvolume_show (const char *subvolume)
* snapshots/test3
*
*/
- p = analyze_line(out, &key, &value);
+ p = analyze_line(out, &key, &value, ':');
if (!p) {
reply_with_error ("truncated output: %s", out);
return NULL;
@@ -984,7 +983,7 @@ do_btrfs_subvolume_show (const char *subvolume)
}
/* Read the lines and split into "key: value". */
- p = analyze_line(p, &key, &value);
+ p = analyze_line(p, &key, &value, ':');
while (key) {
/* snapshot is special, see the output above */
if (STREQLEN (key, "Snapshot(s)", sizeof ("Snapshot(s)") - 1)) {
@@ -994,7 +993,7 @@ do_btrfs_subvolume_show (const char *subvolume)
if (add_string (&ret, key) == -1)
return NULL;
- p = analyze_line(p, &key, &value);
+ p = analyze_line(p, &key, &value, ':');
while (key && !value) {
ss = realloc (ss, ss_len + strlen (key) + 1);
@@ -1008,7 +1007,7 @@ do_btrfs_subvolume_show (const char *subvolume)
ss_len += strlen (key);
ss[ss_len] = '\0';
- p = analyze_line(p, &key, &value);
+ p = analyze_line(p, &key, &value, ':');
}
if (ss) {
@@ -1031,7 +1030,7 @@ do_btrfs_subvolume_show (const char *subvolume)
return NULL;
}
- p = analyze_line(p, &key, &value);
+ p = analyze_line(p, &key, &value, ':');
}
}
@@ -2083,3 +2082,4 @@ do_btrfs_image (char *const *sources, const char *image,
return 0;
}
+
--
2.1.0
9 years, 6 months
[PATCH 1/4] daemon: introduce free_stringsbuf
by Pino Toscano
Simple shortcut to easily cleanup a stringsbuf.
---
daemon/daemon.h | 1 +
daemon/guestfsd.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 53cb797..bed4dbc 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -92,6 +92,7 @@ extern int add_string (struct stringsbuf *sb, const char *str);
extern int add_sprintf (struct stringsbuf *sb, const char *fs, ...)
__attribute__((format (printf,2,3)));
extern int end_stringsbuf (struct stringsbuf *sb);
+extern void free_stringsbuf (struct stringsbuf *sb);
extern size_t count_strings (char *const *argv);
extern void sort_strings (char **argv, size_t len);
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index c912ee3..453dee1 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -587,6 +587,13 @@ end_stringsbuf (struct stringsbuf *sb)
return add_string_nodup (sb, NULL);
}
+void
+free_stringsbuf (struct stringsbuf *sb)
+{
+ if (sb->argv != NULL)
+ free_stringslen (sb->argv, sb->size);
+}
+
size_t
count_strings (char *const *argv)
{
--
2.1.0
9 years, 6 months
[PATCH] btrfs: keep calloc and its error message match
by Chen Hanxiao
commit 3f4ba2e98d21746723d291939ccc2e1f1526aa6d
left some error messages unchanged.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
daemon/btrfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c
index 7b14bac..e8059db 100644
--- a/daemon/btrfs.c
+++ b/daemon/btrfs.c
@@ -479,7 +479,7 @@ do_btrfs_subvolume_list (const mountable_t *fs)
ret->guestfs_int_btrfssubvolume_list_val =
calloc (nr_subvolumes, sizeof (struct guestfs_int_btrfssubvolume));
if (ret->guestfs_int_btrfssubvolume_list_val == NULL) {
- reply_with_perror ("malloc");
+ reply_with_perror ("calloc");
goto error;
}
@@ -1292,7 +1292,7 @@ do_btrfs_qgroup_show (const char *path)
ret->guestfs_int_btrfsqgroup_list_val =
calloc (nr_qgroups, sizeof (struct guestfs_int_btrfsqgroup));
if (ret->guestfs_int_btrfsqgroup_list_val == NULL) {
- reply_with_perror ("malloc");
+ reply_with_perror ("calloc");
goto error;
}
--
2.1.0
9 years, 6 months
[PATCH v3] Improve fixed appliance documentation
by Pino Toscano
Move the "FIXED APPLIANCE" section from
libguestfs-make-fixed-appliance(1) to the "INTERNALS" section of
guestfs(3), so it's more visible and less hidden in the documentation
of a rarely-used tool. Also slightly improve it.
Expand the FAQ question about libguestfs without supermin, mentioning
the build options needed and pointing to the aforementioned new section.
---
appliance/libguestfs-make-fixed-appliance.pod | 28 ++------------------
examples/guestfs-faq.pod | 11 +++++++-
src/guestfs.pod | 37 +++++++++++++++++++++++++++
3 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/appliance/libguestfs-make-fixed-appliance.pod b/appliance/libguestfs-make-fixed-appliance.pod
index 9807f80..99c55fa 100644
--- a/appliance/libguestfs-make-fixed-appliance.pod
+++ b/appliance/libguestfs-make-fixed-appliance.pod
@@ -38,8 +38,8 @@ L<guestfs-performance(1)>).
=back
-For deeper understanding of why you might need this tool, read the
-section L</FIXED APPLIANCE> below.
+For deeper understanding of why you might need this tool, read
+L<guestfs(3)/FIXED APPLIANCE>.
Instead of running this tool, you can download fixed appliances from
L<http://libguestfs.org/download/binaries/appliance/>. These
@@ -120,30 +120,6 @@ completely silent when it is running.
=back
-=head1 FIXED APPLIANCE
-
-When libguestfs (or libguestfs tools) are run, they search a path
-looking for an appliance. The path is built into libguestfs, or can
-be set using the C<LIBGUESTFS_PATH> environment variable.
-
-Normally a supermin appliance is located on this path (see
-L<supermin(1)/SUPERMIN APPLIANCE>). libguestfs reconstructs this
-into a full appliance by running C<supermin --build>.
-
-However, a simpler "fixed appliance" can also be used. libguestfs
-detects this by looking for a directory on the path containing four
-files called F<kernel>, F<initrd>, F<root> and F<README.fixed> (note
-the F<README.fixed> file must be present as well).
-
-If the fixed appliance is found, libguestfs skips supermin entirely
-and just runs qemu with the kernel, initrd and root disk from the
-fixed appliance.
-
-Thus the fixed appliance can be used when a platform or Linux distro
-does not support supermin. You build the fixed appliance on a
-platform that does support supermin, and copy it over, and use that
-to run libguestfs.
-
=head1 LICENSING
The fixed appliance is a complete Linux binary distro. If you
diff --git a/examples/guestfs-faq.pod b/examples/guestfs-faq.pod
index 8d52ab2..bc54c54 100644
--- a/examples/guestfs-faq.pod
+++ b/examples/guestfs-faq.pod
@@ -431,7 +431,16 @@ enough supermin installed, then see the previous question.
If supermin 5 doesn't support your distro at all, you will need to use
the "fixed appliance method" where you use a pre-compiled binary
-appliance. See: L<http://libguestfs.org/download/binaries/appliance/>
+appliance. To build libguestfs without supermin, you need to pass
+C<--disable-appliance --disable-daemon> to either F<./autogen.sh> or
+F<./configure> (depending whether you are building respectively from
+git or from tarballs). Then, when using libguestfs, you B<must> set
+the C<LIBGUESTFS_PATH> environment variable to the directory of a
+pre-compiled appliance, as also described in
+L<guestfs(3)/FIXED APPLIANCE>.
+
+For pre-compiled appliances, see also:
+L<http://libguestfs.org/download/binaries/appliance/>.
Patches to port supermin to more Linux distros are welcome.
diff --git a/src/guestfs.pod b/src/guestfs.pod
index fa04c86..a524fdf 100644
--- a/src/guestfs.pod
+++ b/src/guestfs.pod
@@ -3795,6 +3795,43 @@ The daemon self-limits the frequency of progress messages it sends
(see C<daemon/proto.c:notify_progress>). Not all calls generate
progress messages.
+=head2 FIXED APPLIANCE
+
+When libguestfs (or libguestfs tools) are run, they search a path
+looking for an appliance. The path is built into libguestfs, or can
+be set using the C<LIBGUESTFS_PATH> environment variable.
+
+Normally a supermin appliance is located on this path (see
+L<supermin(1)/SUPERMIN APPLIANCE>). libguestfs reconstructs this
+into a full appliance by running C<supermin --build>.
+
+However, a simpler "fixed appliance" can also be used. libguestfs
+detects this by looking for a directory on the path containing all
+the following files:
+
+=over 4
+
+=item * F<kernel>
+
+=item * F<initrd>
+
+=item * F<root>
+
+=item * F<README.fixed> (note that it B<must> be present as well)
+
+=back
+
+If the fixed appliance is found, libguestfs skips supermin entirely
+and just runs the virtual machine (using qemu or the current backend,
+see L</BACKEND>) with the kernel, initrd and root disk from the fixed
+appliance.
+
+Thus the fixed appliance can be used when a platform or a Linux
+distribution does not support supermin. You build the fixed appliance
+on a platform that does support supermin using
+L<libguestfs-make-fixed-appliance(1)>, copy it over, and use that
+to run libguestfs.
+
=head1 LIBGUESTFS VERSION NUMBERS
Since April 2010, libguestfs has started to make separate development
--
2.1.0
9 years, 6 months