]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Added --readonly flag to virsh
authorDaniel P. Berrange <berrange@redhat.com>
Thu, 8 Mar 2007 13:48:22 +0000 (13:48 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 8 Mar 2007 13:48:22 +0000 (13:48 +0000)
ChangeLog
src/virsh.c

index c47b7cbb33b34b1330faa3ab5daf35ed6795df2d..d19a623df99251ee0a87dd710e2eb906e2584802 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Thu Mar  8 08:45:46 EST 2007 Daniel P., Berrange <berrange@redhat.com>
+
+       * src/virsh.c: Added an explicit --readonly option to virsh
+       to override the simple Xen-specific heuristic when running
+       as non-root. Patch from Rich Jones
+
 Thu Mar  8 09:54:46 CET 2007 Daniel Veillard <veillard@redhat.com>
 
        * src/xml.c: applied patch from Nobuhiro Itou to allow the
index 9434dbd37b79f05563d822e24802d5c5914c2294..445d3fb9ef6ed61fc1cfd1b5d88a58cc8e025aec 100644 (file)
@@ -171,6 +171,9 @@ typedef struct __vshControl {
     int quiet;                  /* quiet mode */
     int debug;                  /* print debug messages? */
     int timing;                 /* print timing info? */
+    int readonly;               /* connect readonly (first time only, not
+                                 * during explicit connect command)
+                                 */
 } __vshControl;
 
 
@@ -371,10 +374,13 @@ cmdConnect(vshControl * ctl, vshCmd * cmd)
         free(ctl->name);
     ctl->name = vshStrdup(ctl, vshCommandOptString(cmd, "name", NULL));
 
-    if (!ro)
+    if (!ro) {
         ctl->conn = virConnectOpen(ctl->name);
-    else
+        ctl->readonly = 0;
+    } else {
         ctl->conn = virConnectOpenReadOnly(ctl->name);
+        ctl->readonly = 1;
+    }
 
     if (!ctl->conn)
         vshError(ctl, FALSE, _("Failed to connect to the hypervisor"));
@@ -3137,12 +3143,12 @@ vshInit(vshControl * ctl)
     /* set up the library error handler */
     virSetErrorFunc(NULL, virshErrorHandler);
 
-    /* basic connection to hypervisor, for Xen connections unless
-       we're root open a read only connections. Allow 'test' HV
-       to be RW all the time though */
-    if (ctl->uid == 0 || (ctl->name && 
-                         (!strncmp(ctl->name, "test", 4) ||
-                          !strncmp(ctl->name, "qemu", 4))))
+    /* Force a non-root, Xen connection to readonly */
+    if ((ctl->name == NULL ||
+         !strcasecmp(ctl->name, "xen")) && ctl->uid != 0)
+         ctl->readonly = 1;
+
+    if (!ctl->readonly)
         ctl->conn = virConnectOpen(ctl->name);
     else
         ctl->conn = virConnectOpenReadOnly(ctl->name);
@@ -3299,6 +3305,7 @@ vshUsage(vshControl * ctl, const char *cmdname)
         fprintf(stdout, _("\n%s [options] [commands]\n\n"
                           "  options:\n"
                           "    -c | --connect <uri>    hypervisor connection URI\n"
+                          "    -r | --readonly         connect readonly\n"
                           "    -d | --debug <num>      debug level [0-5]\n"
                           "    -h | --help             this help\n"
                           "    -q | --quiet            quiet mode\n"
@@ -3336,6 +3343,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
         {"timing", 0, 0, 't'},
         {"version", 0, 0, 'v'},
         {"connect", 1, 0, 'c'},
+        {"readonly", 0, 0, 'r'},
         {0, 0, 0, 0}
     };
 
@@ -3378,7 +3386,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
     end = end ? : argc;
 
     /* standard (non-command) options */
-    while ((arg = getopt_long(end, argv, "d:hqtc:v", opt, &idx)) != -1) {
+    while ((arg = getopt_long(end, argv, "d:hqtc:vr", opt, &idx)) != -1) {
         switch (arg) {
         case 'd':
             ctl->debug = atoi(optarg);
@@ -3398,6 +3406,9 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
         case 'v':
             fprintf(stdout, "%s\n", VERSION);
             exit(EXIT_SUCCESS);
+        case 'r':
+            ctl->readonly = TRUE;
+            break;
         default:
             vshError(ctl, TRUE,
                      _("unsupported option '-%c'. See --help."), arg);