207 lines
5.0 KiB
Diff
207 lines
5.0 KiB
Diff
From a448fe41073d613764b8988d1e22ee0c6e7e3f92 Mon Sep 17 00:00:00 2001
|
|
From: chenminhua <chenminhua1@huawei.com>
|
|
Date: Mon, 2 Apr 2018 04:01:04 -0400
|
|
Subject: [PATCH] remove local path
|
|
|
|
[Changelog]:add upgrade path
|
|
[Author]:chenminhua
|
|
---
|
|
libmultipath/discovery.c | 128 ++++++++++++++++++++++++++++++++++++++++++++---
|
|
libmultipath/discovery.h | 1 +
|
|
multipathd/main.c | 4 ++
|
|
3 files changed, 127 insertions(+), 6 deletions(-)
|
|
|
|
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
|
|
index c2e1754..24e9b50 100644
|
|
--- a/libmultipath/discovery.c
|
|
+++ b/libmultipath/discovery.c
|
|
@@ -36,6 +36,103 @@
|
|
#include "configure.h"
|
|
#include "print.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" },
|
|
@@ -127,22 +224,35 @@ path_discover (vector pathvec, struct config * conf,
|
|
{
|
|
struct path *pp;
|
|
char devt[BLK_DEV_SIZE];
|
|
+ int err = 1;
|
|
dev_t devnum = udev_device_get_devnum(udevice);
|
|
|
|
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);
|
|
- else
|
|
+ if (!pp) {
|
|
+ err = store_pathinfo(pathvec, conf,
|
|
+ udevice, flag | DI_BLACKLIST,
|
|
+ &pp);
|
|
+ if (err == 1)
|
|
+ return 1;
|
|
+ if (err == 0)
|
|
+ remove_local_path(pathvec, pp);
|
|
+ return 0;
|
|
+ }
|
|
+ else {
|
|
/*
|
|
* Don't use DI_BLACKLIST on paths already in pathvec. We rely
|
|
* on the caller to pre-populate the pathvec with valid paths
|
|
* only.
|
|
*/
|
|
- 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)
|
|
@@ -2138,6 +2248,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 (pp->bus == SYSFS_BUS_SCSI &&
|
|
pp->sg_id.proto_id == SCSI_PROTOCOL_USB &&
|
|
!conf->allow_usb_devices) {
|
|
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 12459ab..0b572ee 100644
|
|
--- a/multipathd/main.c
|
|
+++ b/multipathd/main.c
|
|
@@ -964,6 +964,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
|
|
|