From d6aacafe475b4c5e6633f0ee00b26d6f1efbc367 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 28 Feb 2006 21:45:52 +0000 Subject: [PATCH] Branch b1_4_mountconf b=8007 use random uuid for MGC so that MGS doesn't deny reconnection after parition. --- lustre/include/linux/obd_class.h | 3 +- lustre/llite/llite_lib.c | 27 +----- lustre/mgs/mgs_handler.c | 22 +---- lustre/obdclass/class_obd.c | 1 + lustre/obdclass/obd_mount.c | 25 +++-- lustre/obdclass/uuid.c | 205 ++++++++++++++++++++++----------------- 6 files changed, 139 insertions(+), 144 deletions(-) diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 79c6ee7..cff5c37 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -144,6 +144,7 @@ struct lustre_profile { struct lustre_profile *class_get_profile(char * prof); void class_del_profile(char *prof); +/* genops.c */ #define class_export_get(exp) \ ({ \ struct obd_export *exp_ = exp; \ @@ -1227,7 +1228,7 @@ extern void obd_sysctl_clean (void); /* uuid.c */ typedef __u8 class_uuid_t[16]; -//int class_uuid_parse(struct obd_uuid in, class_uuid_t out); +void class_generate_random_uuid(class_uuid_t uuid); void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out); /* lustre_peer.c */ diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index c1ddf7e..90a3604 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -48,31 +48,6 @@ extern struct address_space_operations ll_dir_aops; #define log2(n) ffz(~(n)) #endif -/* We need to have some extra twiddling here because some systems have - * no random state when they start up. */ -static void -lustre_generate_random_uuid(class_uuid_t uuid) -{ - struct timeval t; - int *i, j, k; - - ENTRY; - LASSERT(sizeof(class_uuid_t) % sizeof(*i) == 0); - - j = jiffies; - do_gettimeofday(&t); - k = t.tv_usec; - - generate_random_uuid(uuid); - - for (i = (int *)uuid; (char *)i < (char *)uuid + sizeof(class_uuid_t); i++) { - *i ^= j ^ k; - j = ((j << 8) & 0xffffff00) | ((j >> 24) & 0x000000ff); - k = ((k >> 8) & 0x00ffffff) | ((k << 24) & 0xff000000); - } - - EXIT; -} struct ll_sb_info *ll_init_sbi(void) { @@ -98,7 +73,7 @@ struct ll_sb_info *ll_init_sbi(void) INIT_LIST_HEAD(&sbi->ll_conn_chain); INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list); - lustre_generate_random_uuid(uuid); + class_generate_random_uuid(uuid); class_uuid_unparse(uuid, &sbi->ll_sb_uuid); CDEBUG(D_HA, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid); diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 8ffd4f5..4633e89 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -47,7 +47,6 @@ #include #include "mgs_internal.h" -static int mgs_cleanup(struct obd_device *obd); /* Establish a connection to the MGS.*/ static int mgs_connect(struct lustre_handle *conn, struct obd_device *obd, @@ -81,23 +80,6 @@ static int mgs_connect(struct lustre_handle *conn, struct obd_device *obd, RETURN(rc); } -static int mgs_reconnect(struct obd_export *exp, struct obd_device *obd, - struct obd_uuid *cluuid, - struct obd_connect_data *data) -{ - int rc = -ENOSYS; - ENTRY; - - if (exp == NULL || obd == NULL || cluuid == NULL) - RETURN(-EINVAL); - - CERROR("Reconnect FIXME\n"); - class_fail_export(exp); - //rc = mds_connect_internal(exp, data); - - RETURN(rc); -} - static int mgs_disconnect(struct obd_export *exp) { unsigned long irqflags; @@ -130,6 +112,7 @@ static int mgs_disconnect(struct obd_export *exp) RETURN(rc); } +static int mgs_cleanup(struct obd_device *obd); static int mgs_handle(struct ptlrpc_request *req); /* Start the MGS obd */ @@ -335,7 +318,7 @@ static int mgs_check_target(struct obd_device *obd, struct mgs_target_info *mti) } /* FIXME If the logs don't contain the mti_nids then add - them all as failover nids */ + them all as failover nids? */ RETURN(rc); } @@ -668,7 +651,6 @@ out_free: static struct obd_ops mgs_obd_ops = { .o_owner = THIS_MODULE, .o_connect = mgs_connect, - .o_reconnect = mgs_reconnect, .o_disconnect = mgs_disconnect, .o_setup = mgs_setup, .o_precleanup = mgs_precleanup, diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index cdfd626..f18f032 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -411,6 +411,7 @@ EXPORT_SYMBOL(class_conn2cliimp); EXPORT_SYMBOL(class_disconnect); /* uuid.c */ +EXPORT_SYMBOL(class_generate_random_uuid); EXPORT_SYMBOL(class_uuid_unparse); EXPORT_SYMBOL(lustre_uuid_to_peer); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 2844768..0992da8 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -545,9 +545,9 @@ static int lustre_start_mgc(struct super_block *sb) struct lustre_sb_info *lsi = s2lsi(sb); struct obd_device *obd; struct obd_export *exp; - char *uuid; + struct obd_uuid *uuid; + class_uuid_t uuidc; lnet_nid_t nid; - lnet_process_id_t id; int recov_bk; int rc = 0, i; ENTRY; @@ -590,19 +590,30 @@ static int lustre_start_mgc(struct super_block *sb) if (rc < 0) RETURN(rc); - /* Generate a unique uuid for each MGC - use the 1st non-loopback nid */ + /* Generate a unique uuid for each MGC */ + OBD_ALLOC_PTR(uuid); +#if 0 + /* use the 1st non-loopback nid */ + lnet_process_id_t id; i = 0; while ((rc = LNetGetId(i++, &id)) != -ENOENT) { if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) continue; break; } - OBD_ALLOC(uuid, sizeof(struct obd_uuid)); - sprintf(uuid, "mgc_"LPX64, id.nid); + sprintf(uuid->uuid, "mgc_"LPX64, id.nid); +#else + /* random makes reconnect easier */ + class_generate_random_uuid(uuidc); + class_uuid_unparse(uuidc, uuid); +#endif + CDEBUG(D_MOUNT, "generated uuid: %s\n", uuid->uuid); + /* Start the MGC */ rc = lustre_start_simple(LUSTRE_MGC_OBDNAME, LUSTRE_MGC_NAME, - uuid, LUSTRE_MGS_OBDNAME, libcfs_nid2str(nid)); - OBD_FREE(uuid, sizeof(struct obd_uuid)); + (char *)uuid->uuid, LUSTRE_MGS_OBDNAME, + libcfs_nid2str(nid)); + OBD_FREE_PTR(uuid); if (rc) RETURN(rc); diff --git a/lustre/obdclass/uuid.c b/lustre/obdclass/uuid.c index dd66ae5..f9235dd 100644 --- a/lustre/obdclass/uuid.c +++ b/lustre/obdclass/uuid.c @@ -27,117 +27,142 @@ #include /* for LUSTRE_MDC_NAME */ struct uuid { - __u32 time_low; - __u16 time_mid; - __u16 time_hi_and_version; - __u16 clock_seq; - __u8 node[6]; + __u32 time_low; + __u16 time_mid; + __u16 time_hi_and_version; + __u16 clock_seq; + __u8 node[6]; }; static void uuid_unpack(class_uuid_t in, struct uuid *uu) { - __u8 *ptr = in; - __u32 tmp; + __u8 *ptr = in; + __u32 tmp; - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_low = tmp; + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_mid = tmp; + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->time_hi_and_version = tmp; + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; - tmp = *ptr++; - tmp = (tmp << 8) | *ptr++; - uu->clock_seq = tmp; + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; - memcpy(uu->node, ptr, 6); + memcpy(uu->node, ptr, 6); } #if 0 static void uuid_pack(struct uuid *uu, class_uuid_t ptr) { - __u32 tmp; - unsigned char *out = ptr; - - tmp = uu->time_low; - out[3] = (unsigned char) tmp; - tmp >>= 8; - out[2] = (unsigned char) tmp; - tmp >>= 8; - out[1] = (unsigned char) tmp; - tmp >>= 8; - out[0] = (unsigned char) tmp; - - tmp = uu->time_mid; - out[5] = (unsigned char) tmp; - tmp >>= 8; - out[4] = (unsigned char) tmp; - - tmp = uu->time_hi_and_version; - out[7] = (unsigned char) tmp; - tmp >>= 8; - out[6] = (unsigned char) tmp; - - tmp = uu->clock_seq; - out[9] = (unsigned char) tmp; - tmp >>= 8; - out[8] = (unsigned char) tmp; - - memcpy(out+10, uu->node, 6); + __u32 tmp; + unsigned char *out = ptr; + + tmp = uu->time_low; + out[3] = (unsigned char) tmp; + tmp >>= 8; + out[2] = (unsigned char) tmp; + tmp >>= 8; + out[1] = (unsigned char) tmp; + tmp >>= 8; + out[0] = (unsigned char) tmp; + + tmp = uu->time_mid; + out[5] = (unsigned char) tmp; + tmp >>= 8; + out[4] = (unsigned char) tmp; + + tmp = uu->time_hi_and_version; + out[7] = (unsigned char) tmp; + tmp >>= 8; + out[6] = (unsigned char) tmp; + + tmp = uu->clock_seq; + out[9] = (unsigned char) tmp; + tmp >>= 8; + out[8] = (unsigned char) tmp; + + memcpy(out+10, uu->node, 6); } int class_uuid_parse(struct obd_uuid in, class_uuid_t uu) { - struct uuid uuid; - int i; - char *cp, buf[3]; - - if (strlen(in) != 36) - return -1; - for (i=0, cp = in; i <= 36; i++,cp++) { - if ((i == 8) || (i == 13) || (i == 18) || - (i == 23)) - if (*cp == '-') - continue; - if (i== 36) - if (*cp == 0) - continue; - if (!isxdigit(*cp)) - return -1; - } - uuid.time_low = simple_strtoul(in, NULL, 16); - uuid.time_mid = simple_strtoul(in+9, NULL, 16); - uuid.time_hi_and_version = simple_strtoul(in+14, NULL, 16); - uuid.clock_seq = simple_strtoul(in+19, NULL, 16); - cp = in+24; - buf[2] = 0; - for (i=0; i < 6; i++) { - buf[0] = *cp++; - buf[1] = *cp++; - uuid.node[i] = simple_strtoul(buf, NULL, 16); - } - - uuid_pack(&uuid, uu); - return 0; + struct uuid uuid; + int i; + char *cp, buf[3]; + + if (strlen(in) != 36) + return -1; + for (i=0, cp = in; i <= 36; i++,cp++) { + if ((i == 8) || (i == 13) || (i == 18) || + (i == 23)) + if (*cp == '-') + continue; + if (i== 36) + if (*cp == 0) + continue; + if (!isxdigit(*cp)) + return -1; + } + uuid.time_low = simple_strtoul(in, NULL, 16); + uuid.time_mid = simple_strtoul(in+9, NULL, 16); + uuid.time_hi_and_version = simple_strtoul(in+14, NULL, 16); + uuid.clock_seq = simple_strtoul(in+19, NULL, 16); + cp = in+24; + buf[2] = 0; + for (i=0; i < 6; i++) { + buf[0] = *cp++; + buf[1] = *cp++; + uuid.node[i] = simple_strtoul(buf, NULL, 16); + } + + uuid_pack(&uuid, uu); + return 0; } #endif + +void generate_random_uuid(unsigned char uuid_out[16]); + +/* We need to have some extra twiddling here because some systems have + * no random state when they start up. */ +void class_generate_random_uuid(class_uuid_t uuid) +{ + struct timeval t; + int *i, j, k; + + LASSERT(sizeof(class_uuid_t) % sizeof(*i) == 0); + + j = jiffies; + do_gettimeofday(&t); + k = t.tv_usec; + + generate_random_uuid(uuid); + + for (i = (int *)uuid; (char *)i < (char *)uuid + sizeof(class_uuid_t); i++) { + *i ^= j ^ k; + j = ((j << 8) & 0xffffff00) | ((j >> 24) & 0x000000ff); + k = ((k >> 8) & 0x00ffffff) | ((k << 24) & 0xff000000); + } +} + void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out) { - struct uuid uuid; - - uuid_unpack(uu, &uuid); - sprintf(out->uuid, - "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, - uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, - uuid.node[0], uuid.node[1], uuid.node[2], - uuid.node[3], uuid.node[4], uuid.node[5]); + struct uuid uuid; + + uuid_unpack(uu, &uuid); + sprintf(out->uuid, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, + uuid.clock_seq >> 8, uuid.clock_seq & 0xFF, + uuid.node[0], uuid.node[1], uuid.node[2], + uuid.node[3], uuid.node[4], uuid.node[5]); } -- 1.8.3.1