Commit Graph

31 Commits

Author SHA1 Message Date
Richard W.M. Jones
2ecccfce38 daemon: Replace "noalloc" with [@@noalloc] 2021-12-09 13:54:15 +00:00
Richard W.M. Jones
fe01905729 daemon: Reimplement ‘md_detail’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
2ca0fa778d daemon: Reimplement ‘list_md_devices’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
381c8b68c4 daemon: Remove GUESTFSD_EXT_CMD.
GUESTFSD_EXT_CMD was used by OpenSUSE to track which external commands
are run by the daemon and package those commands into the appliance.

It is no longer used by recent SUSE builds, so remove it.

Thanks: Pino Toscano, Olaf Hering.
2017-07-27 17:31:41 +01:00
Richard W.M. Jones
707f5bcfe0 daemon: Link guestfsd with libutils.
After the previous refactoring, we are able to link the daemon to
common/utils, and also remove some of the "duplicate" functions that
the daemon carried ("duplicate" in quotes because they were often not
exact duplicates).

Also this removes the duplicate reimplementation of (most) cleanup
functions in the daemon, since those are provided by libutils now.

It also allows us in future (but not in this commit) to move utility
functions from the daemon into libutils.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
d5a8f82887 Use 'const' for stack integers where possible.
May improve optimization possibilities in a few cases.
2016-07-26 10:43:45 +01:00
Pino Toscano
9fa8e07465 daemon: fix cleanup of stringsbuf usages
Declare most of the stringsbuf as CLEANUP_FREE_STRINGSBUF, so they are
freed completely on stack unwind: use take_stringsbuf() in return
places to take away from the stringsbuf its content, and remove all the
manual calls to free_stringslen (no more needed now).
This requires to not use free_stringslen anymore on failure in the
helper functions of stringsbuf, which now leave the content as-is (might
be still useful even on error).

This allows us to simplify the memory management of stringsbuf's, which
are not properly fully freed, fixing memory leaks in some error paths
(which were not calling free_stringslen).
2016-07-07 16:28:18 +02:00
Richard W.M. Jones
07c496c53c Use less stack.
GCC has two warnings related to large stack frames.  We were already
using the -Wframe-larger-than warning, but this reduces the threshold
from 10000 to 5000 bytes.

However that warning only covers the static part of frames (not
alloca).  So this change also enables -Wstack-usage=10000 which covers
both the static and dynamic usage (alloca and variable length arrays).

Multiple changes are made throughout the code to reduce frames to fit
within these new limits.

Note that stack allocation of large strings can be a security issue.
For example, we had code like:

 size_t len = strlen (fs->windows_systemroot) + 64;
 char software[len];
 snprintf (software, len, "%s/system32/config/software",
           fs->windows_systemroot);

where fs->windows_systemroot is guest controlled.  It's not clear what
the effects might be of allowing the guest to allocate potentially
very large stack frames, but at best it allows the guest to cause
libguestfs to segfault.  It turns out we are very lucky that
fs->windows_systemroot cannot be set arbitrarily large (see checks in
is_systemroot).

This commit changes those to large heap allocations instead.
2016-03-07 17:36:24 +00:00
Richard W.M. Jones
4dc53f0fba Avoid gcc warnings about infinite loop.
This seemingly redundant change avoids a gcc warning/error:

  error: cannot optimize possibly infinite loops

See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=34114#c3 and
following for an explanation.

