From: Christophe Varoqui Date: Sat, 19 Jul 2008 17:11:23 +0000 (+0200) Subject: [lib] create read-only multipath if rw try failed X-Git-Tag: 0.4.9~196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d8d4330d30890163600f450ea9dfb3b9808de2ef;p=platform%2Fupstream%2Fmultipath-tools.git [lib] create read-only multipath if rw try failed May be soon the devmapper will return more precise return codes. Use that for now. --- diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 5a40222..285a8a2 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -339,6 +339,10 @@ domap (struct multipath * mpp) r = dm_addmap_create(mpp->alias, mpp->params, mpp->size, mpp->wwid); + if (!r) + r = dm_addmap_create_ro(mpp->alias, mpp->params, + mpp->size, mpp->wwid); + lock_multipath(mpp, 0); break; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 3e79d97..d329781 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -175,7 +175,8 @@ dm_simplecmd (int task, const char *name) { extern int dm_addmap (int task, const char *name, const char *target, - const char *params, unsigned long long size, const char *uuid) { + const char *params, unsigned long long size, const char *uuid, + int ro) { int r = 0; struct dm_task *dmt; char *prefixed_uuid = NULL; @@ -189,6 +190,9 @@ dm_addmap (int task, const char *name, const char *target, if (!dm_task_add_target (dmt, 0, size, target, params)) goto addout; + if (ro) + dm_task_set_ro(dmt); + if (uuid){ prefixed_uuid = MALLOC(UUID_PREFIX_LEN + strlen(uuid) + 1); if (!prefixed_uuid) { @@ -215,11 +219,12 @@ dm_addmap (int task, const char *name, const char *target, return r; } -extern int -dm_addmap_create (const char *name, const char *params, - unsigned long long size, const char *uuid) { +static int +_dm_addmap_create (const char *name, const char *params, + unsigned long long size, const char *uuid, int ro) { int r; - r = dm_addmap(DM_DEVICE_CREATE, name, TGT_MPATH, params, size, uuid); + r = dm_addmap(DM_DEVICE_CREATE, name, TGT_MPATH, params, size, uuid, + ro); /* * DM_DEVICE_CREATE is actually DM_DEV_CREATE + DM_TABLE_LOAD. * Failing the second part leaves an empty map. Clean it up. @@ -232,12 +237,33 @@ dm_addmap_create (const char *name, const char *params, return r; } +#define ADDMAP_RW 0 +#define ADDMAP_RO 1 + +extern int +dm_addmap_create (const char *name, const char *params, + unsigned long long size, const char *uuid) { + return _dm_addmap_create(name, params, size, uuid, ADDMAP_RW); +} + +extern int +dm_addmap_create_ro (const char *name, const char *params, + unsigned long long size, const char *uuid) { + return _dm_addmap_create(name, params, size, uuid, ADDMAP_RO); +} + extern int dm_addmap_reload (const char *name, const char *params, unsigned long long size, const char *uuid) { - int r; - r = dm_addmap(DM_DEVICE_RELOAD, name, TGT_MPATH, params, size, uuid); - return r; + return dm_addmap(DM_DEVICE_RELOAD, name, TGT_MPATH, params, size, uuid, + ADDMAP_RW); +} + +extern int +dm_addmap_reload_ro (const char *name, const char *params, + unsigned long long size, const char *uuid) { + return dm_addmap(DM_DEVICE_RELOAD, name, TGT_MPATH, params, size, uuid, + ADDMAP_RO); } extern int diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 962df8a..a340c00 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -6,8 +6,12 @@ int dm_prereq (void); int dm_simplecmd (int, const char *); int dm_addmap_create (const char *, const char *, unsigned long long size, const char *uuid); +int dm_addmap_create_ro (const char *, const char *, + unsigned long long size, const char *uuid); int dm_addmap_reload (const char *, const char *, unsigned long long size, const char *uuid); +int dm_addmap_reload_ro (const char *, const char *, + unsigned long long size, const char *uuid); int dm_map_present (const char *); int dm_get_map(char *, unsigned long long *, char *); int dm_get_status(char *, char *);