Skip to content

Commit c78798f

Browse files
kostaslambdagermanop
authored andcommitted
CA-174119: Infer SR alloc type from xenvm config file's existence
If file '/etc/xenvm.d/VG_XenStorage-<UUID>' exists, the SR's allocation is 'dynamic' and 'xenvm' is called. If not, the normal lvm commands are used. Signed-off-by: Kostas Ladopoulos <[email protected]> Reviewed-by: Jorge Martin <[email protected]>
1 parent 8a17e9e commit c78798f

File tree

1 file changed

+9
-50
lines changed

1 file changed

+9
-50
lines changed

lvm/lvm-util.c

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <stdlib.h>
2525
#include <string.h>
2626
#include <syslog.h>
27+
#include <unistd.h>
2728

2829
#include "lvm-util.h"
2930

@@ -99,61 +100,27 @@ lvm_parse_pv(struct vg *vg, const char *name, int pvs, uint64_t start)
99100
static int
100101
lvm_create_cmd(char *out, const char *command, const char *vgname)
101102
{
102-
char path[96] = "/var/run/nonpersistent/sr_alloc_";
103+
char path[96] = "/etc/xenvm.d/";
103104
char vgs_opts[] = "vg_name,vg_extent_size,lv_count,"
104-
"pv_count,pv_name,pe_start";
105+
"pv_count,pv_name,pe_start";
105106
char lvs_opts[] = "lv_name,lv_size,segtype,seg_count,"
106-
"seg_start,seg_size,devices";
107-
char sr_alloc[8];
108-
char *c;
109-
FILE *f = 0;
110-
int dnmc_flag;
107+
"seg_start,seg_size,devices";
111108
int err = 0;
112109

113110
if (strcmp(command, "vgs") && strcmp(command, "lvs")) {
114111
err = EINVAL;
115112
goto exit;
116113
}
117114

118-
/* 'vgname' is a string that looks like:
115+
/**
116+
* 'vgname' is a string in the form:
119117
* 'VG_XenStorage-85fcc87c-0167-acf1-da64-ed982543add8'.
120-
* '+14' is used to strip the 'VG_XenStorage-' part.
121118
*/
122-
strcat(path, vgname + 14);
123-
124-
if ((f = fopen(path, "r"))) {
125-
if (!fgets(sr_alloc, 8, f)) {
126-
if ((err = ferror(f))) {
127-
} else if ((err = feof(f))) {
128-
} else { /* Unknown error */
129-
err = 666;
130-
}
131-
132-
goto exit;
133-
}
134-
135-
if ((c = strchr(sr_alloc, '\n'))) {
136-
*c = '\0';
137-
}
138-
139-
/* "dnmc": dynamic
140-
* "thck": thick
141-
*/
142-
if (!strcmp(sr_alloc, "dnmc")) {
143-
dnmc_flag = 1;
144-
} else if (!strcmp(sr_alloc, "thck")) {
145-
dnmc_flag = 0;
146-
} else {
147-
err = EINVAL;
148-
goto exit;
149-
}
150-
151-
} else { /* Fallback to original LVM commands. */
152-
dnmc_flag = 0;
153-
}
119+
strcat(path, vgname);
154120

155121
/* Construct the lvm command. */
156-
strcpy(out, dnmc_flag ? "/bin/xenvm " : "");
122+
/* This file exists only if the SR is of type 'dynamic'. */
123+
strcpy(out, access(path, F_OK) ? "" : "/bin/xenvm ");
157124

158125
strcat(out, command);
159126
strcat(out, " ");
@@ -165,10 +132,6 @@ lvm_create_cmd(char *out, const char *command, const char *vgname)
165132
strcat(out, " 2> /dev/null");
166133

167134
exit:
168-
if (f) {
169-
fclose(f);
170-
f = 0;
171-
}
172135
return -err;
173136
}
174137

@@ -390,16 +353,12 @@ lvm_scan_vg(const char *vg_name, struct vg *vg)
390353
if (err)
391354
return err;
392355

393-
fprintf(stderr, "lvm_open_vg success");
394-
395356
err = lvm_scan_lvs(vg);
396357
if (err) {
397358
lvm_free_vg(vg);
398359
return err;
399360
}
400361

401-
fprintf(stderr, "lvm_scan_lvs success");
402-
403362
return 0;
404363
}
405364

0 commit comments

Comments
 (0)