From d27c044a5dd6d02dcbf8cef9c4ae95e5d3920bef Mon Sep 17 00:00:00 2001 From: yury Date: Thu, 25 Nov 2004 12:58:31 +0000 Subject: [PATCH] - many fixes and cleanups in cobd. By now it load and unloads fine. - small improvements in lmv. - fixed possible freeing of not allocated memory pointer in mds_connect() --- lustre/cobd/cache_obd.c | 207 ++++++++++++++++++++++++--------------- lustre/include/linux/obd.h | 2 + lustre/include/linux/obd_class.h | 16 +-- lustre/ldlm/ldlm_lib.c | 4 +- lustre/lmv/lmv_obd.c | 7 +- lustre/lov/lov_obd.c | 2 +- lustre/mds/handler.c | 6 +- 7 files changed, 150 insertions(+), 94 deletions(-) diff --git a/lustre/cobd/cache_obd.c b/lustre/cobd/cache_obd.c index 204ee8a..884d82b 100644 --- a/lustre/cobd/cache_obd.c +++ b/lustre/cobd/cache_obd.c @@ -33,7 +33,8 @@ #include #include -static int cobd_attach(struct obd_device *obd, obd_count len, void *buf) +static int cobd_attach(struct obd_device *obd, + obd_count len, void *buf) { struct lprocfs_static_vars lvars; @@ -46,30 +47,12 @@ static int cobd_detach(struct obd_device *obd) return lprocfs_obd_detach(obd); } -static int connect_to_obd(char *name, struct lustre_handle *conn) -{ - struct obd_uuid obd_uuid; - struct obd_device *obd; - int rc = 0; - ENTRY; - - obd = class_name2obd(name); - if (obd == NULL) { - CERROR("COBD: unable to find a client for obd: %s\n", - name); - RETURN(-EINVAL); - } - rc = obd_connect(conn, obd, &obd_uuid, 0); - RETURN(rc); -} - static int cobd_setup(struct obd_device *obd, obd_count len, void *buf) { struct lustre_cfg *lcfg = (struct lustre_cfg *)buf; struct cache_obd *cobd = &obd->u.cobd; - struct lustre_handle conn = { 0 }; struct obd_device *master; - int rc; + int rc = 0; ENTRY; if (lcfg->lcfg_inllen1 == 0 || lcfg->lcfg_inlbuf1 == NULL) { @@ -91,35 +74,25 @@ static int cobd_setup(struct obd_device *obd, obd_count len, void *buf) RETURN(-EINVAL); } - cobd->cache_on = 1; sema_init(&cobd->sem, 1); - OBD_ALLOC(cobd->master_name, strlen(lcfg->lcfg_inlbuf1) + 1); + OBD_ALLOC(cobd->master_name, lcfg->lcfg_inllen1); if (!cobd->master_name) - GOTO(put_names, rc = -ENOMEM); + RETURN(-ENOMEM); memcpy(cobd->master_name, lcfg->lcfg_inlbuf1, - strlen(lcfg->lcfg_inlbuf1)); + lcfg->lcfg_inllen1); - OBD_ALLOC(cobd->cache_name, strlen(lcfg->lcfg_inlbuf2) + 1); + OBD_ALLOC(cobd->cache_name, lcfg->lcfg_inllen2); if (!cobd->cache_name) GOTO(put_names, rc = -ENOMEM); memcpy(cobd->cache_name, lcfg->lcfg_inlbuf2, - strlen(lcfg->lcfg_inlbuf2)); + lcfg->lcfg_inllen2); - rc = connect_to_obd(cobd->cache_name, &conn); - if (rc) - GOTO(put_names, rc); - cobd->cache_exp = class_conn2export(&conn); - - RETURN(0); + EXIT; put_names: if (rc) { - if (cobd->cache_name) - OBD_FREE(cobd->cache_name, - strlen(cobd->cache_name) + 1); - if (cobd->master_name) - OBD_FREE(cobd->master_name, - strlen(cobd->master_name) + 1); + OBD_FREE(cobd->master_name, lcfg->lcfg_inllen1); + cobd->master_name = NULL; } return rc; } @@ -127,22 +100,10 @@ put_names: static int cobd_cleanup(struct obd_device *obd, int flags) { struct cache_obd *cobd = &obd->u.cobd; - int rc; ENTRY; - if (cobd->cache_on) { - rc = obd_disconnect(cobd->cache_exp, flags); - if (rc) { - CERROR("error disconnecting cache, err %d\n", - rc); - } - } else { - rc = obd_disconnect(cobd->master_exp, flags); - if (rc) { - CERROR("error disconnecting master, err %d\n", - rc); - } - } + if (!list_empty(&obd->obd_exports)) + RETURN(-EBUSY); if (cobd->cache_name) OBD_FREE(cobd->cache_name, @@ -151,29 +112,127 @@ static int cobd_cleanup(struct obd_device *obd, int flags) OBD_FREE(cobd->master_name, strlen(cobd->master_name) + 1); - RETURN(rc); + RETURN(0); } -struct obd_export *cobd_get_exp(struct obd_device *obd) +static inline struct obd_export * +cobd_get_exp(struct obd_device *obd) { struct cache_obd *cobd = &obd->u.cobd; - if (cobd->cache_on) return cobd->cache_exp; - return cobd->master_exp; } +static int client_obd_connect(struct obd_device *obd, char *name, + struct lustre_handle *conn, + unsigned long flags) +{ + struct obd_device *cli_obd; + int rc = 0; + ENTRY; + + LASSERT(obd); + LASSERT(name); + LASSERT(conn); + + cli_obd = class_name2obd(name); + if (cli_obd == NULL) { + CERROR("%s: unable to find a client for obd: %s\n", + obd->obd_name, name); + RETURN(-EINVAL); + } + rc = obd_connect(conn, cli_obd, &obd->obd_uuid, flags); + if (rc) { + CERROR("error connecting to %s, err %d\n", + name, rc); + } + RETURN(rc); +} + +static int client_obd_disconnect(struct obd_device *obd, + struct obd_export *exp, + unsigned long flags) +{ + struct obd_device *cli_obd; + int rc = 0; + ENTRY; + + cli_obd = class_exp2obd(exp); + cli_obd->obd_no_recov = obd->obd_no_recov; + + rc = obd_disconnect(exp, flags); + if (rc) { + CERROR("error disconnecting from %s, err %d\n", + cli_obd->obd_name, rc); + class_export_put(exp); + } + RETURN(rc); +} + static int cobd_connect(struct lustre_handle *conn, struct obd_device *obd, struct obd_uuid *cluuid, unsigned long flags) { - return class_connect(conn, obd, cluuid); + struct lustre_handle cache_conn = { 0 }; + struct cache_obd *cobd = &obd->u.cobd; + struct obd_export *exp; + int rc = 0; + ENTRY; + + /* connecting class */ + rc = class_connect(conn, obd, cluuid); + if (rc) + RETURN(rc); + exp = class_conn2export(conn); + + /* connecting cache */ + rc = client_obd_connect(obd, cobd->cache_name, + &cache_conn, flags); + if (rc) + GOTO(err_discon, rc); + cobd->cache_exp = class_conn2export(&cache_conn); + cobd->cache_on = 1; + + EXIT; +err_discon: + if (rc) + class_disconnect(exp, 0); + else + class_export_put(exp); + return rc; } -static int cobd_disconnect(struct obd_export *exp, unsigned long flags) +static int +cobd_disconnect(struct obd_export *exp, unsigned long flags) { - return class_disconnect(exp, flags); + struct obd_device *obd; + struct cache_obd *cobd; + int rc = 0; + ENTRY; + + LASSERT(exp != NULL); + obd = class_exp2obd(exp); + if (obd == NULL) { + CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n", + exp->exp_handle.h_cookie); + RETURN(-EINVAL); + } + + cobd = &obd->u.cobd; + + if (cobd->cache_on) { + rc = client_obd_disconnect(obd, cobd->cache_exp, + flags); + cobd->cache_exp = NULL; + } else { + rc = client_obd_disconnect(obd, cobd->master_exp, + flags); + cobd->master_exp = NULL; + } + + rc = class_disconnect(exp, flags); + RETURN(rc); } static int cobd_get_info(struct obd_export *exp, obd_count keylen, @@ -652,7 +711,6 @@ static int cobd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa, static int cobd_flush(struct obd_device *obd) { - /* flush the filesystem from the cache to the real device. */ return 0; } @@ -670,14 +728,10 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, switch (cmd) { case OBD_IOC_COBD_CON: if (!cobd->cache_on) { - struct lustre_handle conn = {0,}; - - rc = obd_disconnect(cobd->master_exp, 0); - if (rc) { - CERROR("error disconnecting master, err %d\n", - rc); - } - rc = connect_to_obd(cobd->cache_name, &conn); + struct lustre_handle conn = {0}; + + rc = client_obd_disconnect(obd, cobd->master_exp, 0); + rc = client_obd_connect(obd, cobd->cache_name, &conn, 0); if (rc) GOTO(out, rc); cobd->cache_exp = class_conn2export(&conn); @@ -694,20 +748,14 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, cache = class_exp2obd(cobd->cache_exp); easize = cache->u.cli.cl_max_mds_easize; cooksize = cache->u.cli.cl_max_mds_cookiesize; - - rc = obd_disconnect(cobd->cache_exp, 0); - if (rc) { - CERROR("error disconnecting master, err %d\n", - rc); - } - - /* should we read from master_dev? */ - rc = connect_to_obd(cobd->master_name, &conn); + + rc = client_obd_disconnect(obd, cobd->cache_exp, 0); + rc = client_obd_connect(obd, cobd->master_name, &conn, 0); if (rc) GOTO(out, rc); cobd->master_exp = class_conn2export(&conn); - master = class_exp2obd(cobd->master_exp); + master = class_exp2obd(cobd->master_exp); master->u.cli.cl_max_mds_easize = easize; master->u.cli.cl_max_mds_cookiesize = cooksize; cobd->cache_on = 0; @@ -718,8 +766,7 @@ static int cobd_iocontrol(unsigned int cmd, struct obd_export *exp, cobd->cache_on = 0; cobd_flush(obd); } else { - CERROR("%s: cache is turned off\n", - obd->obd_name); + CERROR("%s: cache is turned off\n", obd->obd_name); } break; default: diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index 283b1db..52d73c4 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -441,6 +441,8 @@ struct echo_client_obd { struct cache_obd { struct obd_export *master_exp; /* local connection to master obd */ struct obd_export *cache_exp; /* local connection to cache obd */ + struct obd_device *master; + struct obd_device *cache; char *master_name; char *cache_name; int refcount; diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 08f8523..4d07d64 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -658,7 +658,8 @@ static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid, RETURN(rc); } -static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid) +static inline int obd_del_conn(struct obd_import *imp, + struct obd_uuid *uuid) { struct obd_device *obd = imp->imp_obd; int rc; @@ -674,8 +675,9 @@ static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid) static inline int obd_connect(struct lustre_handle *conn, - struct obd_device *obd, struct obd_uuid *cluuid, - unsigned long connect_flags) + struct obd_device *obd, + struct obd_uuid *cluuid, + unsigned long flags) { int rc; ENTRY; @@ -684,11 +686,12 @@ static inline int obd_connect(struct lustre_handle *conn, OBD_CHECK_OP(obd, connect, -EOPNOTSUPP); OBD_COUNTER_INCREMENT(obd, connect); - rc = OBP(obd, connect)(conn, obd, cluuid, connect_flags); + rc = OBP(obd, connect)(conn, obd, cluuid, flags); RETURN(rc); } -static inline int obd_connect_post(struct obd_export *exp, unsigned long flags) +static inline int obd_connect_post(struct obd_export *exp, + unsigned long flags) { int rc; ENTRY; @@ -701,7 +704,8 @@ static inline int obd_connect_post(struct obd_export *exp, unsigned long flags) RETURN(rc); } -static inline int obd_disconnect(struct obd_export *exp, unsigned long flags) +static inline int obd_disconnect(struct obd_export *exp, + unsigned long flags) { int rc; ENTRY; diff --git a/lustre/ldlm/ldlm_lib.c b/lustre/ldlm/ldlm_lib.c index 20a398e..68b7609 100644 --- a/lustre/ldlm/ldlm_lib.c +++ b/lustre/ldlm/ldlm_lib.c @@ -455,7 +455,9 @@ int client_disconnect_export(struct obd_export *exp, unsigned long flags) obd->obd_namespace = NULL; } - /* Yeah, obd_no_recov also (mainly) means "forced shutdown". */ + /* + * Yeah, obd_no_recov also (mainly) means "forced shutdown". + */ if (obd->obd_no_recov) ptlrpc_invalidate_import(imp, 0); else diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 204d211..e7c840d 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -441,6 +441,9 @@ static int lmv_disconnect(struct obd_export *exp, unsigned long flags) mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp); + if (mdc_obd) + mdc_obd->obd_no_recov = obd->obd_no_recov; + #ifdef __KERNEL__ if (lmv_proc_dir) { struct proc_dir_entry *mdc_symlink; @@ -455,10 +458,6 @@ static int lmv_disconnect(struct obd_export *exp, unsigned long flags) } } #endif - if (obd->obd_no_recov) { - if (mdc_obd) - mdc_obd->obd_no_recov = 1; - } CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n", lmv->tgts[i].ltd_exp->exp_obd->obd_name, lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid); diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index ed4612b..b480612 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -427,8 +427,8 @@ static int lov_set_osc_active(struct lov_obd *lov, struct obd_uuid *uuid, static int lov_notify(struct obd_device *obd, struct obd_device *watched, int active, void *data) { - int rc; struct obd_uuid *uuid; + int rc; ENTRY; if (strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) { diff --git a/lustre/mds/handler.c b/lustre/mds/handler.c index 4db5653..19cc81b 100644 --- a/lustre/mds/handler.c +++ b/lustre/mds/handler.c @@ -408,10 +408,12 @@ static int mds_connect(struct lustre_handle *conn, struct obd_device *obd, EXIT; out: if (rc) { - OBD_FREE(mcd, sizeof(*mcd)); + if (mcd) + OBD_FREE(mcd, sizeof(*mcd)); class_disconnect(exp, 0); + } else { + class_export_put(exp); } - class_export_put(exp); return rc; } -- 1.8.3.1