提交 30f555c6 编写于 作者: S Serge E. Hallyn 提交者: Eric Blake

lvm storage backend: handle command_names=1 in lvm.conf

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: NSerge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 a111b9e2
...@@ -1400,7 +1400,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, ...@@ -1400,7 +1400,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
const char **regex, const char **regex,
int *nvars, int *nvars,
virStorageBackendListVolRegexFunc func, virStorageBackendListVolRegexFunc func,
void *data) void *data, const char *prefix)
{ {
int fd = -1, err, ret = -1; int fd = -1, err, ret = -1;
FILE *list = NULL; FILE *list = NULL;
...@@ -1460,13 +1460,20 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, ...@@ -1460,13 +1460,20 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
} }
while (fgets(line, sizeof(line), list) != NULL) { while (fgets(line, sizeof(line), list) != NULL) {
char *p = NULL;
/* Strip trailing newline */ /* Strip trailing newline */
int len = strlen(line); int len = strlen(line);
if (len && line[len-1] == '\n') if (len && line[len-1] == '\n')
line[len-1] = '\0'; 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++) { 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++; maxReg++;
if (i == 0) if (i == 0)
...@@ -1475,9 +1482,9 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, ...@@ -1475,9 +1482,9 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
/* NULL terminate each captured group in the line */ /* NULL terminate each captured group in the line */
for (j = 0 ; j < nvars[i] ; j++) { for (j = 0 ; j < nvars[i] ; j++) {
/* NB vars[0] is the full pattern, so we offset j by 1 */ /* 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++] = if ((groups[ngroup++] =
strdup(line + vars[j+1].rm_so)) == NULL) { strdup(p + vars[j+1].rm_so)) == NULL) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
......
...@@ -140,7 +140,7 @@ int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool, ...@@ -140,7 +140,7 @@ int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
const char **regex, const char **regex,
int *nvars, int *nvars,
virStorageBackendListVolRegexFunc func, virStorageBackendListVolRegexFunc func,
void *data); void *data, const char *cmd_to_ignore);
int virStorageBackendRunProgNul(virStoragePoolObjPtr pool, int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
const char **prog, const char **prog,
......
...@@ -266,7 +266,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE ...@@ -266,7 +266,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSE
if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars, if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
virStorageBackendFileSystemNetFindPoolSourcesFunc, virStorageBackendFileSystemNetFindPoolSourcesFunc,
&state) < 0) &state, NULL) < 0)
goto cleanup; goto cleanup;
retval = virStoragePoolSourceListFormat(&state.list); retval = virStoragePoolSourceListFormat(&state.list);
......
...@@ -160,7 +160,7 @@ virStorageBackendISCSISession(virStoragePoolObjPtr pool, ...@@ -160,7 +160,7 @@ virStorageBackendISCSISession(virStoragePoolObjPtr pool,
regexes, regexes,
vars, vars,
virStorageBackendISCSIExtractSession, virStorageBackendISCSIExtractSession,
&session) < 0) &session, NULL) < 0)
return NULL; return NULL;
if (session == NULL && if (session == NULL &&
...@@ -517,7 +517,7 @@ virStorageBackendISCSIScanTargets(const char *portal, ...@@ -517,7 +517,7 @@ virStorageBackendISCSIScanTargets(const char *portal,
regexes, regexes,
vars, vars,
virStorageBackendISCSIGetTargets, virStorageBackendISCSIGetTargets,
&list) < 0) { &list, NULL) < 0) {
return -1; return -1;
} }
......
...@@ -211,7 +211,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool, ...@@ -211,7 +211,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
regexes, regexes,
vars, vars,
virStorageBackendLogicalMakeVol, virStorageBackendLogicalMakeVol,
vol) < 0) { vol, "lvs") < 0) {
return -1; return -1;
} }
...@@ -329,7 +329,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -329,7 +329,7 @@ virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars, if (virStorageBackendRunProgRegex(NULL, prog, 1, regexes, vars,
virStorageBackendLogicalFindPoolSourcesFunc, virStorageBackendLogicalFindPoolSourcesFunc,
&sourceList) < 0) &sourceList, "pvs") < 0)
return NULL; return NULL;
retval = virStoragePoolSourceListFormat(&sourceList); retval = virStoragePoolSourceListFormat(&sourceList);
...@@ -503,7 +503,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -503,7 +503,7 @@ virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
regexes, regexes,
vars, vars,
virStorageBackendLogicalRefreshPoolFunc, virStorageBackendLogicalRefreshPoolFunc,
NULL) < 0) { NULL, "vgs") < 0) {
virStoragePoolObjClearVols(pool); virStoragePoolObjClearVols(pool);
return -1; return -1;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册