Of course gcc is completely wrong and stupid here, because there's no
possibility on current or future hardware that an array of size
SSIZE_MAX could be allocated since it would by definition occupy at
least all addressible memory (if it was an array of bytes, which this
isn't), leaving no room for the code that is being compiled.
2015-11-13 11:53:12 +00:00
Richard W.M. Jones
677c721e85 Fix whitespace.
Because of previous automated commits, such as changing 'guestfs___'
-> 'guestfs_int_', several function calls no longer lined up with
their parameters, and some lines were too long.

The bulk of this commit was done using emacs batch mode and the
technique described here:

  http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html

The changes suggested by emacs were then reviewed by hand.
2015-10-05 14:28:33 +01:00
Chen Hanxiao
d29337605a daemon: add a space after func/macro to fit code-style
more daemon codes covered

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-07-17 13:27:13 +01:00
Chen Hanxiao
3ae5f72743 error log: keep more calloc and its error messages match
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-06-18 10:19:41 +01:00
Richard W.M. Jones
8da50e5a3f daemon: md: Whitespace fix. 2014-03-26 20:08:36 +00:00
Richard W.M. Jones
90cafed4c2 daemon: list-md-devices: Check if a /dev/md<X> device is valid before returning it.
For reasons not fully understood, if md is linked into the kernel (and
not a module), a /dev/md0 device node is created.  However this is not
a real RAID device.  For example running mdadm --detail /dev/md0 will
fail on it.

Check the /dev/md<X> devices are real RAID devices before returning
them from the list-md-devices API.
2013-08-13 15:46:54 +01:00
Richard W.M. Jones
52188f1ea3 daemon: md: Whitespace fixes. 2013-08-13 15:46:54 +01:00
Richard W.M. Jones
e527aed895 getline: Rename &n parameter as &allocsize.
The second parameter passed into getline(3) is the size of the
allocated buffer, *NOT* the length of the returned line.  This can be
confusing, so rename this parameter as 'allocsize' consistently
throughout the code.

This is just code motion.
2013-02-11 13:21:51 +00:00
Richard W.M. Jones
950951c67d daemon: Use the new CLEANUP_* macros to simplify code. 2013-01-28 18:01:43 +00:00
Richard W.M. Jones
b18a1b4e66 md: Free up 'ret' along error path (found by Coverity). 2012-12-08 16:42:38 +00:00
Olaf Hering
0306c98d31 daemon: collect list of called external commands
guestfsd calls many different tools. Keeping track of all of them is
error prone. This patch introduces a new helper macro to put the command
string into its own ELF section:

GUESTFSD_EXT_CMD(C_variable, command_name);

This syntax makes it still possible to grep for used command names.

The actual usage of the collected list could be like this:

  objcopy -j .guestfsd_ext_cmds -O binary daemon/guestfsd /dev/stdout |
  tr '\0' '\n' | sort -u

The resulting output will be used to tell mkinitrd which programs to
copy into the initrd.

Signed-off-by: Olaf Hering <olaf@aepfle.de>

RWMJ:
 - Move str_vgchange at request of author.
 - Fix snprintf call in daemon/debug.c
2012-08-30 20:57:07 +01:00
Richard W.M. Jones
3f6cc550ff New API: md-stat.
This returns information about the underlying devices of an MD
(software RAID) device.
2012-03-20 18:50:24 +00:00
Richard W.M. Jones
710ec49bac daemon: Don't call reply_with_* after split_lines fails.
split_lines already sets reply_with_*, so calling it again would lose
protocol synchronization.
2012-03-16 14:11:02 +00:00
Richard W.M. Jones
14df5fa5d1 daemon: Implement a growable strings buffer type.
Previously a lot of daemon code used three variables (a string list,
'int size' and 'int alloc') to track growable strings buffers.  This
commit implements a simple struct containing the same variables, but
using size_t instead of int:

  struct stringsbuf {
    char **argv;
    size_t size;
    size_t alloc;
  };

Use it like this:

  DECLARE_STRINGSBUF (ret);
//...
  if (add_string (&ret, str) == -1)
    return NULL;
//...
  if (end_stringsbuf (&ret) == -1)
    return NULL;
  return ret.argv;
2012-03-13 08:19:11 +00:00
Richard W.M. Jones
9700708a19 daemon: Fix leaking error message (found by valgrind). 2012-01-24 17:00:37 +00:00
Richard W.M. Jones
ff2e685828 daemon: Fix leak of strings in md-detail (found by valgrind). 2012-01-24 17:00:36 +00:00
Richard W.M. Jones
4c2101362e daemon: md: Whitespace changes, and use size_t for i instead of pointer.
This is just a code clean-up with no functional change.
2012-01-24 17:00:32 +00:00
Richard W.M. Jones
2d5841133a debian: Use mdadm -D --export instead of mdadm -DY.
For compatibility with mdadm on Debian Squeeze.
2011-11-24 16:27:36 +00:00
Wanlong Gao
cbd1c45d95 New API: md-stop for stopping MD devices
This API is used to stop a md device.
When we want to move a device to another md array, we should
stop the md device which contained this device first.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-11-24 13:24:17 +00:00
Matthew Booth
182c25b2a4 Rename mdadm_ apis to md_
This change renames the following 2 apis:
* mdadm_create -> md_create
* mdadm_detail -> md_detail

This is more consistent with list_md_devices, and removes a reference to an
implementation detail from the api.
2011-11-24 13:22:42 +00:00
Matthew Booth
c4bd6bba8d New API: mdadm-detail. 2011-11-17 12:43:49 +00:00
Matthew Booth
00a0fab50b New API: list-md-devices.
Return a list of Linux MD devices detected in the guest.

This API complements list_devices, list_partitions, list_lvs and
list_dm_devices.
2011-11-11 22:52:31 +00:00
Richard W.M. Jones
c11a92751e New API: mdadm-create for creating MD devices. 2011-11-11 22:52:31 +00:00