2009-09-08 13:47:45 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_mpath.c: storage backend for multipath handling
|
|
|
|
*
|
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
|
|
|
* Copyright (C) 2009-2014 Red Hat, Inc.
|
2009-09-08 13:47:45 +00:00
|
|
|
* Copyright (C) 2009-2008 Dave Allan
|
|
|
|
*
|
|
|
|
* 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/>.
|
2009-09-08 13:47:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <libdevmapper.h>
|
|
|
|
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2009-09-08 13:47:45 +00:00
|
|
|
#include "storage_conf.h"
|
|
|
|
#include "storage_backend.h"
|
2017-01-13 15:50:11 +00:00
|
|
|
#include "storage_backend_mpath.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"
|
2017-01-11 17:04:15 +00:00
|
|
|
#include "storage_util.h"
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("storage.storage_backend_mpath");
|
|
|
|
|
2009-09-08 13:47:45 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
|
2009-09-08 13:47:45 +00:00
|
|
|
const int devnum,
|
|
|
|
const char *dev)
|
|
|
|
{
|
2017-07-26 18:28:16 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2009-09-08 13:47:45 +00:00
|
|
|
virStorageVolDefPtr vol;
|
|
|
|
int ret = -1;
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC(vol) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
vol->type = VIR_STORAGE_VOL_BLOCK;
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (virAsprintf(&(vol->name), "dm-%u", devnum) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-02-19 12:43:03 +00:00
|
|
|
if (virStorageBackendUpdateVolInfo(vol, true,
|
2015-11-24 15:08:29 +00:00
|
|
|
VIR_STORAGE_VOL_OPEN_DEFAULT, 0) < 0) {
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX should use logical unit's UUID instead */
|
2013-05-03 12:49:08 +00:00
|
|
|
if (VIR_STRDUP(vol->key, vol->target.path) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-05-09 12:05:16 +00:00
|
|
|
if (virStoragePoolObjAddVol(pool, vol) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto cleanup;
|
2017-05-09 12:05:16 +00:00
|
|
|
|
2017-07-26 18:28:16 +00:00
|
|
|
def->capacity += vol->target.capacity;
|
|
|
|
def->allocation += vol->target.allocation;
|
2009-09-08 13:47:45 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
virStorageVolDefFree(vol);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-09-16 12:05:58 +00:00
|
|
|
virStorageBackendIsMultipath(const char *dev_name)
|
2009-09-08 13:47:45 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct dm_task *dmt = NULL;
|
|
|
|
void *next = NULL;
|
|
|
|
uint64_t start, length;
|
|
|
|
char *target_type = NULL;
|
|
|
|
char *params = NULL;
|
|
|
|
|
|
|
|
dmt = dm_task_create(DM_DEVICE_TABLE);
|
|
|
|
if (dmt == NULL) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-09-16 12:05:58 +00:00
|
|
|
if (dm_task_set_name(dmt, dev_name) == 0) {
|
2009-09-08 13:47:45 +00:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_task_no_open_count(dmt);
|
|
|
|
|
|
|
|
if (!dm_task_run(dmt)) {
|
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-02-11 14:26:37 +00:00
|
|
|
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2016-04-13 21:29:59 +00:00
|
|
|
if (STREQ_NULLABLE(target_type, "multipath"))
|
2009-09-08 13:47:45 +00:00
|
|
|
ret = 1;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
out:
|
2014-11-13 14:25:27 +00:00
|
|
|
if (dmt != NULL)
|
2009-09-08 13:47:45 +00:00
|
|
|
dm_task_destroy(dmt);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-09-16 12:05:58 +00:00
|
|
|
virStorageBackendGetMinorNumber(const char *dev_name, uint32_t *minor)
|
2009-09-08 13:47:45 +00:00
|
|
|
{
|
2009-09-08 15:32:57 +00:00
|
|
|
int ret = -1;
|
|
|
|
struct dm_task *dmt;
|
|
|
|
struct dm_info info;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (!(dmt = dm_task_create(DM_DEVICE_INFO)))
|
2009-09-08 15:32:57 +00:00
|
|
|
goto out;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (!dm_task_set_name(dmt, dev_name))
|
2009-09-08 15:32:57 +00:00
|
|
|
goto out;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (!dm_task_run(dmt))
|
2009-09-08 15:32:57 +00:00
|
|
|
goto out;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (!dm_task_get_info(dmt, &info))
|
2009-09-08 15:32:57 +00:00
|
|
|
goto out;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2009-09-08 15:32:57 +00:00
|
|
|
*minor = info.minor;
|
|
|
|
ret = 0;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
out:
|
2009-09-08 15:32:57 +00:00
|
|
|
if (dmt != NULL)
|
|
|
|
dm_task_destroy(dmt);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2009-09-08 15:32:57 +00:00
|
|
|
return ret;
|
2009-09-08 13:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendCreateVols(virStoragePoolObjPtr pool,
|
2009-09-08 13:47:45 +00:00
|
|
|
struct dm_names *names)
|
|
|
|
{
|
2010-05-20 18:16:54 +00:00
|
|
|
int retval = -1, is_mpath = 0;
|
2009-09-08 13:47:45 +00:00
|
|
|
char *map_device = NULL;
|
|
|
|
uint32_t minor = -1;
|
2011-02-15 02:12:24 +00:00
|
|
|
uint32_t next;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
is_mpath = virStorageBackendIsMultipath(names->name);
|
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (is_mpath < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (is_mpath == 1) {
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (virAsprintf(&map_device, "mapper/%s", names->name) < 0)
|
2009-09-08 13:47:45 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (virStorageBackendGetMinorNumber(names->name, &minor) < 0) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to get %s minor number"),
|
|
|
|
names->name);
|
2009-09-08 13:47:45 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:25:27 +00:00
|
|
|
if (virStorageBackendMpathNewVol(pool, minor, map_device) < 0)
|
2010-05-20 18:16:54 +00:00
|
|
|
goto out;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
VIR_FREE(map_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given the way libdevmapper returns its data, I don't see
|
|
|
|
* any way to avoid this series of casts. */
|
2013-04-03 14:52:40 +00:00
|
|
|
VIR_WARNINGS_NO_CAST_ALIGN
|
2011-02-15 02:12:24 +00:00
|
|
|
next = names->next;
|
|
|
|
names = (struct dm_names *)(((char *)names) + next);
|
2013-04-03 14:52:40 +00:00
|
|
|
VIR_WARNINGS_RESET
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2011-02-15 02:12:24 +00:00
|
|
|
} while (next);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2010-05-20 18:16:54 +00:00
|
|
|
retval = 0;
|
2014-03-25 06:52:40 +00:00
|
|
|
out:
|
2017-07-19 00:36:54 +00:00
|
|
|
VIR_FREE(map_device);
|
2009-09-08 13:47:45 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendGetMaps(virStoragePoolObjPtr pool)
|
2009-09-08 13:47:45 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
struct dm_task *dmt = NULL;
|
|
|
|
struct dm_names *names = NULL;
|
|
|
|
|
|
|
|
if (!(dmt = dm_task_create(DM_DEVICE_LIST))) {
|
|
|
|
retval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dm_task_no_open_count(dmt);
|
|
|
|
|
|
|
|
if (!dm_task_run(dmt)) {
|
|
|
|
retval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(names = dm_task_get_names(dmt))) {
|
|
|
|
retval = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!names->dev) {
|
|
|
|
/* No devices found */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendCreateVols(pool, names);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
out:
|
2014-11-13 14:25:27 +00:00
|
|
|
if (dmt != NULL)
|
2012-10-17 09:23:12 +00:00
|
|
|
dm_task_destroy(dmt);
|
2009-09-08 13:47:45 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
static int
|
2015-03-09 14:34:35 +00:00
|
|
|
virStorageBackendMpathCheckPool(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
2010-11-11 20:09:20 +00:00
|
|
|
bool *isActive)
|
|
|
|
{
|
2015-06-24 11:46:47 +00:00
|
|
|
*isActive = virFileExists("/dev/mapper") ||
|
|
|
|
virFileExists("/dev/mpath");
|
2010-11-11 20:09:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendMpathRefreshPool(virStoragePoolObjPtr pool)
|
2009-09-08 13:47:45 +00:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2017-07-26 18:28:16 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2018-01-26 13:31:58 +00:00
|
|
|
VIR_DEBUG("pool=%p", pool);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2017-07-26 18:28:16 +00:00
|
|
|
def->allocation = def->capacity = def->available = 0;
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2017-02-20 12:00:51 +00:00
|
|
|
virWaitForDevices();
|
2009-09-08 13:47:45 +00:00
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendGetMaps(pool);
|
2009-09-08 13:47:45 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virStorageBackend virStorageBackendMpath = {
|
|
|
|
.type = VIR_STORAGE_POOL_MPATH,
|
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
.checkPool = virStorageBackendMpathCheckPool,
|
2009-09-08 13:47:45 +00:00
|
|
|
.refreshPool = virStorageBackendMpathRefreshPool,
|
2014-07-07 14:50:11 +00:00
|
|
|
.uploadVol = virStorageBackendVolUploadLocal,
|
|
|
|
.downloadVol = virStorageBackendVolDownloadLocal,
|
2014-07-07 14:50:11 +00:00
|
|
|
.wipeVol = virStorageBackendVolWipeLocal,
|
2009-09-08 13:47:45 +00:00
|
|
|
};
|
2017-01-13 15:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendMpathRegister(void)
|
|
|
|
{
|
|
|
|
return virStorageBackendRegister(&virStorageBackendMpath);
|
|
|
|
}
|