From a1461cbfa7ea2bccef20eb2f5275648452ee050c Mon Sep 17 00:00:00 2001 From: chenminhua Date: Mon, 2 Apr 2018 04:01:04 -0400 Subject: [PATCH] 1hostos-patch-upgrade:0330 hotpatch modify [Changelog]:add upgrade path [Author]:chenminhua --- libmultipath/discovery.c | 124 +++++++++++++++++++++++++++++++++++++++++++++-- libmultipath/discovery.h | 1 + multipathd/main.c | 4 ++ 3 files changed, 124 insertions(+), 5 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index ee3290c..c49848e 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -34,6 +34,103 @@ #include "prioritizers/alua_rtpg.h" #include "foreign.h" +const char *conf_file = "/etc/multipath_private.conf"; +static int conf_file_parsed = 0; +static int should_remove_local_disk = 0; + +static void parse_config() +{ + FILE *fp = NULL; + char buffer[256] = {0}; + char *str = NULL; + char *p = NULL; + + fp = fopen(conf_file, "r"); + if (fp) { + while (fgets(buffer, sizeof(buffer), fp)) { + str = buffer; + /* skip the space */ + while (isspace(*str)) + str++; + /* skip the comment line */ + if (strncmp(str, "#", 1) == 0) + continue; + /* skip line feed */ + if((p = strchr(str, '\n')) != NULL) + *p = '\0'; + if (strstr(str, "remove_local_disk") != NULL && (p = strstr(str, "=")) != NULL){ + str = p + 1; + /* skip the space */ + while (isspace(*str)) + str++; + if (strcmp(str, "1") == 0){ + should_remove_local_disk = 1; + } + break; + } + } + fclose(fp); + fp = NULL; + } + conf_file_parsed = 1; +} + +static int get_should_remove_local_disk() +{ + if (!conf_file_parsed) + parse_config(); + return should_remove_local_disk; +} + +/* Filter the local disks and remove them from pathvec */ +static int +transport (int h) +{ + char buff[PATH_SIZE]; + int len, off; + struct stat a_stat; + + /* FC host */ + strcpy(buff, "/sys"); + strcat(buff, "/class/fc_host/"); + len = strlen(buff); + snprintf(buff + len, PATH_SIZE - len, "host%d", h); + if ((stat(buff, &a_stat) >= 0) && S_ISDIR(a_stat.st_mode)) { + return 0; + } + memset(buff, 0, PATH_SIZE); + + /* iSCSI device */ + strcpy(buff, "/sys"); + strcat(buff, "/class/iscsi_host/"); + off = strlen(buff); + snprintf(buff + off, PATH_SIZE - off, "host%d", h); + if ((stat(buff, &a_stat) >= 0) && S_ISDIR(a_stat.st_mode)) { + return 0; + } + return 1; +} + +int +remove_local_path (vector pathvec, struct path *pp) +{ + int i = -1; + + if(!get_should_remove_local_disk()){ + return 1; + } + + if (transport(pp->sg_id.host_no) == 0) { + return 1; + } + + if ((i = find_slot(pathvec, (void *)pp)) != -1) { + vector_del_slot(pathvec, i); + } + free_path(pp); + return 0; +} + struct vpd_vendor_page vpd_vendor_pages[VPD_VP_ARRAY_SIZE] = { [VPD_VP_UNDEF] = { 0x00, "undef" }, [VPD_VP_HP3PAR] = { 0xc0, "hp3par" }, @@ -124,6 +221,7 @@ path_discover (vector pathvec, struct config * conf, { struct path * pp; const char * devname; + int err = 1; devname = udev_device_get_sysname(udevice); if (!devname) @@ -137,12 +235,22 @@ path_discover (vector pathvec, struct config * conf, snprintf(devt, BLK_DEV_SIZE, "%d:%d", major(devnum), minor(devnum)); pp = find_path_by_devt(pathvec, devt); - if (!pp) - return store_pathinfo(pathvec, conf, - udevice, flag | DI_BLACKLIST, - NULL); + if (!pp) { + err = store_pathinfo(pathvec, conf, + udevice, flag, &pp); + if (err == 1) + return 1; + if (err == 0) + remove_local_path(pathvec, pp); + return 0; + } } - return pathinfo(pp, conf, flag); + err = pathinfo(pp, conf, flag); + if (err) + return err; + + remove_local_path(pathvec, pp); + return err; } static void cleanup_udev_enumerate_ptr(void *arg) @@ -2091,6 +2199,12 @@ int pathinfo(struct path *pp, struct config *conf, int mask) if (rc != PATHINFO_OK) return rc; + + /* free local device */ + if (transport(pp->sg_id.host_no)) { + condlog(3, "%s is a local device", pp->dev); + return 0; + } } if (mask & DI_BLACKLIST && mask & DI_SYSFS) { diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h index 6444887..a438b44 100644 --- a/libmultipath/discovery.h +++ b/libmultipath/discovery.h @@ -56,6 +56,7 @@ int sysfs_get_asymmetric_access_state(struct path *pp, char *buff, int buflen); int get_uid(struct path * pp, int path_state, struct udev_device *udev, int allow_fallback); +int remove_local_path(vector pathvec, struct path *pp); /* * discovery bitmask diff --git a/multipathd/main.c b/multipathd/main.c index ef14750..41c4258 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -943,6 +943,10 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map) int start_waiter = 0; int ret; + /* if pp is local path,remove it and return 0. */ + if (!remove_local_path(vecs->pathvec, pp)) + return 0; + /* * need path UID to go any further */ -- 1.8.3.1