2008-02-20 15:45:33 +00:00
|
|
|
/*
|
2011-04-17 06:34:10 +00:00
|
|
|
* storage_backend_logical.c: storage backend for logical volume handling
|
2008-02-20 15:45:33 +00:00
|
|
|
*
|
2014-03-30 02:27:44 +00:00
|
|
|
* Copyright (C) 2007-2014 Red Hat, Inc.
|
2008-02-20 15:45:33 +00:00
|
|
|
* Copyright (C) 2007-2008 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-02-20 15:45:33 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2008-02-20 15:45:33 +00:00
|
|
|
#include "storage_backend_logical.h"
|
|
|
|
#include "storage_conf.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("storage.storage_backend_logical");
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
#define PV_BLANK_SECTOR_SIZE 512
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendLogicalSetActive(virStoragePoolObjPtr pool,
|
2008-02-20 15:45:33 +00:00
|
|
|
int on)
|
|
|
|
{
|
2012-07-11 14:56:55 +00:00
|
|
|
int ret;
|
|
|
|
virCommandPtr cmd =
|
|
|
|
virCommandNewArgList(VGCHANGE,
|
|
|
|
on ? "-aly" : "-aln",
|
|
|
|
pool->def->source.name,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
ret = virCommandRun(cmd, NULL);
|
|
|
|
virCommandFree(cmd);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
#define VIR_STORAGE_VOL_LOGICAL_SEGTYPE_STRIPED "striped"
|
|
|
|
|
2014-03-18 14:35:01 +00:00
|
|
|
struct virStorageBackendLogicalPoolVolData {
|
|
|
|
virStoragePoolObjPtr pool;
|
|
|
|
virStorageVolDefPtr vol;
|
|
|
|
};
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
static int
|
2014-03-18 14:35:01 +00:00
|
|
|
virStorageBackendLogicalMakeVol(char **const groups,
|
|
|
|
void *opaque)
|
2008-02-20 15:45:33 +00:00
|
|
|
{
|
2014-03-18 14:35:01 +00:00
|
|
|
struct virStorageBackendLogicalPoolVolData *data = opaque;
|
|
|
|
virStoragePoolObjPtr pool = data->pool;
|
2008-02-20 15:45:33 +00:00
|
|
|
virStorageVolDefPtr vol = NULL;
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
bool is_new_vol = false;
|
2008-02-20 15:45:33 +00:00
|
|
|
unsigned long long offset, size, length;
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
const char *regex_unit = "(\\S+)\\((\\S+)\\)";
|
|
|
|
char *regex = NULL;
|
|
|
|
regex_t *reg = NULL;
|
|
|
|
regmatch_t *vars = NULL;
|
|
|
|
char *p = NULL;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
|
|
|
int err, nextents, nvars, ret = -1;
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
const char *attrs = groups[9];
|
|
|
|
|
|
|
|
/* Skip inactive volume */
|
|
|
|
if (attrs[4] != 'a')
|
|
|
|
return 0;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2013-10-09 03:51:18 +00:00
|
|
|
/*
|
|
|
|
* Skip thin pools(t). These show up in normal lvs output
|
|
|
|
* but do not have a corresponding /dev/$vg/$lv device that
|
|
|
|
* is created by udev. This breaks assumptions in later code.
|
|
|
|
*/
|
|
|
|
if (attrs[0] == 't')
|
|
|
|
return 0;
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
/* See if we're only looking for a specific volume */
|
2014-03-18 14:35:01 +00:00
|
|
|
if (data->vol != NULL) {
|
|
|
|
vol = data->vol;
|
2008-02-20 15:45:33 +00:00
|
|
|
if (STRNEQ(vol->name, groups[0]))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Or filling in more data on an existing volume */
|
|
|
|
if (vol == NULL)
|
|
|
|
vol = virStorageVolDefFindByName(pool, groups[0]);
|
|
|
|
|
|
|
|
/* Or a completely new volume */
|
|
|
|
if (vol == NULL) {
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC(vol) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
is_new_vol = true;
|
2008-11-17 11:19:33 +00:00
|
|
|
vol->type = VIR_STORAGE_VOL_BLOCK;
|
|
|
|
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(vol->name, groups[0]) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vol->target.path == NULL) {
|
2009-01-27 18:30:03 +00:00
|
|
|
if (virAsprintf(&vol->target.path, "%s/%s",
|
2013-07-04 10:16:29 +00:00
|
|
|
pool->def->target.path, vol->name) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2009-01-27 18:30:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 16:41:43 +00:00
|
|
|
/* Mark the (s) sparse/snapshot lv, e.g. the lv created using
|
|
|
|
* the --virtualsize/-V option. We've already ignored the (t)hin
|
|
|
|
* pool definition. In the manner libvirt defines these, the
|
|
|
|
* thin pool is hidden to the lvs output, except as the name
|
|
|
|
* in brackets [] described for the groups[1] (backingStore).
|
|
|
|
*/
|
|
|
|
if (attrs[0] == 's')
|
|
|
|
vol->target.sparse = true;
|
|
|
|
|
2011-11-18 11:15:10 +00:00
|
|
|
/* Skips the backingStore of lv created with "--virtualsize",
|
|
|
|
* its original device "/dev/$vgname/$lvname_vorigin" is
|
|
|
|
* just for lvm internal use, one should never use it.
|
|
|
|
*
|
|
|
|
* (lvs outputs "[$lvname_vorigin] for field "origin" if the
|
|
|
|
* lv is created with "--virtualsize").
|
|
|
|
*/
|
|
|
|
if (groups[1] && !STREQ(groups[1], "") && (groups[1][0] != '[')) {
|
2014-07-14 13:19:49 +00:00
|
|
|
if (VIR_ALLOC(vol->target.backingStore) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virAsprintf(&vol->target.backingStore->path, "%s/%s",
|
2013-07-04 10:16:29 +00:00
|
|
|
pool->def->target.path, groups[1]) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2009-01-27 18:30:03 +00:00
|
|
|
|
2014-07-14 13:19:49 +00:00
|
|
|
vol->target.backingStore->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 12:49:08 +00:00
|
|
|
if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2014-04-15 20:32:04 +00:00
|
|
|
if (virStorageBackendUpdateVolInfo(vol, true, false,
|
2014-03-30 22:27:14 +00:00
|
|
|
VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
nextents = 1;
|
|
|
|
if (STREQ(groups[4], VIR_STORAGE_VOL_LOGICAL_SEGTYPE_STRIPED)) {
|
|
|
|
if (virStrToLong_i(groups[5], NULL, 10, &nextents) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed volume extent stripes value"));
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
/* Finally fill in extents information */
|
2008-06-06 11:09:57 +00:00
|
|
|
if (VIR_REALLOC_N(vol->source.extents,
|
2013-07-04 10:16:29 +00:00
|
|
|
vol->source.nextent + nextents) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
if (virStrToLong_ull(groups[6], NULL, 10, &length) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("malformed volume extent length value"));
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virStrToLong_ull(groups[7], NULL, 10, &size) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("malformed volume extent size value"));
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (virStrToLong_ull(groups[8], NULL, 10, &vol->target.allocation) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("malformed volume allocation value"));
|
2012-07-11 16:28:39 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
|
2011-10-10 20:02:06 +00:00
|
|
|
/* Now parse the "devices" field separately */
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(regex, regex_unit) < 0)
|
|
|
|
goto cleanup;
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
|
|
|
|
for (i = 1; i < nextents; i++) {
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2011-10-10 20:02:06 +00:00
|
|
|
/* "," is the separator of "devices" field */
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
strcat(regex, ",");
|
|
|
|
strncat(regex, regex_unit, strlen(regex_unit));
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC(reg) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
/* Each extent has a "path:offset" pair, and vars[0] will
|
|
|
|
* be the whole matched string.
|
|
|
|
*/
|
|
|
|
nvars = (nextents * 2) + 1;
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC_N(vars, nvars) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
err = regcomp(reg, regex, REG_EXTENDED);
|
|
|
|
if (err != 0) {
|
|
|
|
char error[100];
|
|
|
|
regerror(err, reg, error, sizeof(error));
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to compile regex %s"),
|
|
|
|
error);
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
|
2013-01-10 19:44:26 +00:00
|
|
|
err = regexec(reg, groups[3], nvars, vars, 0);
|
|
|
|
regfree(reg);
|
|
|
|
if (err != 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed volume extent devices value"));
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
p = groups[3];
|
2008-02-20 15:45:33 +00:00
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
/* vars[0] is skipped */
|
|
|
|
for (i = 0; i < nextents; i++) {
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t j;
|
|
|
|
int len;
|
2013-05-03 12:49:08 +00:00
|
|
|
char *offset_str = NULL;
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
|
|
|
|
j = (i * 2) + 1;
|
|
|
|
len = vars[j].rm_eo - vars[j].rm_so;
|
|
|
|
p[vars[j].rm_eo] = '\0';
|
|
|
|
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRNDUP(vol->source.extents[vol->source.nextent].path,
|
|
|
|
p + vars[j].rm_so, len) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
len = vars[j + 1].rm_eo - vars[j + 1].rm_so;
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0)
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed volume extent offset value"));
|
2011-10-13 21:06:01 +00:00
|
|
|
VIR_FREE(offset_str);
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(offset_str);
|
|
|
|
|
|
|
|
vol->source.extents[vol->source.nextent].start = offset * size;
|
|
|
|
vol->source.extents[vol->source.nextent].end = (offset * size) + length;
|
|
|
|
vol->source.nextent++;
|
|
|
|
}
|
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
if (is_new_vol &&
|
|
|
|
VIR_APPEND_ELEMENT(pool->volumes.objs, pool->volumes.count, vol) < 0)
|
|
|
|
goto cleanup;
|
2011-12-12 07:26:20 +00:00
|
|
|
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
VIR_FREE(regex);
|
2013-01-10 19:44:26 +00:00
|
|
|
VIR_FREE(reg);
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
VIR_FREE(vars);
|
|
|
|
if (is_new_vol && (ret == -1))
|
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStorageVolDefPtr vol)
|
|
|
|
{
|
|
|
|
/*
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
* # lvs --separator , --noheadings --units b --unbuffered --nosuffix --options \
|
|
|
|
* "lv_name,origin,uuid,devices,seg_size,vg_extent_size,size,lv_attr" VGNAME
|
|
|
|
*
|
|
|
|
* RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432,5234491392,-wi-ao
|
|
|
|
* SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432,1040187392,-wi-ao
|
|
|
|
* Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432,1073741824,owi-a-
|
|
|
|
* Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432,2181038080,-wi-a-
|
|
|
|
* Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432,1040187392,swi-a-
|
2008-02-20 15:45:33 +00:00
|
|
|
*
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
* Pull out name, origin, & uuid, device, device extent start #,
|
|
|
|
* segment size, extent size, size, attrs
|
2008-02-20 15:45:33 +00:00
|
|
|
*
|
|
|
|
* NB can be multiple rows per volume if they have many extents
|
2008-07-30 08:52:44 +00:00
|
|
|
*
|
2008-11-14 16:10:47 +00:00
|
|
|
* NB lvs from some distros (e.g. SLES10 SP2) outputs trailing "," on each line
|
|
|
|
*
|
|
|
|
* NB Encrypted logical volumes can print ':' in their name, so it is
|
|
|
|
* not a suitable separator (rhbz 470693).
|
storage: Do not use comma as seperator for lvs output
* src/storage/storage_backend_logical.c:
If a logical vol is created as striped. (e.g. --stripes 3),
the "device" field of lvs output will have multiple fileds which are
seperated by comma. Thus the RE we write in the codes will not
work well anymore. E.g. (lvs output for a stripped vol, uses "#" as
seperator here):
test_stripes##fSLSZH-zAS2-yAIb-n4mV-Al9u-HA3V-oo9K1B#\
/dev/sdc1(10240),/dev/sdd1(0)#42949672960#4194304
The RE we use:
const char *regexes[] = {
"^\\s*(\\S+),(\\S*),(\\S+),(\\S+)\\((\\S+)\\),(\\S+),([0-9]+),?\\s*$"
};
Also the RE doesn't match the "devices" field of striped vol properly,
it contains multiple "device path" and "offset".
This patch mainly does:
1) Change the seperator into "#"
2) Change the RE for "devices" field from "(\\S+)\\((\\S+)\\)"
into "(\\S+)".
3) Add two new options for lvs command, (segtype, stripes)
4) Extend the RE to match the value for the two new fields.
5) Parse the "devices" field seperately in virStorageBackendLogicalMakeVol,
multiple "extents" info are generated if the vol is striped. The
number of "extents" is equal to the stripes number of the striped vol.
A incidental fix: (virStorageBackendLogicalMakeVol)
Free "vol" if it's new created and there is error.
Demo on striped vol with the patch applied:
% virsh vol-dumpxml /dev/test_vg/vol_striped2
<volume>
<name>vol_striped2</name>
<key>QuWqmn-kIkZ-IATt-67rc-OWEP-1PHX-Cl2ICs</key>
<source>
<device path='/dev/sda5'>
<extent start='79691776' end='88080384'/>
</device>
<device path='/dev/sda6'>
<extent start='62914560' end='71303168'/>
</device>
</source>
<capacity>8388608</capacity>
<allocation>8388608</allocation>
<target>
<path>/dev/test_vg/vol_striped2</path>
<permissions>
<mode>0660</mode>
<owner>0</owner>
<group>6</group>
<label>system_u:object_r:fixed_disk_device_t:s0</label>
</permissions>
</target>
</volume>
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=727474
2011-10-10 12:34:59 +00:00
|
|
|
* NB "devices" field has multiple device paths and "," if the volume is
|
|
|
|
* striped, so "," is not a suitable separator either (rhbz 727474).
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
"^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#(\\S+)#?\\s*$"
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
|
|
|
int vars[] = {
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
10
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
2012-07-11 14:56:55 +00:00
|
|
|
int ret = -1;
|
|
|
|
virCommandPtr cmd;
|
2014-03-18 14:35:01 +00:00
|
|
|
struct virStorageBackendLogicalPoolVolData cbdata = {
|
|
|
|
.pool = pool,
|
|
|
|
.vol = vol,
|
|
|
|
};
|
2012-07-11 14:56:55 +00:00
|
|
|
|
|
|
|
cmd = virCommandNewArgList(LVS,
|
|
|
|
"--separator", "#",
|
|
|
|
"--noheadings",
|
|
|
|
"--units", "b",
|
|
|
|
"--unbuffered",
|
|
|
|
"--nosuffix",
|
storage: Skip inactive lv volumes
If the volume is of a clustered volume group, and not active, the
related pool APIs fails on opening /dev/vg/lv. If the volume is
suspended, it hangs on open(2) the volume.
Though the best solution is to expose the volume status in volume
XML, and even better to provide API to activate/deactivate the volume,
but it's not the work I want to touch currently. Volume status in
other status is just fine to skip.
About the 5th field of lv_attr (from man lvs[8])
<quote>
5 State: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid
(S)uspended snapshot, snapshot (m)erge failed,suspended
snapshot (M)erge failed, mapped (d)evice present without
tables, mapped device present with (i)nactive table
</quote>
2013-05-07 10:29:29 +00:00
|
|
|
"--options",
|
|
|
|
"lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size,size,lv_attr",
|
2012-07-11 14:56:55 +00:00
|
|
|
pool->def->source.name,
|
|
|
|
NULL);
|
2014-03-18 14:35:01 +00:00
|
|
|
if (virCommandRunRegex(cmd,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendLogicalMakeVol,
|
|
|
|
&cbdata,
|
|
|
|
"lvs") < 0)
|
2012-07-11 14:56:55 +00:00
|
|
|
goto cleanup;
|
2008-06-17 12:45:24 +00:00
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-18 14:35:01 +00:00
|
|
|
virStorageBackendLogicalRefreshPoolFunc(char **const groups,
|
|
|
|
void *data)
|
2008-02-20 15:45:33 +00:00
|
|
|
{
|
2014-03-18 14:35:01 +00:00
|
|
|
virStoragePoolObjPtr pool = data;
|
2008-02-20 15:45:33 +00:00
|
|
|
if (virStrToLong_ull(groups[0], NULL, 10, &pool->def->capacity) < 0)
|
|
|
|
return -1;
|
|
|
|
if (virStrToLong_ull(groups[1], NULL, 10, &pool->def->available) < 0)
|
|
|
|
return -1;
|
|
|
|
pool->def->allocation = pool->def->capacity - pool->def->available;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
static int
|
2014-03-18 14:35:01 +00:00
|
|
|
virStorageBackendLogicalFindPoolSourcesFunc(char **const groups,
|
2008-08-27 20:05:58 +00:00
|
|
|
void *data)
|
|
|
|
{
|
2008-10-23 11:39:53 +00:00
|
|
|
virStoragePoolSourceListPtr sourceList = data;
|
|
|
|
char *pvname = NULL;
|
|
|
|
char *vgname = NULL;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2008-10-23 11:39:53 +00:00
|
|
|
virStoragePoolSourceDevicePtr dev;
|
|
|
|
virStoragePoolSource *thisSource;
|
|
|
|
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(pvname, groups[0]) < 0 ||
|
|
|
|
VIR_STRDUP(vgname, groups[1]) < 0)
|
|
|
|
goto error;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
|
|
|
thisSource = NULL;
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < sourceList->nsources; i++) {
|
2008-10-23 11:39:53 +00:00
|
|
|
if (STREQ(sourceList->sources[i].name, vgname)) {
|
|
|
|
thisSource = &sourceList->sources[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
if (thisSource == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
if (!(thisSource = virStoragePoolSourceListNewSource(sourceList)))
|
2013-05-03 12:49:08 +00:00
|
|
|
goto error;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
|
|
|
thisSource->name = vgname;
|
2008-08-27 20:05:58 +00:00
|
|
|
}
|
2008-10-23 11:39:53 +00:00
|
|
|
else
|
|
|
|
VIR_FREE(vgname);
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_REALLOC_N(thisSource->devices, thisSource->ndevice + 1) != 0)
|
2013-05-03 12:49:08 +00:00
|
|
|
goto error;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
dev = &thisSource->devices[thisSource->ndevice];
|
|
|
|
thisSource->ndevice++;
|
2008-11-04 21:54:21 +00:00
|
|
|
thisSource->format = VIR_STORAGE_POOL_LOGICAL_LVM2;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
dev->path = pvname;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
return 0;
|
2008-10-23 11:39:53 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
error:
|
2008-10-23 11:39:53 +00:00
|
|
|
VIR_FREE(pvname);
|
|
|
|
VIR_FREE(vgname);
|
|
|
|
|
|
|
|
return -1;
|
2008-08-27 20:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendLogicalFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-08-27 20:05:58 +00:00
|
|
|
const char *srcSpec ATTRIBUTE_UNUSED,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
2008-08-27 20:05:58 +00:00
|
|
|
{
|
|
|
|
/*
|
2008-10-23 11:39:53 +00:00
|
|
|
* # pvs --noheadings -o pv_name,vg_name
|
|
|
|
* /dev/sdb
|
|
|
|
* /dev/sdc VolGroup00
|
2008-08-27 20:05:58 +00:00
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
2008-10-23 11:39:53 +00:00
|
|
|
"^\\s*(\\S+)\\s+(\\S+)\\s*$"
|
2008-08-27 20:05:58 +00:00
|
|
|
};
|
|
|
|
int vars[] = {
|
2008-10-23 11:39:53 +00:00
|
|
|
2
|
2008-08-27 20:05:58 +00:00
|
|
|
};
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr cmd;
|
2008-08-27 20:05:58 +00:00
|
|
|
char *retval = NULL;
|
2008-10-23 11:39:53 +00:00
|
|
|
virStoragePoolSourceList sourceList;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2008-11-05 11:41:43 +00:00
|
|
|
/*
|
|
|
|
* NOTE: ignoring errors here; this is just to "touch" any logical volumes
|
|
|
|
* that might be hanging around, so if this fails for some reason, the
|
|
|
|
* worst that happens is that scanning doesn't pick everything up
|
|
|
|
*/
|
2012-07-11 14:56:55 +00:00
|
|
|
cmd = virCommandNew(VGSCAN);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Failure when running vgscan to refresh physical volumes");
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
2008-11-05 11:41:43 +00:00
|
|
|
|
2008-10-23 11:39:53 +00:00
|
|
|
memset(&sourceList, 0, sizeof(sourceList));
|
2008-11-04 21:54:21 +00:00
|
|
|
sourceList.type = VIR_STORAGE_POOL_LOGICAL;
|
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
cmd = virCommandNewArgList(PVS,
|
|
|
|
"--noheadings",
|
|
|
|
"-o", "pv_name,vg_name",
|
|
|
|
NULL);
|
2014-03-18 14:35:01 +00:00
|
|
|
if (virCommandRunRegex(cmd, 1, regexes, vars,
|
|
|
|
virStorageBackendLogicalFindPoolSourcesFunc,
|
|
|
|
&sourceList, "pvs") < 0) {
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
2008-08-27 20:05:58 +00:00
|
|
|
return NULL;
|
2012-07-11 14:56:55 +00:00
|
|
|
}
|
|
|
|
virCommandFree(cmd);
|
2008-08-27 20:05:58 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
retval = virStoragePoolSourceListFormat(&sourceList);
|
2008-08-27 20:05:58 +00:00
|
|
|
if (retval == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("failed to get source from sourceList"));
|
2008-08-27 20:05:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2008-10-23 11:39:53 +00:00
|
|
|
for (i = 0; i < sourceList.nsources; i++)
|
2011-10-21 22:44:52 +00:00
|
|
|
virStoragePoolSourceClear(&sourceList.sources[i]);
|
2008-10-23 11:39:53 +00:00
|
|
|
VIR_FREE(sourceList.sources);
|
2008-08-27 20:05:58 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendLogicalCheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
bool *isActive)
|
|
|
|
{
|
2013-09-13 13:32:43 +00:00
|
|
|
*isActive = virFileExists(pool->def->target.path);
|
2010-11-11 20:09:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendLogicalStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virStorageBackendLogicalSetActive(pool, 1) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
2008-02-20 15:45:33 +00:00
|
|
|
{
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr vgcmd;
|
|
|
|
int fd;
|
2008-02-20 15:45:33 +00:00
|
|
|
char zeros[PV_BLANK_SECTOR_SIZE];
|
2012-07-11 14:56:55 +00:00
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
memset(zeros, 0, sizeof(zeros));
|
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
vgcmd = virCommandNewArgList(VGCREATE, pool->def->source.name, NULL);
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < pool->def->source.ndevice; i++) {
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr pvcmd;
|
2008-02-20 15:45:33 +00:00
|
|
|
/*
|
|
|
|
* LVM requires that the first sector is blanked if using
|
|
|
|
* a whole disk as a PV. So we just blank them out regardless
|
|
|
|
* rather than trying to figure out if we're a disk or partition
|
|
|
|
*/
|
|
|
|
if ((fd = open(pool->def->source.devices[i].path, O_WRONLY)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot open device '%s'"),
|
|
|
|
pool->def->source.devices[i].path);
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-25 10:00:16 +00:00
|
|
|
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot clear device header of '%s'"),
|
|
|
|
pool->def->source.devices[i].path);
|
2011-08-18 12:40:03 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (fsync(fd) < 0) {
|
|
|
|
virReportSystemError(errno,
|
|
|
|
_("cannot flush header of device'%s'"),
|
|
|
|
pool->def->source.devices[i].path);
|
2010-10-28 15:43:16 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-10-28 15:43:16 +00:00
|
|
|
if (VIR_CLOSE(fd) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot close device '%s'"),
|
|
|
|
pool->def->source.devices[i].path);
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the physical volume because vgcreate is not
|
|
|
|
* clever enough todo this for us :-(
|
|
|
|
*/
|
2012-07-11 14:56:55 +00:00
|
|
|
pvcmd = virCommandNewArgList(PVCREATE,
|
|
|
|
pool->def->source.devices[i].path,
|
|
|
|
NULL);
|
|
|
|
if (virCommandRun(pvcmd, NULL) < 0) {
|
|
|
|
virCommandFree(pvcmd);
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
2012-07-11 14:56:55 +00:00
|
|
|
}
|
|
|
|
virCommandFree(pvcmd);
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandAddArg(vgcmd, pool->def->source.devices[i].path);
|
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
/* Now create the volume group itself */
|
2012-07-11 14:56:55 +00:00
|
|
|
if (virCommandRun(vgcmd, NULL) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
ret = 0;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(vgcmd);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendLogicalRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* # vgs --separator : --noheadings --units b --unbuffered --nosuffix --options "vg_size,vg_free" VGNAME
|
|
|
|
* 10603200512:4328521728
|
|
|
|
*
|
|
|
|
* Pull out size & free
|
2008-07-30 08:52:44 +00:00
|
|
|
*
|
|
|
|
* NB vgs from some distros (e.g. SLES10 SP2) outputs trailing ":" on each line
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
2008-07-30 08:52:44 +00:00
|
|
|
"^\\s*(\\S+):([0-9]+):?\\s*$"
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|
|
|
|
int vars[] = {
|
|
|
|
2
|
|
|
|
};
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
int ret = -1;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
virFileWaitForDevices();
|
2008-11-28 07:50:20 +00:00
|
|
|
|
2008-02-20 15:45:33 +00:00
|
|
|
/* Get list of all logical volumes */
|
2012-07-11 14:56:55 +00:00
|
|
|
if (virStorageBackendLogicalFindLVs(pool, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cmd = virCommandNewArgList(VGS,
|
|
|
|
"--separator", ":",
|
|
|
|
"--noheadings",
|
|
|
|
"--units", "b",
|
|
|
|
"--unbuffered",
|
|
|
|
"--nosuffix",
|
|
|
|
"--options", "vg_size,vg_free",
|
|
|
|
pool->def->source.name,
|
|
|
|
NULL);
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
/* Now get basic volgrp metadata */
|
2014-03-18 14:35:01 +00:00
|
|
|
if (virCommandRunRegex(cmd,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendLogicalRefreshPoolFunc,
|
|
|
|
pool,
|
|
|
|
"vgs") < 0)
|
2012-07-11 14:56:55 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
if (ret < 0)
|
|
|
|
virStoragePoolObjClearVols(pool);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/*
|
|
|
|
* This is actually relatively safe; if you happen to try to "stop" the
|
|
|
|
* pool that your / is on, for instance, you will get failure like:
|
|
|
|
* "Can't deactivate volume group "VolGroup00" with 3 open logical volume(s)"
|
2008-02-20 15:45:33 +00:00
|
|
|
*/
|
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendLogicalStopPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virStorageBackendLogicalSetActive(pool, 0) < 0)
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-04 22:41:52 +00:00
|
|
|
virStorageBackendLogicalDeletePool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
2008-02-20 15:45:33 +00:00
|
|
|
{
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
|
|
|
size_t i;
|
|
|
|
int ret = -1;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/* first remove the volume group */
|
2012-07-11 14:56:55 +00:00
|
|
|
cmd = virCommandNewArgList(VGREMOVE,
|
|
|
|
"-f", pool->def->source.name,
|
|
|
|
NULL);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
virCommandFree(cmd);
|
2013-03-28 15:36:50 +00:00
|
|
|
cmd = NULL;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2008-09-22 20:22:35 +00:00
|
|
|
/* now remove the pv devices and clear them out */
|
2012-07-11 14:56:55 +00:00
|
|
|
ret = 0;
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < pool->def->source.ndevice; i++) {
|
2012-07-11 14:56:55 +00:00
|
|
|
cmd = virCommandNewArgList(PVREMOVE,
|
|
|
|
pool->def->source.devices[i].path,
|
|
|
|
NULL);
|
|
|
|
if (virCommandRun(cmd, NULL) < 0) {
|
|
|
|
ret = -1;
|
2008-09-22 20:22:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
cmd = NULL;
|
2008-09-22 20:22:35 +00:00
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
return ret;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-12-11 14:36:56 +00:00
|
|
|
virStorageBackendLogicalDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
2008-02-20 15:45:33 +00:00
|
|
|
virStorageVolDefPtr vol,
|
2013-12-11 14:36:56 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virCommandPtr lvchange_cmd = NULL;
|
|
|
|
virCommandPtr lvremove_cmd = NULL;
|
|
|
|
|
|
|
|
virCheckFlags(0, -1);
|
|
|
|
|
|
|
|
virFileWaitForDevices();
|
|
|
|
|
|
|
|
lvchange_cmd = virCommandNewArgList(LVCHANGE, "-aln", vol->target.path, NULL);
|
|
|
|
lvremove_cmd = virCommandNewArgList(LVREMOVE, "-f", vol->target.path, NULL);
|
|
|
|
|
|
|
|
if (virCommandRun(lvremove_cmd, NULL) < 0) {
|
|
|
|
if (virCommandRun(lvchange_cmd, NULL) < 0) {
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
if (virCommandRun(lvremove_cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2013-12-11 14:36:56 +00:00
|
|
|
virCommandFree(lvchange_cmd);
|
|
|
|
virCommandFree(lvremove_cmd);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
2014-02-12 13:23:30 +00:00
|
|
|
virStorageBackendLogicalCreateVol(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol)
|
2008-02-20 15:45:33 +00:00
|
|
|
{
|
2013-03-06 11:57:40 +00:00
|
|
|
int fd = -1;
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandPtr cmd = NULL;
|
2012-10-17 00:25:41 +00:00
|
|
|
virErrorPtr err;
|
2014-03-30 23:01:23 +00:00
|
|
|
struct stat sb;
|
2009-01-27 18:30:03 +00:00
|
|
|
|
2014-02-12 13:23:30 +00:00
|
|
|
if (vol->target.encryption != NULL) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
|
|
"%s", _("storage pool does not support encrypted "
|
|
|
|
"volumes"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vol->type = VIR_STORAGE_VOL_BLOCK;
|
|
|
|
|
2014-07-21 17:08:58 +00:00
|
|
|
/* A target path passed to CreateVol has no meaning */
|
|
|
|
VIR_FREE(vol->target.path);
|
2014-02-12 13:23:30 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&vol->target.path, "%s/%s",
|
|
|
|
pool->def->target.path,
|
|
|
|
vol->name) == -1)
|
|
|
|
return -1;
|
2008-08-20 13:33:01 +00:00
|
|
|
|
2012-07-11 14:56:55 +00:00
|
|
|
cmd = virCommandNewArgList(LVCREATE,
|
|
|
|
"--name", vol->name,
|
|
|
|
NULL);
|
|
|
|
virCommandAddArg(cmd, "-L");
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
if (vol->target.capacity != vol->target.allocation) {
|
2012-10-17 00:30:23 +00:00
|
|
|
virCommandAddArgFormat(cmd, "%lluK",
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
VIR_DIV_UP(vol->target.allocation
|
|
|
|
? vol->target.allocation : 1, 1024));
|
2012-07-11 16:28:39 +00:00
|
|
|
virCommandAddArg(cmd, "--virtualsize");
|
2014-07-17 16:41:43 +00:00
|
|
|
vol->target.sparse = true;
|
2012-07-11 16:28:39 +00:00
|
|
|
}
|
conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile. As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file. This sets up the fields for
the tracking, although it does not modify XML to display any
new information.
* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-01 23:43:36 +00:00
|
|
|
virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->target.capacity,
|
|
|
|
1024));
|
2014-07-14 13:19:49 +00:00
|
|
|
if (vol->target.backingStore)
|
|
|
|
virCommandAddArgList(cmd, "-s", vol->target.backingStore->path, NULL);
|
2012-07-11 14:56:55 +00:00
|
|
|
else
|
|
|
|
virCommandAddArg(cmd, pool->def->source.name);
|
|
|
|
|
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
2013-03-06 11:57:40 +00:00
|
|
|
virCommandFree(cmd);
|
|
|
|
cmd = NULL;
|
|
|
|
|
2014-03-30 23:01:23 +00:00
|
|
|
if ((fd = virStorageBackendVolOpen(vol->target.path, &sb,
|
|
|
|
VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
/* We can only chown/grp if root */
|
2013-10-09 11:13:45 +00:00
|
|
|
if (geteuid() == 0) {
|
2014-03-30 02:27:44 +00:00
|
|
|
if (fchown(fd, vol->target.perms->uid, vol->target.perms->gid) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot set file owner '%s'"),
|
|
|
|
vol->target.path);
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-30 02:27:44 +00:00
|
|
|
if (fchmod(fd, vol->target.perms->mode) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot set file mode '%s'"),
|
|
|
|
vol->target.path);
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 15:43:16 +00:00
|
|
|
if (VIR_CLOSE(fd) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot close file '%s'"),
|
|
|
|
vol->target.path);
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill in data about this new vol */
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendLogicalFindLVs(pool, vol) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-01-20 17:13:33 +00:00
|
|
|
_("cannot find newly created volume '%s'"),
|
|
|
|
vol->target.path);
|
2013-03-06 11:57:40 +00:00
|
|
|
goto error;
|
2008-02-20 15:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-02-12 13:23:30 +00:00
|
|
|
error:
|
2012-10-17 00:25:41 +00:00
|
|
|
err = virSaveLastError();
|
2010-10-28 15:43:16 +00:00
|
|
|
VIR_FORCE_CLOSE(fd);
|
2008-02-20 15:45:33 +00:00
|
|
|
virStorageBackendLogicalDeleteVol(conn, pool, vol, 0);
|
2012-07-11 14:56:55 +00:00
|
|
|
virCommandFree(cmd);
|
2012-10-17 00:25:41 +00:00
|
|
|
virSetError(err);
|
2013-03-06 11:57:40 +00:00
|
|
|
virFreeError(err);
|
2008-02-20 15:45:33 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-07-09 23:17:31 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendLogicalBuildVolFrom(virConnectPtr conn,
|
2010-01-20 23:41:52 +00:00
|
|
|
virStoragePoolObjPtr pool,
|
2009-07-09 23:17:31 +00:00
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
virStorageVolDefPtr inputvol,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
virStorageBackendBuildVolFrom build_func;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
build_func = virStorageBackendGetBuildVolFromFunction(vol, inputvol);
|
2009-07-09 23:17:31 +00:00
|
|
|
if (!build_func)
|
|
|
|
return -1;
|
|
|
|
|
2010-01-20 23:41:52 +00:00
|
|
|
return build_func(conn, pool, vol, inputvol, flags);
|
2009-07-09 23:17:31 +00:00
|
|
|
}
|
|
|
|
|
2014-07-17 16:41:43 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendLogicalVolWipe(virConnectPtr conn,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
virStorageVolDefPtr vol,
|
|
|
|
unsigned int algorithm,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
if (!vol->target.sparse)
|
|
|
|
return virStorageBackendVolWipeLocal(conn, pool, vol, algorithm, flags);
|
|
|
|
|
|
|
|
/* The wiping algorithms will write something to the logical volume.
|
|
|
|
* Writing to a sparse logical volume causes it to be filled resulting
|
|
|
|
* in the volume becoming INACTIVE because there is some amount of
|
|
|
|
* metadata contained within the sparse lv. Choosing to only write
|
|
|
|
* a wipe pattern to the already written portion lv based on what
|
|
|
|
* 'lvs' shows in the "Data%" column/field for the sparse lv was
|
|
|
|
* considered. However, there is no guarantee that sparse lv could
|
|
|
|
* grow or shrink outside of libvirt's knowledge and thus still render
|
|
|
|
* the volume INACTIVE. Until there is some sort of wipe function
|
|
|
|
* implemented by lvm for one of these sparse lv, we'll just return
|
|
|
|
* unsupported.
|
|
|
|
*/
|
|
|
|
virReportError(VIR_ERR_NO_SUPPORT,
|
|
|
|
_("logical volue '%s' is sparse, volume wipe not supported"),
|
|
|
|
vol->target.path);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-02-20 15:45:33 +00:00
|
|
|
|
|
|
|
virStorageBackend virStorageBackendLogical = {
|
|
|
|
.type = VIR_STORAGE_POOL_LOGICAL,
|
|
|
|
|
2008-08-27 20:05:58 +00:00
|
|
|
.findPoolSources = virStorageBackendLogicalFindPoolSources,
|
2010-11-11 20:09:20 +00:00
|
|
|
.checkPool = virStorageBackendLogicalCheckPool,
|
2008-02-20 15:45:33 +00:00
|
|
|
.startPool = virStorageBackendLogicalStartPool,
|
|
|
|
.buildPool = virStorageBackendLogicalBuildPool,
|
|
|
|
.refreshPool = virStorageBackendLogicalRefreshPool,
|
|
|
|
.stopPool = virStorageBackendLogicalStopPool,
|
|
|
|
.deletePool = virStorageBackendLogicalDeletePool,
|
2014-02-12 13:23:30 +00:00
|
|
|
.buildVol = NULL,
|
2009-07-09 23:17:31 +00:00
|
|
|
.buildVolFrom = virStorageBackendLogicalBuildVolFrom,
|
2008-02-20 15:45:33 +00:00
|
|
|
.createVol = virStorageBackendLogicalCreateVol,
|
|
|
|
.deleteVol = virStorageBackendLogicalDeleteVol,
|
2014-07-07 14:50:11 +00:00
|
|
|
.uploadVol = virStorageBackendVolUploadLocal,
|
|
|
|
.downloadVol = virStorageBackendVolDownloadLocal,
|
2014-07-17 16:41:43 +00:00
|
|
|
.wipeVol = virStorageBackendLogicalVolWipe,
|
2008-02-20 15:45:33 +00:00
|
|
|
};
|