Add uid, gid, and mode config attributes
Benjamin Marzinski
maintainerPATCH 1/1 Add uid, gid, and mode config attributes
This adds the ability to set uid, gid, and mode for the multipath device nodes. Also, kpartx created device nodes will inherit the uid, gid, and mode of their parent device. These attributes can be set in either the defaults or the multipaths section of /etc/multipath.conf
Signed-off-by Benjamin Marzinski <[email protected]>
--- kpartx/devmapper.c | 10 ++- kpartx/devmapper.h | 2 +- kpartx/kpartx.c | 8 ++- libmultipath/config.c | 1 + libmultipath/config.h | 10 ++ libmultipath/configure.c | 17 ++-- libmultipath/devmapper.c | 57 +++++++------ libmultipath/devmapper.h | 19 +++-- libmultipath/dict.c | 211 ++++++++++++++++++++++++++++++++++++++++++++++ libmultipath/propsel.c | 54 ++++++++++++ libmultipath/propsel.h | 3 + libmultipath/structs.h | 11 +++ multipath.conf.annotated | 54 ++++++++++++ multipath.conf.synthetic | 3 + 14 files changed, 412 insertions(+), 48 deletions(-)
kpartx/devmapper.c +9 -1
@@ -78,7 +78,8 @@ dm_simplecmd (int task, const char *name, int no_flush) {extern int dm_addmap (int task,const char *name,const char *target, -const char *params,uint64_t size,const char *uuid,int part) { +const char *params,uint64_t size,const char *uuid,int part, +mode_t mode,uid_t uid,gid_t gid) {int r =0 ;struct dm_task *dmt;char *prefixed_uuid =NULL ;
@@ -104,6 +105,13 @@ dm_addmap (int task, const char *name, const char *target, goto addout; } +if (!dm_task_set_mode (dmt, mode)) + goto addout; +if (!dm_task_set_uid (dmt, uid)) + goto addout; +if (!dm_task_set_gid (dmt, gid)) + goto addout; +dm_task_no_open_count (dmt); r =dm_task_run (dmt);
kpartx/devmapper.h +1 -1
@@ -1,7 +1,7 @@int dm_prereq (char *,int ,int ,int );int dm_simplecmd (int ,const char *,int );int dm_addmap (int ,const char *,const char *,const char *,uint64_t , -const char *,int ); +const char *,int ,mode_t ,uid_t ,gid_t );int dm_map_present (char *);char *dm_mapname (int major,int minor);dev_t dm_get_first_dep (char *devname);
kpartx/kpartx.c +6 -2
@@ -462,7 +462,9 @@ main(int argc, char **argv){ DM_DEVICE_RELOAD : DM_DEVICE_CREATE);if (!dm_addmap (op, partname,DM_TARGET , params, - slices[j].size, uuid, j+1 )) { + slices[j].size, uuid, j+1 , + buf.st_mode &0777 , buf.st_uid, + buf.st_gid)) {fprintf (stderr,"create/reload failed on %s\n" , partname); r++;
@@ -524,7 +526,9 @@ main(int argc, char **argv){ DM_DEVICE_RELOAD : DM_DEVICE_CREATE);dm_addmap (op, partname,DM_TARGET , params, - slices[j].size, uuid, j+1 ); + slices[j].size, uuid, j+1 , + buf.st_mode &0777 , + buf.st_uid, buf.st_gid);if (op ==DM_DEVICE_RELOAD ) dm_simplecmd(DM_DEVICE_RESUME,
libmultipath/config.c +1 -0
@@ -440,6 +440,7 @@ load_config (char * file) conf->bindings_file =DEFAULT_BINDINGS_FILE ; conf->multipath_dir =set_default (DEFAULT_MULTIPATHDIR ); conf->flush_on_last_del =0 ; + conf->attribute_flags =0 ;/* * preload default hwtable
libmultipath/config.h +10 -0
@@ -1,6 +1,8 @@#ifndef _CONFIG_H#define _CONFIG_H +#include <sys/types.h> +#define ORIGIN_DEFAULT 0#define ORIGIN_CONFIG 1
@@ -45,6 +47,10 @@ struct mpentry {int minio;int pg_timeout;int flush_on_last_del; +int attribute_flags; +uid_t uid; +gid_t gid; +mode_t mode; };struct config {
@@ -68,6 +74,10 @@ struct config {int force_reload;int daemon;int flush_on_last_del; +int attribute_flags; +uid_t uid; +gid_t gid; +mode_t mode;char * dev;char * sysfs_dir;
libmultipath/configure.c +9 -8
@@ -67,6 +67,9 @@ setup_map (struct multipath * mpp)select_minio (mpp);select_no_path_retry (mpp);select_pg_timeout (mpp); +select_mode (mpp); +select_uid (mpp); +select_gid (mpp);/* * assign paths to path groups -- start with no groups and all paths
@@ -346,28 +349,26 @@ domap (struct multipath * mpp)break ; } - r =dm_addmap_create (mpp->alias, mpp->params, mpp->size, - mpp->wwid); + r =dm_addmap_create (mpp);if (!r) - r =dm_addmap_create_ro (mpp->alias, mpp->params, - mpp->size, mpp->wwid); + r =dm_addmap_create_ro (mpp);lock_multipath (mpp,0 );break ;case ACT_RELOAD : - r =dm_addmap_reload (mpp->alias, mpp->params, mpp->size,NULL ); + r =dm_addmap_reload (mpp);if (!r) - r =dm_addmap_reload_ro (mpp->alias, mpp->params, mpp->size,NULL ); + r =dm_addmap_reload_ro (mpp);if (r) r =dm_simplecmd_noflush (DM_DEVICE_RESUME , mpp->alias);break ;case ACT_RESIZE : - r =dm_addmap_reload (mpp->alias, mpp->params, mpp->size,NULL ); + r =dm_addmap_reload (mpp);if (!r) - r =dm_addmap_reload_ro (mpp->alias, mpp->params, mpp->size,NULL ); + r =dm_addmap_reload_ro (mpp);if (r) r =dm_simplecmd_flush (DM_DEVICE_RESUME , mpp->alias);break ;
libmultipath/devmapper.c +29 -28
112 lines not on this page · raw message
libmultipath/devmapper.h +11 -8
@@ -1,3 +1,8 @@ +#ifndef _DEVMAPPER_H +#define _DEVMAPPER_H + +#include "structs.h" +#define TGT_MPATH "multipath"#define TGT_PART "linear"
@@ -5,14 +10,10 @@ void dm_init(void);int dm_prereq (void );int dm_simplecmd_flush (int ,const char *);int dm_simplecmd_noflush (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_addmap_create (struct multipath *mpp); +int dm_addmap_create_ro (struct multipath *mpp); +int dm_addmap_reload (struct multipath *mpp); +int dm_addmap_reload_ro (struct multipath *mpp);int dm_map_present (const char *);int dm_get_map (char *,unsigned long long *,char *);int dm_get_status (char *,char *);
@@ -35,3 +36,5 @@ int dm_get_uuid(char *name, char *uuid);int dm_get_info (char * mapname,struct dm_info ** dmi);int dm_rename (char * old,char * new);int dm_get_name (char * uuid,char * name); + +#endif /* _DEVMAPPER_H */
libmultipath/dict.c +211 -0
252 lines not on this page · raw message
libmultipath/propsel.c +54 -0
60 lines not on this page · raw message
libmultipath/propsel.h +3 -0
@@ -12,3 +12,6 @@ int select_no_path_retry(struct multipath *mp);int select_pg_timeout (struct multipath *mp);int select_flush_on_last_del (struct multipath *mp);int select_minio (struct multipath *mp); +int select_mode (struct multipath *mp); +int select_uid (struct multipath *mp); +int select_gid (struct multipath *mp);
libmultipath/structs.h +11 -0
@@ -1,6 +1,8 @@#ifndef _STRUCTS_H#define _STRUCTS_H +#include <sys/types.h> +#define WWID_SIZE 128#define SERIAL_SIZE 64#define NODE_NAME_SIZE 19
@@ -67,6 +69,11 @@ enum pgtimeouts {PGTIMEOUT_NONE }; +enum attribute_bits { +ATTR_UID , +ATTR_GID , +ATTR_MODE , +};enum flush_states {FLUSH_UNDEF ,
@@ -159,6 +166,10 @@ struct multipath {int minio;int pg_timeout;int flush_on_last_del; +int attribute_flags; +uid_t uid; +gid_t gid; +mode_t mode;unsigned long long size;vector paths;vector pg;
multipath.conf.annotated +54 -0
66 lines not on this page · raw message
multipath.conf.synthetic +3 -0
@@ -17,6 +17,9 @@ # failback immediate # no_path_retry fail # user_friendly_names no +# mode 644 +# uid 0 +# gid disk #} #blacklist { # wwid 26353900f02796769
Signature · 1 line
1.5.3.3