]> xenbits.xensource.com Git - libvirt.git/commitdiff
lvm storage backend: handle command_names=1 in lvm.conf
authorSerge E. Hallyn <serge.hallyn@canonical.com>
Wed, 28 Sep 2011 20:08:34 +0000 (15:08 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 30 Sep 2011 21:17:44 +0000 (15:17 -0600)
If the regexes supported (?:pvs)?, then we could handle this by
optionally matching but not returning the initial command name.  But it
doesn't.  So add a new char* argument to
virStorageBackendRunProgRegex().  If that argument is NULL then we act
as usual.  Otherwise, if the string at that argument is found at the
start of a returned line, we drop that before running the regex.

With this patch, virt-manager shows me lvs with command_names 1 or 0.

The definitions of PVS_BASE etc may want to be moved into the configure
scripts (though given how PVS is found, IIUC that could only happen if
pvs was a link to pvs_real), but in any case no sense dealing with that
until we're sure this is an ok way to handle it.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_fs.c
src/storage/storage_backend_iscsi.c
src/storage/storage_backend_logical.c

index d125504b441245bfdf2f354eff3b29d4f8e4f6f6..64c35c2bf3d46cd823c4f18d27364e3011183083 100644 (file)
@@ -1400,7 +1400,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
                               const char **regex,
                               int *nvars,
                               virStorageBackendListVolRegexFunc func,
-                              void *data)
+                              void *data, const char *prefix)
 {
     int fd = -1, err, ret = -1;
     FILE *list = NULL;
@@ -1460,13 +1460,20 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
     }
 
     while (fgets(line, sizeof(line), list) != NULL) {
+        char *p = NULL;
         /* Strip trailing newline */
         int len = strlen(line);
         if (len && line[len-1] == '\n')
             line[len-1] = '\0';
 
+        /* ignore any command prefix */
+        if (prefix)
+            p = STRSKIP(line, prefix);
+        if (!p)
+            p = line;
+
         for (i = 0 ; i <= maxReg && i < nregex ; i++) {
-            if (regexec(&reg[i], line, nvars[i]+1, vars, 0) == 0) {
+            if (regexec(&reg[i], p, nvars[i]+1, vars, 0) == 0) {
                 maxReg++;
 
                 if (i == 0)
@@ -1475,9 +1482,9 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
                 /* NULL terminate each captured group in the line */
                 for (j = 0 ; j < nvars[i] ; j++) {
                     /* NB vars[0] is the full pattern, so we offset j by 1 */
-                    line[vars[j+1].rm_eo] = '\0';
+                    p[vars[j+1].rm_eo] = '\0';
                     if ((groups[ngroup++] =
-                         strdup(line + vars[j+1].rm_so)) == NULL) {
+                         strdup(p + vars[j+1].rm_so)) == NULL) {
                         virReportOOMError();
                         goto cleanup;
                     }
index 67ac32c7ae3af2d1fdd560b16657044a57a64fc2..75ed676f8385f53e417d7b16421e85c870c16b16 100644 (file)
@@ -140,7 +140,7 @@ int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
                                   const char **regex,
                                   int *nvars,
                                   virStorageBackendListVolRegexFunc func,
-                                  void *data);
+                                  void *data, const char *cmd_to_ignore);
 
 int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
                                 const char **prog,
index da98f87b512e0fbd3f39bbd46d6ea00f1c997e90..d6786259bbc19419c0fc937920bf9d2d87238c9a 100644 (file)
@@ -266,7 +266,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
 
     if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
                             virStorageBackendFileSystemNetFindPoolSourcesFunc,
-                            &state) < 0)
+                            &state, NULL) < 0)
         goto cleanup;
 
     retval = virStoragePoolSourceListFormat(&state.list);
index 346e698050012e844e6e2c86479b3409b6f1cbd6..99e69c9a63179c301ce77f1d574e80d190247de3 100644 (file)
@@ -160,7 +160,7 @@ virStorageBackendISCSISession(virStoragePoolObjPtr pool,
                                       regexes,
                                       vars,
                                       virStorageBackendISCSIExtractSession,
-                                      &session) < 0)
+                                      &session, NULL) < 0)
         return NULL;
 
     if (session == NULL &&
@@ -517,7 +517,7 @@ virStorageBackendISCSIScanTargets(const char *portal,
                                       regexes,
                                       vars,
                                       virStorageBackendISCSIGetTargets,
-                                      &list) < 0) {
+                                      &list, NULL) < 0) {
         return -1;
     }
 
index 23d80cbe6d318d792b73e417c53e4707d6a8adf3..589f486fe7c09fda53b4aa72cff6f8601b02cf8d 100644 (file)
@@ -211,7 +211,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
                                       regexes,
                                       vars,
                                       virStorageBackendLogicalMakeVol,
-                                      vol) < 0) {
+                                      vol, "lvs") < 0) {
         return -1;
     }
 
@@ -329,7 +329,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
 
     if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
                                 virStorageBackendLogicalFindPoolSourcesFunc,
-                                &sourceList) < 0)
+                                &sourceList, "pvs") < 0)
         return NULL;
 
     retval = virStoragePoolSourceListFormat(&sourceList);
@@ -503,7 +503,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                       regexes,
                                       vars,
                                       virStorageBackendLogicalRefreshPoolFunc,
-                                      NULL) < 0) {
+                                      NULL, "vgs") < 0) {
         virStoragePoolObjClearVols(pool);
         return -1;
     }