From 18d39ba3ba872581e0f9498eb7ddb902cda53685 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 31 Jul 2004 14:35:46 +0000 Subject: [PATCH] b=4044 r=adilger - few clients connecting simultaneously might race in mds_lmv_connect(). just take a sem around code that connects to LMV --- lustre/include/linux/obd.h | 1 + lustre/mds/handler.c | 1 + lustre/mds/mds_lmv.c | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index 0279d97..dbcbd69 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -342,6 +342,7 @@ struct mds_obd { struct obd_device *mds_lmv_obd; /* XXX lmv_obd */ struct obd_export *mds_lmv_exp; /* XXX lov_exp */ struct ptlrpc_service *mds_create_service; + struct semaphore mds_lmv_sem; atomic_t mds_real_clients; struct obd_uuid mds_lmv_uuid; struct dentry *mds_fids_dir; diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 035b9fc..a52583b 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -2014,6 +2014,7 @@ static int mds_setup(struct obd_device *obd, obd_count len, void *buf) lcfg->lcfg_inlbuf4); /* we have to know mdsnum before touching underlying fs -bzzz */ + sema_init(&mds->mds_lmv_sem, 1); if (lcfg->lcfg_inllen5 > 0 && lcfg->lcfg_inlbuf5 && strcmp(lcfg->lcfg_inlbuf5, "dumb")) { class_uuid_t uuid; diff --git a/lustre/mds/mds_lmv.c b/lustre/mds/mds_lmv.c index 225d55a..da60695 100644 --- a/lustre/mds/mds_lmv.c +++ b/lustre/mds/mds_lmv.c @@ -57,12 +57,18 @@ int mds_lmv_connect(struct obd_device *obd, char * lmv_name) if (mds->mds_lmv_obd) RETURN(0); + down(&mds->mds_lmv_sem); + if (mds->mds_lmv_obd) { + up(&mds->mds_lmv_sem); + RETURN(0); + } + mds->mds_lmv_obd = class_name2obd(lmv_name); if (!mds->mds_lmv_obd) { CERROR("MDS cannot locate LMV %s\n", lmv_name); mds->mds_lmv_obd = ERR_PTR(-ENOTCONN); - RETURN(-ENOTCONN); + GOTO(err_last, rc = -ENOTCONN); } rc = obd_connect(&conn, mds->mds_lmv_obd, &obd->obd_uuid, OBD_OPT_MDS_CONNECTION); @@ -70,7 +76,7 @@ int mds_lmv_connect(struct obd_device *obd, char * lmv_name) CERROR("MDS cannot connect to LMV %s (%d)\n", lmv_name, rc); mds->mds_lmv_obd = ERR_PTR(rc); - RETURN(rc); + GOTO(err_last, rc); } mds->mds_lmv_exp = class_conn2export(&conn); if (mds->mds_lmv_exp == NULL) @@ -105,6 +111,7 @@ int mds_lmv_connect(struct obd_device *obd, char * lmv_name) if (rc) GOTO(err_reg, rc); + up(&mds->mds_lmv_sem); RETURN(0); err_reg: @@ -113,6 +120,8 @@ err_discon: obd_disconnect(mds->mds_lmv_exp, 0); mds->mds_lmv_exp = NULL; mds->mds_lmv_obd = ERR_PTR(rc); +err_last: + up(&mds->mds_lmv_sem); RETURN(rc); } @@ -135,6 +144,7 @@ int mds_lmv_disconnect(struct obd_device *obd, int flags) int rc = 0; ENTRY; + down(&mds->mds_lmv_sem); if (!IS_ERR(mds->mds_lmv_obd) && mds->mds_lmv_exp != NULL) { obd_register_observer(mds->mds_lmv_obd, NULL); @@ -148,6 +158,7 @@ int mds_lmv_disconnect(struct obd_device *obd, int flags) mds->mds_lmv_exp = NULL; mds->mds_lmv_obd = NULL; } + up(&mds->mds_lmv_sem); RETURN(rc); } -- 1.8.3.1