From db17ca630494cb171d4142137002e4056a0105f6 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 23 Jan 2006 18:20:34 +0000 Subject: [PATCH] Branch b1_4_mountconf b=8007 - check for already running target - check for already registered mdt - mdt index assignment prep for CMD --- lustre/include/linux/lustre_disk.h | 22 ++++- lustre/include/linux/lustre_mgs.h | 3 +- lustre/liblustre/super.c | 6 +- lustre/llite/llite_lib.c | 3 +- lustre/mgs/.cvsignore | 15 +++ lustre/mgs/mgs_llog.c | 181 +++++++++++++++++++++++-------------- lustre/obdclass/obd_mount.c | 8 +- 7 files changed, 158 insertions(+), 80 deletions(-) create mode 100644 lustre/mgs/.cvsignore diff --git a/lustre/include/linux/lustre_disk.h b/lustre/include/linux/lustre_disk.h index d298289..fa03e8a 100644 --- a/lustre/include/linux/lustre_disk.h +++ b/lustre/include/linux/lustre_disk.h @@ -101,19 +101,35 @@ struct lustre_disk_data { #define MT_STR(data) mt_str((data)->ldd_mount_type) /* Make the mdt/ost server obd name based on the filesystem name */ -static inline void make_sv_name(__u32 flags, __u16 index, char *fs, char *name) +static inline int sv_make_name(__u32 flags, __u16 index, char *fs, char *name) { if (flags & (LDD_F_SV_TYPE_MDT | LDD_F_SV_TYPE_OST)) { sprintf(name, "%.8s-%s%04x", fs, (flags & LDD_F_SV_TYPE_MDT) ? "MDT" : "OST", index); - } else { + } else if (flags & LDD_F_SV_TYPE_MGMT) { sprintf(name, "MGMT"); + } else { + CERROR("unknown server type %#x\n", flags); + return 1; } + return 0; } + +static inline int sv_name2index(char *svname, int *idx) +{ + char *dash = strchr(svname, '-'); + if (!dash) { + CERROR("Can't understand server name %s\n", svname); + return(-EINVAL); + } + *idx = simple_strtol(dash + 4, NULL, 16); + return 0; +} + static inline void ldd_make_sv_name(struct lustre_disk_data *ldd) { - make_sv_name(ldd->ldd_flags, ldd->ldd_svindex, + sv_make_name(ldd->ldd_flags, ldd->ldd_svindex, ldd->ldd_fsname, ldd->ldd_svname); } diff --git a/lustre/include/linux/lustre_mgs.h b/lustre/include/linux/lustre_mgs.h index fc01dd6..061a0d5 100644 --- a/lustre/include/linux/lustre_mgs.h +++ b/lustre/include/linux/lustre_mgs.h @@ -25,7 +25,8 @@ struct fs_db { char fd_name[8]; struct list_head fd_list; - void* fd_index_map; + void* fd_ost_index_map; + void* fd_mdt_index_map; __u32 fd_flags; __u32 fd_gen; //FIXME add a semaphore for locking the fs_db (and logs) diff --git a/lustre/liblustre/super.c b/lustre/liblustre/super.c index 9e982df..ee8ee37 100644 --- a/lustre/liblustre/super.c +++ b/lustre/liblustre/super.c @@ -1887,10 +1887,8 @@ static struct inode_ops llu_inode_ops = { inop_lookup: llu_iop_lookup, inop_getattr: llu_iop_getattr, inop_setattr: llu_iop_setattr, - /* - FIXME doesn't work on 2.6.10fc3? - inop_filldirentries: llu_iop_filldirentries, - */ + //FIXME corresponding libsysio is tagged b_release_1_4_6 + // inop_filldirentries: llu_iop_filldirentries, inop_mkdir: llu_iop_mkdir_raw, inop_rmdir: llu_iop_rmdir_raw, inop_symlink: llu_iop_symlink_raw, diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index e462de8..65f24f0 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -637,7 +637,8 @@ int ll_fill_super(struct super_block *sb) sprintf(ll_instance, "%p", sb); cfg.cfg_instance = ll_instance; cfg.cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid; - + cfg.cfg_last_idx = 0; + /* set up client obds */ err = lustre_process_log(sb, profilenm, &cfg); if (err < 0) { diff --git a/lustre/mgs/.cvsignore b/lustre/mgs/.cvsignore new file mode 100644 index 0000000..d5103fa --- /dev/null +++ b/lustre/mgs/.cvsignore @@ -0,0 +1,15 @@ +.Xrefs +config.log +config.status +configure +Makefile +.deps +TAGS +.*.cmd +autoMakefile.in +autoMakefile +*.ko +*.mod.c +.*.o.flags +.tmp_versions +.depend diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 91b3141..a2d7df6 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -49,50 +49,62 @@ /******************** DB functions *********************/ /* from the (client) config log, figure out: - 1. which ost's are active (by index) + 1. which ost's/mdt's are configured (by index) 2. what the last config step is */ +/* FIXME is it better to have a separate db file, instead of parsing the info + out of the client log? */ static int db_handler(struct llog_handle *llh, struct llog_rec_hdr *rec, void *data) { struct fs_db *db = (struct fs_db *)data; int cfg_len = rec->lrh_len; char *cfg_buf = (char*) (rec + 1); - int rc = 0; + struct lustre_cfg *lcfg; + int index, rc = 0; ENTRY; - if (rec->lrh_type == OBD_CFG_REC) { - struct lustre_cfg *lcfg; - int index; + if (rec->lrh_type != OBD_CFG_REC) { + CERROR("unhandled lrh_type: %#x\n", rec->lrh_type); + RETURN(-EINVAL); + } - rc = lustre_cfg_sanity_check(cfg_buf, cfg_len); - if (rc) - GOTO(out, rc); + rc = lustre_cfg_sanity_check(cfg_buf, cfg_len); + if (rc) + RETURN(rc); - lcfg = (struct lustre_cfg *)cfg_buf; + lcfg = (struct lustre_cfg *)cfg_buf; - if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD || - lcfg->lcfg_command == LCFG_LOV_DEL_OBD) { - index = simple_strtol(lustre_cfg_string(lcfg, 2), - NULL, 0); - set_bit(index, db->fd_index_map); - } - /* Never clear_bit: once assigned, we can never reassign the - same index again */ - - if (lcfg->lcfg_command == LCFG_MARKER) { - struct cfg_marker *marker; - marker = lustre_cfg_buf(lcfg, 1); - db->fd_gen = max(db->fd_gen, marker->cm_step); - CDEBUG(D_MGS, "marker %d %s\n", marker->cm_step, - marker->cm_comment); - } + CDEBUG(D_INFO, "cmd %x %s %s\n", lcfg->lcfg_command, + lustre_cfg_string(lcfg, 0), lustre_cfg_string(lcfg, 1)); - } else { - CERROR("unhandled lrh_type: %#x\n", rec->lrh_type); - rc = -EINVAL; + /* Figure out ost indicies */ + if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD || + lcfg->lcfg_command == LCFG_LOV_DEL_OBD) { + index = simple_strtol(lustre_cfg_string(lcfg, 2), + NULL, 10); + set_bit(index, db->fd_ost_index_map); } -out: + + /* Figure out mdt indicies */ + if ((lcfg->lcfg_command == LCFG_ATTACH) && + (strcmp(lustre_cfg_string(lcfg, 1), LUSTRE_MDC_NAME) == 0)) { + rc = sv_name2index(lustre_cfg_string(lcfg, 0), &index); + if (rc) + RETURN(rc); + CDEBUG(D_MGS, "MDT index is %d\n", index); + set_bit(index, db->fd_mdt_index_map); + } + + /* Keep track of the latest marker step */ + if (lcfg->lcfg_command == LCFG_MARKER) { + struct cfg_marker *marker; + marker = lustre_cfg_buf(lcfg, 1); + db->fd_gen = max(db->fd_gen, marker->cm_step); + CDEBUG(D_MGS, "marker %d %s\n", marker->cm_step, + marker->cm_comment); + } + RETURN(rc); } @@ -127,12 +139,11 @@ out_pop: RETURN(rc); } -static int next_ost_index(void *index_map, int map_len) +static int next_index(void *index_map, int map_len) { int i; for (i = 0; i < map_len * 8; i++) if (!test_bit(i, index_map)) { - set_bit(i, index_map); return i; } CERROR("max index %d exceeded.\n", i); @@ -168,18 +179,19 @@ static struct fs_db *mgs_new_db(struct obd_device *obd, char *fsname) { struct mgs_obd *mgs = &obd->u.mgs; struct fs_db *db; + ENTRY; OBD_ALLOC(db, sizeof(*db)); - if (!db) { - CERROR("No memory for fs_db.\n"); - return NULL; - } - OBD_ALLOC(db->fd_index_map, INDEX_MAP_SIZE); - if (!db->fd_index_map) { - CERROR("No memory for index_map.\n"); - OBD_FREE(db, sizeof(*db)); - return NULL; + if (!db) + RETURN(NULL); + + OBD_ALLOC(db->fd_ost_index_map, INDEX_MAP_SIZE); + OBD_ALLOC(db->fd_mdt_index_map, INDEX_MAP_SIZE); + if (!db->fd_ost_index_map || !db->fd_mdt_index_map) { + CERROR("No memory for index maps\n"); + GOTO(err, 0); } + strncpy(db->fd_name, fsname, sizeof(db->fd_name)); //INIT_LIST_HEAD(&db->ost_infos); @@ -187,13 +199,21 @@ static struct fs_db *mgs_new_db(struct obd_device *obd, char *fsname) list_add(&db->fd_list, &mgs->mgs_fs_db_list); spin_unlock(&mgs->mgs_fs_db_lock); - return db; + RETURN(db); +err: + if (db->fd_ost_index_map) + OBD_FREE(db->fd_ost_index_map, INDEX_MAP_SIZE); + if (db->fd_mdt_index_map) + OBD_FREE(db->fd_mdt_index_map, INDEX_MAP_SIZE); + OBD_FREE(db, sizeof(*db)); + RETURN(NULL); } static void mgs_free_db(struct fs_db *db) { list_del(&db->fd_list); - OBD_FREE(db->fd_index_map, INDEX_MAP_SIZE); + OBD_FREE(db->fd_ost_index_map, INDEX_MAP_SIZE); + OBD_FREE(db->fd_mdt_index_map, INDEX_MAP_SIZE); OBD_FREE(db, sizeof(*db)); } @@ -272,49 +292,68 @@ static int mgs_find_or_make_db(struct obd_device *obd, char *name, int mgs_set_index(struct obd_device *obd, struct mgmt_target_info *mti) { struct fs_db *db; + void *imap; int rc = 0; + ENTRY; rc = mgs_find_or_make_db(obd, mti->mti_fsname, &db); if (rc) { CERROR("Can't get db for %s\n", mti->mti_fsname); - return rc; + RETURN(rc); } - if (!(mti->mti_flags & LDD_F_NEED_INDEX)) { - if (mti->mti_stripe_index >= INDEX_MAP_SIZE * 8) { - LCONSOLE_ERROR("Server %s requested index %d, but the" - "max index is %d.\n", - mti->mti_svname, mti->mti_stripe_index, - INDEX_MAP_SIZE * 8); - return -ERANGE; - } - if (test_bit(mti->mti_stripe_index, db->fd_index_map)) { - LCONSOLE_ERROR("Server %s requested index %d, but that" - "index is already in use.\n", - mti->mti_svname, mti->mti_stripe_index); - return -EADDRINUSE; - } else { - set_bit(mti->mti_stripe_index, db->fd_index_map); - return 0; - } - } + if (mti->mti_flags & LDD_F_SV_TYPE_OST) + imap = db->fd_ost_index_map; + else if (mti->mti_flags & LDD_F_SV_TYPE_MDT) + imap = db->fd_mdt_index_map; + else + RETURN(-EINVAL); - if (mti->mti_flags & LDD_F_SV_TYPE_OST) { - rc = next_ost_index(db->fd_index_map, INDEX_MAP_SIZE); + if (mti->mti_flags & LDD_F_NEED_INDEX) { + rc = next_index(imap, INDEX_MAP_SIZE); if (rc == -1) - return -ERANGE; + RETURN(-ERANGE); mti->mti_stripe_index = rc; - } else { - mti->mti_stripe_index = 1; /*FIXME*/ } - make_sv_name(mti->mti_flags, mti->mti_stripe_index, + /* Remove after CMD */ + if ((mti->mti_flags & LDD_F_SV_TYPE_MDT) && + (mti->mti_stripe_index > 0)) { + LCONSOLE_ERROR("MDT index must = 0 (until Clustered MetaData " + "feature is ready.)\n"); + mti->mti_stripe_index = 0; + } + + if (mti->mti_stripe_index >= INDEX_MAP_SIZE * 8) { + LCONSOLE_ERROR("Server %s requested index %d, but the" + "max index is %d.\n", + mti->mti_svname, mti->mti_stripe_index, + INDEX_MAP_SIZE * 8); + RETURN(-ERANGE); + } + + if (test_bit(mti->mti_stripe_index, imap)) { + LCONSOLE_ERROR("Server %s requested index %d, but that " + "index is already in use in the %s " + "filesystem. This server " + "may have been reformatted, or the " + "index changed. (To reformat the entire " + "filesystem, specify 'destroy_fs' " + "when reformatting a MDT.)\n", + mti->mti_svname, mti->mti_stripe_index, + mti->mti_fsname); + /* FIXME implement destroy_fs! */ + RETURN(-EADDRINUSE); + } + + set_bit(mti->mti_stripe_index, imap); + sv_make_name(mti->mti_flags, mti->mti_stripe_index, mti->mti_fsname, mti->mti_svname); CDEBUG(D_MGS, "Set new index for %s to %d\n", mti->mti_svname, mti->mti_stripe_index); - return 0; + RETURN(0); } /******************** config log recording functions *********************/ @@ -680,6 +719,7 @@ static int mgs_write_log_mdt(struct obd_device *obd, struct fs_db *db, rc = mgs_write_log_lov(obd, db, mti, mti->mti_svname, lovname); } + /* else there's already some ost entries in the mdt log. */ name_create(mti->mti_svname, "_UUID", &mdsuuid); @@ -853,8 +893,9 @@ static int mgs_write_log_ost(struct obd_device *obd, struct fs_db *db, /* We also have to update the other logs where this osc is part of the lov */ /* Append ost info to mdt log */ - // FIXME need real mdt name - name_create(mti->mti_fsname, "-MDT0001", &logname); + // FIXME need real mdt name -- but MDT may not have registered yet! + // FIXME add to all mdt logs for CMD + name_create(mti->mti_fsname, "-MDT0000", &logname); name_create(mti->mti_fsname, "-mdtlov", &lovname); mgs_write_log_osc(obd, db, mti, logname, lovname, ostuuid); name_destroy(lovname); diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index a0d0d85..1744bd4 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -973,6 +973,12 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt) } } + if (class_name2obd(lsi->lsi_ldd->ldd_svname)) { + LCONSOLE_ERROR("The target named %s is already running\n", + lsi->lsi_ldd->ldd_svname); + GOTO(out, rc = -EBUSY); + } + /* Let the target look up the mount using the target's name (we can't pass the sb or mnt through class_process_config.) */ rc = server_register_mount(lsi->lsi_ldd->ldd_svname, sb, mnt); @@ -980,7 +986,7 @@ static int server_start_targets(struct super_block *sb, struct vfsmount *mnt) GOTO(out, rc); /* Start targets using the llog named for the target */ - cfg.cfg_instance = NULL; + memset(&cfg, 0, sizeof(cfg)); rc = lustre_process_log(sb, lsi->lsi_ldd->ldd_svname, &cfg); if (rc) { CERROR("failed to start server %s: %d\n", -- 1.8.3.1