@@ -72,98 +72,18 @@ struct virStorageBackendLogicalPoolVolData {
72
72
};
73
73
74
74
static int
75
- virStorageBackendLogicalMakeVol ( char * * const groups ,
76
- void * opaque )
75
+ virStorageBackendLogicalParseVolExtents ( virStorageVolDefPtr vol ,
76
+ char * * const groups )
77
77
{
78
- struct virStorageBackendLogicalPoolVolData * data = opaque ;
79
- virStoragePoolObjPtr pool = data -> pool ;
80
- virStorageVolDefPtr vol = NULL ;
81
- bool is_new_vol = false;
82
- unsigned long long offset , size , length ;
78
+ int nextents , ret = -1 ;
83
79
const char * regex_unit = "(\\S+)\\((\\S+)\\)" ;
84
80
char * regex = NULL ;
85
81
regex_t * reg = NULL ;
86
82
regmatch_t * vars = NULL ;
87
83
char * p = NULL ;
88
84
size_t i ;
89
- int err , nextents , nvars , ret = -1 ;
90
- const char * attrs = groups [9 ];
91
-
92
- /* Skip inactive volume */
93
- if (attrs [4 ] != 'a' )
94
- return 0 ;
95
-
96
- /*
97
- * Skip thin pools(t). These show up in normal lvs output
98
- * but do not have a corresponding /dev/$vg/$lv device that
99
- * is created by udev. This breaks assumptions in later code.
100
- */
101
- if (attrs [0 ] == 't' )
102
- return 0 ;
103
-
104
- /* See if we're only looking for a specific volume */
105
- if (data -> vol != NULL ) {
106
- vol = data -> vol ;
107
- if (STRNEQ (vol -> name , groups [0 ]))
108
- return 0 ;
109
- }
110
-
111
- /* Or filling in more data on an existing volume */
112
- if (vol == NULL )
113
- vol = virStorageVolDefFindByName (pool , groups [0 ]);
114
-
115
- /* Or a completely new volume */
116
- if (vol == NULL ) {
117
- if (VIR_ALLOC (vol ) < 0 )
118
- return -1 ;
119
-
120
- is_new_vol = true;
121
- vol -> type = VIR_STORAGE_VOL_BLOCK ;
122
-
123
- if (VIR_STRDUP (vol -> name , groups [0 ]) < 0 )
124
- goto cleanup ;
125
-
126
- }
127
-
128
- if (vol -> target .path == NULL ) {
129
- if (virAsprintf (& vol -> target .path , "%s/%s" ,
130
- pool -> def -> target .path , vol -> name ) < 0 )
131
- goto cleanup ;
132
- }
133
-
134
- /* Mark the (s) sparse/snapshot lv, e.g. the lv created using
135
- * the --virtualsize/-V option. We've already ignored the (t)hin
136
- * pool definition. In the manner libvirt defines these, the
137
- * thin pool is hidden to the lvs output, except as the name
138
- * in brackets [] described for the groups[1] (backingStore).
139
- */
140
- if (attrs [0 ] == 's' )
141
- vol -> target .sparse = true;
142
-
143
- /* Skips the backingStore of lv created with "--virtualsize",
144
- * its original device "/dev/$vgname/$lvname_vorigin" is
145
- * just for lvm internal use, one should never use it.
146
- *
147
- * (lvs outputs "[$lvname_vorigin] for field "origin" if the
148
- * lv is created with "--virtualsize").
149
- */
150
- if (groups [1 ] && STRNEQ (groups [1 ], "" ) && (groups [1 ][0 ] != '[' )) {
151
- if (VIR_ALLOC (vol -> target .backingStore ) < 0 )
152
- goto cleanup ;
153
-
154
- if (virAsprintf (& vol -> target .backingStore -> path , "%s/%s" ,
155
- pool -> def -> target .path , groups [1 ]) < 0 )
156
- goto cleanup ;
157
-
158
- vol -> target .backingStore -> format = VIR_STORAGE_POOL_LOGICAL_LVM2 ;
159
- }
160
-
161
- if (!vol -> key && VIR_STRDUP (vol -> key , groups [2 ]) < 0 )
162
- goto cleanup ;
163
-
164
- if (virStorageBackendUpdateVolInfo (vol , false,
165
- VIR_STORAGE_VOL_OPEN_DEFAULT , 0 ) < 0 )
166
- goto cleanup ;
85
+ int err , nvars ;
86
+ unsigned long long offset , size , length ;
167
87
168
88
nextents = 1 ;
169
89
if (STREQ (groups [4 ], VIR_STORAGE_VOL_LOGICAL_SEGTYPE_STRIPED )) {
@@ -174,7 +94,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
174
94
}
175
95
}
176
96
177
- /* Finally fill in extents information */
97
+ /* Allocate and fill in extents information */
178
98
if (VIR_REALLOC_N (vol -> source .extents ,
179
99
vol -> source .nextent + nextents ) < 0 )
180
100
goto cleanup ;
@@ -184,18 +104,13 @@ virStorageBackendLogicalMakeVol(char **const groups,
184
104
"%s" , _ ("malformed volume extent length value" ));
185
105
goto cleanup ;
186
106
}
107
+
187
108
if (virStrToLong_ull (groups [7 ], NULL , 10 , & size ) < 0 ) {
188
109
virReportError (VIR_ERR_INTERNAL_ERROR ,
189
110
"%s" , _ ("malformed volume extent size value" ));
190
111
goto cleanup ;
191
112
}
192
- if (virStrToLong_ull (groups [8 ], NULL , 10 , & vol -> target .allocation ) < 0 ) {
193
- virReportError (VIR_ERR_INTERNAL_ERROR ,
194
- "%s" , _ ("malformed volume allocation value" ));
195
- goto cleanup ;
196
- }
197
113
198
- /* Now parse the "devices" field separately */
199
114
if (VIR_STRDUP (regex , regex_unit ) < 0 )
200
115
goto cleanup ;
201
116
@@ -269,16 +184,119 @@ virStorageBackendLogicalMakeVol(char **const groups,
269
184
vol -> source .nextent ++ ;
270
185
}
271
186
187
+ ret = 0 ;
188
+
189
+ cleanup :
190
+ VIR_FREE (regex );
191
+ VIR_FREE (reg );
192
+ VIR_FREE (vars );
193
+ return ret ;
194
+ }
195
+
196
+
197
+ static int
198
+ virStorageBackendLogicalMakeVol (char * * const groups ,
199
+ void * opaque )
200
+ {
201
+ struct virStorageBackendLogicalPoolVolData * data = opaque ;
202
+ virStoragePoolObjPtr pool = data -> pool ;
203
+ virStorageVolDefPtr vol = NULL ;
204
+ bool is_new_vol = false;
205
+ int ret = -1 ;
206
+ const char * attrs = groups [9 ];
207
+
208
+ /* Skip inactive volume */
209
+ if (attrs [4 ] != 'a' )
210
+ return 0 ;
211
+
212
+ /*
213
+ * Skip thin pools(t). These show up in normal lvs output
214
+ * but do not have a corresponding /dev/$vg/$lv device that
215
+ * is created by udev. This breaks assumptions in later code.
216
+ */
217
+ if (attrs [0 ] == 't' )
218
+ return 0 ;
219
+
220
+ /* See if we're only looking for a specific volume */
221
+ if (data -> vol != NULL ) {
222
+ vol = data -> vol ;
223
+ if (STRNEQ (vol -> name , groups [0 ]))
224
+ return 0 ;
225
+ }
226
+
227
+ /* Or filling in more data on an existing volume */
228
+ if (vol == NULL )
229
+ vol = virStorageVolDefFindByName (pool , groups [0 ]);
230
+
231
+ /* Or a completely new volume */
232
+ if (vol == NULL ) {
233
+ if (VIR_ALLOC (vol ) < 0 )
234
+ return -1 ;
235
+
236
+ is_new_vol = true;
237
+ vol -> type = VIR_STORAGE_VOL_BLOCK ;
238
+
239
+ if (VIR_STRDUP (vol -> name , groups [0 ]) < 0 )
240
+ goto cleanup ;
241
+
242
+ }
243
+
244
+ if (vol -> target .path == NULL ) {
245
+ if (virAsprintf (& vol -> target .path , "%s/%s" ,
246
+ pool -> def -> target .path , vol -> name ) < 0 )
247
+ goto cleanup ;
248
+ }
249
+
250
+ /* Mark the (s) sparse/snapshot lv, e.g. the lv created using
251
+ * the --virtualsize/-V option. We've already ignored the (t)hin
252
+ * pool definition. In the manner libvirt defines these, the
253
+ * thin pool is hidden to the lvs output, except as the name
254
+ * in brackets [] described for the groups[1] (backingStore).
255
+ */
256
+ if (attrs [0 ] == 's' )
257
+ vol -> target .sparse = true;
258
+
259
+ /* Skips the backingStore of lv created with "--virtualsize",
260
+ * its original device "/dev/$vgname/$lvname_vorigin" is
261
+ * just for lvm internal use, one should never use it.
262
+ *
263
+ * (lvs outputs "[$lvname_vorigin] for field "origin" if the
264
+ * lv is created with "--virtualsize").
265
+ */
266
+ if (groups [1 ] && STRNEQ (groups [1 ], "" ) && (groups [1 ][0 ] != '[' )) {
267
+ if (VIR_ALLOC (vol -> target .backingStore ) < 0 )
268
+ goto cleanup ;
269
+
270
+ if (virAsprintf (& vol -> target .backingStore -> path , "%s/%s" ,
271
+ pool -> def -> target .path , groups [1 ]) < 0 )
272
+ goto cleanup ;
273
+
274
+ vol -> target .backingStore -> format = VIR_STORAGE_POOL_LOGICAL_LVM2 ;
275
+ }
276
+
277
+ if (!vol -> key && VIR_STRDUP (vol -> key , groups [2 ]) < 0 )
278
+ goto cleanup ;
279
+
280
+ if (virStorageBackendUpdateVolInfo (vol , false,
281
+ VIR_STORAGE_VOL_OPEN_DEFAULT , 0 ) < 0 )
282
+ goto cleanup ;
283
+
284
+ if (virStrToLong_ull (groups [8 ], NULL , 10 , & vol -> target .allocation ) < 0 ) {
285
+ virReportError (VIR_ERR_INTERNAL_ERROR ,
286
+ "%s" , _ ("malformed volume allocation value" ));
287
+ goto cleanup ;
288
+ }
289
+
290
+ if (virStorageBackendLogicalParseVolExtents (vol , groups ) < 0 )
291
+ goto cleanup ;
292
+
272
293
if (is_new_vol &&
273
294
VIR_APPEND_ELEMENT (pool -> volumes .objs , pool -> volumes .count , vol ) < 0 )
274
295
goto cleanup ;
275
296
276
297
ret = 0 ;
277
298
278
299
cleanup :
279
- VIR_FREE (regex );
280
- VIR_FREE (reg );
281
- VIR_FREE (vars );
282
300
if (is_new_vol && (ret == -1 ))
283
301
virStorageVolDefFree (vol );
284
302
return ret ;
0 commit comments