daemon: Improve protocol debug messages.
[libguestfs.git] / daemon / daemon.h
index d90b65c..4a686c0 100644 (file)
 
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <errno.h>
 #include <unistd.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 
-#include "../src/guestfs_protocol.h"
+#include "guestfs_protocol.h"
 
 /*-- in guestfsd.c --*/
 extern int verbose;
 
+extern int autosync_umount;
+
 extern const char *sysroot;
 extern int sysroot_len;
 
 extern char *sysroot_path (const char *path);
 
+extern int is_root_device (const char *device);
+
 extern int xwrite (int sock, const void *buf, size_t len)
   __attribute__((__warn_unused_result__));
 extern int xread (int sock, void *buf, size_t len)
@@ -48,6 +53,8 @@ extern void sort_strings (char **argv, int len);
 extern void free_strings (char **argv);
 extern void free_stringslen (char **argv, int len);
 
+extern int is_power_of_2 (unsigned long v);
+
 #define command(out,err,name,...) commandf((out),(err),0,(name),__VA_ARGS__)
 #define commandr(out,err,name,...) commandrf((out),(err),0,(name),__VA_ARGS__)
 #define commandv(out,err,argv) commandvf((out),(err),0,(argv))
@@ -76,8 +83,8 @@ extern int prog_exists (const char *prog);
 
 extern void udev_settle (void);
 
-/* This just stops gcc from giving a warning about our custom
- * printf formatters %Q and %R.  See HACKING file for more
+/* This just stops gcc from giving a warning about our custom printf
+ * formatters %Q and %R.  See guestfs(3)/EXTENDING LIBGUESTFS for more
  * info about these.
  */
 static inline int
@@ -98,9 +105,11 @@ extern const char *function_names[];
 /*-- in proto.c --*/
 extern int proc_nr;
 extern int serial;
+extern uint64_t progress_hint;
+extern uint64_t optargs_bitmask;
 
 /*-- in mount.c --*/
-extern int root_mounted;
+extern int is_root_mounted (void);
 
 /*-- in stubs.c (auto-generated) --*/
 extern void dispatch_incoming_message (XDR *);
@@ -119,6 +128,9 @@ extern struct optgroup optgroups[];
 /* Use this as a replacement for sync(2). */
 extern int sync_disks (void);
 
+/*-- in lvm.c --*/
+extern int lv_canonical (const char *device, char **ret);
+
 /*-- in proto.c --*/
 extern void main_loop (int sock) __attribute__((noreturn));
 
@@ -157,12 +169,18 @@ extern int send_file_end (int cancel);
 /* only call this if there is a FileOut parameter */
 extern void reply (xdrproc_t xdrp, char *ret);
 
+/* Notify progress to caller.  This function is self-rate-limiting so
+ * you can call it as often as necessary.  Actions which call this
+ * should add 'Progress' note in generator.
+ */
+extern void notify_progress (uint64_t position, uint64_t total);
+
 /* Helper for functions that need a root filesystem mounted.
  * NB. Cannot be used for FileIn functions.
  */
 #define NEED_ROOT(cancel_stmt,fail_stmt)                                \
   do {                                                                 \
-    if (!root_mounted) {                                               \
+    if (!is_root_mounted ()) {                                         \
       if ((cancel_stmt) != -2)                                          \
         reply_with_error ("%s: you must call 'mount' first to mount the root filesystem", __func__); \
       fail_stmt;                                                       \
@@ -196,6 +214,8 @@ extern void reply (xdrproc_t xdrp, char *ret);
         reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \
       fail_stmt;                                                       \
     }                                                                  \
+    if (is_root_device (path))                                          \
+      reply_with_error ("%s: %s: device not found", __func__, path);    \
     if (device_name_translation ((path)) == -1) {                       \
       int err = errno;                                                  \
       int r = cancel_stmt;                                              \
@@ -235,17 +255,21 @@ extern void reply (xdrproc_t xdrp, char *ret);
  */
 #define CHROOT_IN                              \
   do {                                         \
-    int __old_errno = errno;                   \
-    if (chroot (sysroot) == -1)                        \
-      perror ("CHROOT_IN: sysroot");           \
-    errno = __old_errno;                       \
+    if (sysroot_len > 0) {                      \
+      int __old_errno = errno;                 \
+      if (chroot (sysroot) == -1)               \
+        perror ("CHROOT_IN: sysroot");         \
+      errno = __old_errno;                     \
+    }                                           \
   } while (0)
 #define CHROOT_OUT                             \
   do {                                         \
-    int __old_errno = errno;                   \
-    if (chroot (".") == -1)                    \
-      perror ("CHROOT_OUT: .");                        \
-    errno = __old_errno;                       \
+    if (sysroot_len > 0) {                      \
+      int __old_errno = errno;                 \
+      if (chroot (".") == -1)                  \
+        perror ("CHROOT_OUT: .");               \
+      errno = __old_errno;                     \
+    }                                           \
   } while (0)
 
 /* Marks functions which are not implemented.