X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Flmv%2Flmv_obd.c;h=bd74795355f3015da6e973741491f6e1a7248ec6;hp=e88dfc4d9cc29e7f55fa5bf7adb8551d4bf7282b;hb=57b9e88690b51cd8ccd9b2fd8a09f533ca09a7bd;hpb=9bc7e4aaddc53c442e50ca49b565ea689db83eed diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index e88dfc4..bd74795 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -31,6 +31,7 @@ #include #include #include +#include #else #include #endif @@ -47,8 +48,14 @@ #include #include #include +#include #include "lmv_internal.h" +/* not defined for liblustre building */ +#if !defined(ATOMIC_INIT) +#define ATOMIC_INIT(val) { (val) } +#endif + /* object cache. */ kmem_cache_t *obj_cache; atomic_t obj_cache_count = ATOMIC_INIT(0); @@ -73,8 +80,8 @@ static void lmv_activate_target(struct lmv_obd *lmv, static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid, int activate) { - struct obd_device *obd; struct lmv_tgt_desc *tgt; + struct obd_device *obd; int i, rc = 0; ENTRY; @@ -89,7 +96,7 @@ static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid, CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n", i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie); - if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0) + if (obd_uuid_equals(uuid, &tgt->uuid)) break; } @@ -126,14 +133,15 @@ static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid, static int lmv_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_MDC_NAME)) { CERROR("unexpected notification of %s %s!\n", watched->obd_type->typ_name, watched->obd_name); - return -EINVAL; + RETURN(-EINVAL); } uuid = &watched->u.cli.cl_import->imp_target_uuid; @@ -185,7 +193,8 @@ int lmv_detach(struct obd_device *dev) /* this is fake connect function. Its purpose is to initialize lmv and say * caller that everything is okay. Real connection will be performed later. */ static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd, - struct obd_uuid *cluuid, unsigned long flags) + struct obd_uuid *cluuid, struct obd_connect_data *data, + unsigned long flags) { #ifdef __KERNEL__ struct proc_dir_entry *lmv_proc_dir; @@ -216,6 +225,8 @@ static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd, lmv->cluuid = *cluuid; lmv->connect_flags = flags; sema_init(&lmv->init_sem, 1); + if (data) + memcpy(&lmv->conn_data, data, sizeof(*data)); #ifdef __KERNEL__ lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry, @@ -281,14 +292,15 @@ int lmv_check_connect(struct obd_device *obd) struct obd_uuid *cluuid; struct obd_export *exp; int rc, rc2, i; + ENTRY; if (lmv->connected) - return 0; + RETURN(0); down(&lmv->init_sem); if (lmv->connected) { up(&lmv->init_sem); - return 0; + RETURN(0); } cluuid = &lmv->cluuid; @@ -298,9 +310,9 @@ int lmv_check_connect(struct obd_device *obd) cluuid->uuid, obd->obd_name); for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) { - struct obd_device *tgt_obd; - struct lustre_handle conn = {0, }; struct obd_uuid lmv_mdc_uuid = { "LMV_MDC_UUID" }; + struct lustre_handle conn = {0, }; + struct obd_device *tgt_obd; LASSERT(tgts != NULL); @@ -329,7 +341,7 @@ int lmv_check_connect(struct obd_device *obd) GOTO(out_disc, rc = -EINVAL); } - rc = obd_connect(&conn, tgt_obd, &lmv_mdc_uuid, + rc = obd_connect(&conn, tgt_obd, &lmv_mdc_uuid, &lmv->conn_data, lmv->connect_flags); if (rc) { CERROR("target %s connect error %d\n", @@ -388,7 +400,7 @@ int lmv_check_connect(struct obd_device *obd) class_export_put(exp); lmv->connected = 1; up(&lmv->init_sem); - return 0; + RETURN(0); out_disc: while (i-- > 0) { @@ -405,7 +417,7 @@ int lmv_check_connect(struct obd_device *obd) } class_disconnect(exp, 0); up(&lmv->init_sem); - RETURN (rc); + return rc; } static int lmv_disconnect(struct obd_export *exp, unsigned long flags) @@ -439,6 +451,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; @@ -453,10 +468,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); @@ -541,27 +552,27 @@ static int lmv_setup(struct obd_device *obd, obd_count len, void *buf) struct lmv_obd *lmv = &obd->u.lmv; ENTRY; - if (lcfg->lcfg_inllen1 < 1) { + if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) { CERROR("LMV setup requires a descriptor\n"); RETURN(-EINVAL); } - if (lcfg->lcfg_inllen2 < 1) { - CERROR("LMV setup requires an OST UUID list\n"); + if (LUSTRE_CFG_BUFLEN(lcfg, 2) < 1) { + CERROR("LMV setup requires an MDT UUID list\n"); RETURN(-EINVAL); } - desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1; - if (sizeof(*desc) > lcfg->lcfg_inllen1) { + desc = (struct lmv_desc *)lustre_cfg_buf(lcfg, 1); + if (sizeof(*desc) > LUSTRE_CFG_BUFLEN(lcfg, 1)) { CERROR("descriptor size wrong: %d > %d\n", - (int)sizeof(*desc), lcfg->lcfg_inllen1); + (int)sizeof(*desc), LUSTRE_CFG_BUFLEN(lcfg, 1)); RETURN(-EINVAL); } - uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2; - if (sizeof(*uuids) * desc->ld_tgt_count != lcfg->lcfg_inllen2) { + uuids = (struct obd_uuid *)lustre_cfg_buf(lcfg, 2); + if (sizeof(*uuids) * desc->ld_tgt_count != LUSTRE_CFG_BUFLEN(lcfg, 2)) { CERROR("UUID array size wrong: %u * %u != %u\n", - sizeof(*uuids), desc->ld_tgt_count, lcfg->lcfg_inllen2); + sizeof(*uuids), desc->ld_tgt_count, LUSTRE_CFG_BUFLEN(lcfg, 2)); RETURN(-EINVAL); } @@ -590,7 +601,7 @@ static int lmv_setup(struct obd_device *obd, obd_count len, void *buf) OBD_FREE(lmv->tgts, lmv->tgts_size); } - tgt_obd = class_find_client_obd(&lmv->tgts->uuid, LUSTRE_MDC_NAME, + tgt_obd = class_find_client_obd(&lmv->tgts->uuid, LUSTRE_MDC_NAME, &obd->obd_uuid); if (!tgt_obd) { CERROR("Target %s not attached\n", lmv->tgts->uuid.uuid); @@ -615,36 +626,43 @@ static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs, unsigned long max_age) { struct lmv_obd *lmv = &obd->u.lmv; - struct obd_statfs temp; + struct obd_statfs *temp; int rc = 0, i; ENTRY; rc = lmv_check_connect(obd); if (rc) RETURN(rc); + + OBD_ALLOC(temp, sizeof(*temp)); + if (temp == NULL) + RETURN(-ENOMEM); for (i = 0; i < lmv->desc.ld_tgt_count; i++) { - if (lmv->tgts[i].ltd_exp == NULL) { - CWARN("%s: NULL export for %d\n", obd->obd_name, i); + if (lmv->tgts[i].ltd_exp == NULL) continue; - } - rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, &temp, max_age); + rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, temp, max_age); if (rc) { - CERROR("can't stat MDS #%d (%s)\n", i, - lmv->tgts[i].ltd_exp->exp_obd->obd_name); - RETURN(rc); + CERROR("can't stat MDS #%d (%s), error %d\n", i, + lmv->tgts[i].ltd_exp->exp_obd->obd_name, + rc); + GOTO(out_free_temp, rc); } if (i == 0) { - memcpy(osfs, &temp, sizeof(temp)); + memcpy(osfs, temp, sizeof(*temp)); } else { - osfs->os_bavail += temp.os_bavail; - osfs->os_blocks += temp.os_blocks; - osfs->os_ffree += temp.os_ffree; - osfs->os_files += temp.os_files; + osfs->os_bavail += temp->os_bavail; + osfs->os_blocks += temp->os_blocks; + osfs->os_ffree += temp->os_ffree; + osfs->os_files += temp->os_files; } } - RETURN(rc); + + EXIT; +out_free_temp: + OBD_FREE(temp, sizeof(*temp)); + return rc; } static int lmv_getstatus(struct obd_export *exp, struct lustre_id *id) @@ -665,8 +683,8 @@ static int lmv_getstatus(struct obd_export *exp, struct lustre_id *id) } static int lmv_getattr(struct obd_export *exp, struct lustre_id *id, - __u64 valid, unsigned int ea_size, - struct ptlrpc_request **request) + __u64 valid, const char *ea_name, int ea_namelen, + unsigned int ea_size, struct ptlrpc_request **request) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; @@ -680,8 +698,9 @@ static int lmv_getattr(struct obd_export *exp, struct lustre_id *id, LASSERT(i < lmv->desc.ld_tgt_count); + rc = md_getattr(lmv->tgts[i].ltd_exp, id, valid, - ea_size, request); + ea_name, ea_namelen, ea_size, request); if (rc) RETURN(rc); @@ -839,17 +858,18 @@ int lmv_get_mea_and_update_object(struct obd_export *exp, struct ptlrpc_request *req = NULL; struct lmv_obj *obj; struct lustre_md md; - __u64 valid; int mealen, rc; + __u64 valid; + ENTRY; md.mea = NULL; mealen = MEA_SIZE_LMV(lmv); - valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA; + valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA | OBD_MD_MEA; /* time to update mea of parent id */ rc = md_getattr(lmv->tgts[id_group(id)].ltd_exp, - id, valid, mealen, &req); + id, valid, NULL, 0, mealen, &req); if (rc) { CERROR("md_getattr() failed, error %d\n", rc); GOTO(cleanup, rc); @@ -871,10 +891,11 @@ int lmv_get_mea_and_update_object(struct obd_export *exp, lmv_put_obj(obj); obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea); + EXIT; cleanup: if (req) ptlrpc_req_finished(req); - RETURN(rc); + return rc; } int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data, @@ -940,6 +961,7 @@ int lmv_done_writing(struct obd_export *exp, struct obdo *obdo) struct lmv_obd *lmv = &obd->u.lmv; int rc; ENTRY; + rc = lmv_check_connect(obd); if (rc) RETURN(rc); @@ -959,45 +981,99 @@ int lmv_enqueue_slaves(struct obd_export *exp, int locktype, struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; struct mea *mea = data->mea1; - struct mdc_op_data data2; + struct mdc_op_data *data2; int i, rc, mds; ENTRY; + OBD_ALLOC(data2, sizeof(*data2)); + if (data2 == NULL) + RETURN(-ENOMEM); + LASSERT(mea != NULL); for (i = 0; i < mea->mea_count; i++) { - memset(&data2, 0, sizeof(data2)); - data2.id1 = mea->mea_ids[i]; - mds = id_group(&data2.id1); + memset(data2, 0, sizeof(*data2)); + data2->id1 = mea->mea_ids[i]; + mds = id_group(&data2->id1); if (lmv->tgts[mds].ltd_exp == NULL) continue; rc = md_enqueue(lmv->tgts[mds].ltd_exp, locktype, it, - lockmode, &data2, lockh + i, lmm, lmmsize, + lockmode, data2, lockh + i, lmm, lmmsize, cb_compl, cb_blocking, cb_data); CDEBUG(D_OTHER, "take lock on slave "DLID4" -> %d/%d\n", - OLID4(&mea->mea_ids[i]), rc, it->d.lustre.it_status); + OLID4(&mea->mea_ids[i]), rc, LUSTRE_IT(it)->it_status); if (rc) GOTO(cleanup, rc); - if (it->d.lustre.it_data) { + if (LUSTRE_IT(it)->it_data) { struct ptlrpc_request *req; - req = (struct ptlrpc_request *) it->d.lustre.it_data; + req = (struct ptlrpc_request *) LUSTRE_IT(it)->it_data; ptlrpc_req_finished(req); } - if (it->d.lustre.it_status) - GOTO(cleanup, rc = it->d.lustre.it_status); + if (LUSTRE_IT(it)->it_status) + GOTO(cleanup, rc = LUSTRE_IT(it)->it_status); } - RETURN(0); + OBD_FREE(data2, sizeof(*data2)); + RETURN(0); cleanup: + OBD_FREE(data2, sizeof(*data2)); + /* drop all taken locks */ while (--i >= 0) { if (lockh[i].cookie) ldlm_lock_decref(lockh + i, lockmode); lockh[i].cookie = 0; } + return rc; +} + +int lmv_enqueue_remote(struct obd_export *exp, int lock_type, + struct lookup_intent *it, int lock_mode, + struct mdc_op_data *data, struct lustre_handle *lockh, + void *lmm, int lmmsize, ldlm_completion_callback cb_compl, + ldlm_blocking_callback cb_blocking, void *cb_data) +{ + struct ptlrpc_request *req = LUSTRE_IT(it)->it_data; + struct obd_device *obd = exp->exp_obd; + struct lmv_obd *lmv = &obd->u.lmv; + struct lustre_handle plock; + struct mdc_op_data rdata; + struct mds_body *body = NULL; + int rc = 0, pmode; + ENTRY; + + body = lustre_msg_buf(req->rq_repmsg, 1, sizeof(*body)); + LASSERT(body != NULL); + + if (!(body->valid & OBD_MD_MDS)) + RETURN(0); + + CDEBUG(D_OTHER, "ENQUEUE '%s' on "DLID4" -> "DLID4"\n", + LL_IT2STR(it), OLID4(&data->id1), OLID4(&body->id1)); + + /* we got LOOKUP lock, but we really need attrs */ + pmode = LUSTRE_IT(it)->it_lock_mode; + LASSERT(pmode != 0); + memcpy(&plock, lockh, sizeof(plock)); + LUSTRE_IT(it)->it_lock_mode = 0; + LUSTRE_IT(it)->it_data = NULL; + LASSERT((body->valid & OBD_MD_FID) != 0); + + memcpy(&rdata, data, sizeof(rdata)); + rdata.id1 = body->id1; + rdata.name = NULL; + rdata.namelen = 0; + + LUSTRE_IT(it)->it_disposition &= ~DISP_ENQ_COMPLETE; + ptlrpc_req_finished(req); + + rc = md_enqueue(lmv->tgts[id_group(&rdata.id1)].ltd_exp, + lock_type, it, lock_mode, &rdata, lockh, lmm, + lmmsize, cb_compl, cb_blocking, cb_data); + ldlm_lock_decref(&plock, pmode); RETURN(rc); } @@ -1041,6 +1117,10 @@ int lmv_enqueue(struct obd_export *exp, int lock_type, rc = md_enqueue(lmv->tgts[id_group(&data->id1)].ltd_exp, lock_type, it, lock_mode, data, lockh, lmm, lmmsize, cb_compl, cb_blocking, cb_data); + if (rc == 0 && it->it_op == IT_OPEN) + rc = lmv_enqueue_remote(exp, lock_type, it, lock_mode, + data, lockh, lmm, lmmsize, + cb_compl, cb_blocking, cb_data); RETURN(rc); } @@ -1054,7 +1134,6 @@ int lmv_getattr_lock(struct obd_export *exp, struct lustre_id *id, struct lustre_id rid = *id; struct mds_body *body; struct lmv_obj *obj; - __u64 old_valid; ENTRY; rc = lmv_check_connect(obd); @@ -1074,18 +1153,9 @@ repeat: CDEBUG(D_OTHER, "getattr_lock for %*s on "DLID4" -> "DLID4"\n", namelen, filename, OLID4(id), OLID4(&rid)); - old_valid = valid; - - /* - * here should be applied OBD_MD_FID to ->valid, because otherwise, - * mds_getattr_lock() will not fetch fid component of lustre_id and - * thus, next call to md_getattr_lock() will be performed to wrong mds. - */ - if (!(old_valid & OBD_MD_FID)) - valid |= OBD_MD_FID; - - rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp, - &rid, filename, namelen, valid, + rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp, + &rid, filename, namelen, + valid == OBD_MD_FLID ? valid : valid | OBD_MD_FID, ea_size, request); if (rc == 0) { /* @@ -1095,20 +1165,15 @@ repeat: */ body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body)); LASSERT(body != NULL); + LASSERT((body->valid & OBD_MD_FID) != 0 + || body->valid == OBD_MD_FLID); + if (body->valid & OBD_MD_MDS) { struct ptlrpc_request *req = NULL; rid = body->id1; CDEBUG(D_OTHER, "request attrs for "DLID4"\n", OLID4(&rid)); - /* - * turning OBD_MD_FID fetching off, as we already have - * full lustre_id and do need to fetch fid component - * again. This will help to make thing slightly faster. - */ - if (!(old_valid & OBD_MD_FID)) - valid &= ~OBD_MD_FID; - rc = md_getattr_lock(lmv->tgts[id_group(&rid)].ltd_exp, &rid, NULL, 1, valid, ea_size, &req); ptlrpc_req_finished(*request); @@ -1136,7 +1201,7 @@ int lmv_link(struct obd_export *exp, struct mdc_op_data *data, struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; struct lmv_obj *obj; - int rc; + int rc, mds; ENTRY; rc = lmv_check_connect(obd); @@ -1145,25 +1210,31 @@ int lmv_link(struct obd_export *exp, struct mdc_op_data *data, if (data->namelen != 0) { /* usual link request */ - obj = lmv_grab_obj(obd, &data->id1); + obj = lmv_grab_obj(obd, &data->id2); if (obj) { rc = raw_name2idx(obj->hashtype, obj->objcount, data->name, data->namelen); - data->id1 = obj->objs[rc].id; + data->id2 = obj->objs[rc].id; lmv_put_obj(obj); } + + mds = id_group(&data->id2); CDEBUG(D_OTHER,"link "DLID4":%*s to "DLID4"\n", OLID4(&data->id2), data->namelen, data->name, OLID4(&data->id1)); } else { + mds = id_group(&data->id1); + /* request from MDS to acquire i_links for inode by id1 */ CDEBUG(D_OTHER, "inc i_nlinks for "DLID4"\n", OLID4(&data->id1)); } - - rc = md_link(lmv->tgts[id_group(&data->id1)].ltd_exp, - data, request); + + CDEBUG(D_OTHER, "forward to MDS #%u ("DLID4")\n", + mds, OLID4(&data->id1)); + rc = md_link(lmv->tgts[mds].ltd_exp, data, request); + RETURN(rc); } @@ -1178,7 +1249,8 @@ int lmv_rename(struct obd_export *exp, struct mdc_op_data *data, ENTRY; CDEBUG(D_OTHER, "rename %*s in "DLID4" to %*s in "DLID4"\n", - oldlen, old, OLID4(&data->id1), newlen, new, OLID4(&data->id2)); + oldlen, old, OLID4(&data->id1), newlen, new, + OLID4(&data->id2)); rc = lmv_check_connect(obd); if (rc) @@ -1305,6 +1377,7 @@ int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data, body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body)); LASSERT(body != NULL); + LASSERT((body->valid & OBD_MD_FID) != 0); LASSERT(id_group(&body->id1) == id_group(&data->id1)); } } @@ -1368,10 +1441,10 @@ int lmv_dirobj_blocking_ast(struct ldlm_lock *lock, void lmv_remove_dots(struct page *page) { - char *kaddr = page_address(page); unsigned limit = PAGE_CACHE_SIZE; - unsigned offs, rec_len; + char *kaddr = page_address(page); struct ext2_dir_entry_2 *p; + unsigned offs, rec_len; for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) { p = (struct ext2_dir_entry_2 *)(kaddr + offs); @@ -1439,21 +1512,25 @@ int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data, struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; struct mea *mea = data->mea1; - struct mdc_op_data data2; + struct mdc_op_data *data2; int i, rc = 0; ENTRY; + OBD_ALLOC(data2, sizeof(*data2)); + if (data2 == NULL) + RETURN(-ENOMEM); + LASSERT(mea != NULL); for (i = 0; i < mea->mea_count; i++) { - memset(&data2, 0, sizeof(data2)); - data2.id1 = mea->mea_ids[i]; - data2.create_mode = MDS_MODE_DONT_LOCK | S_IFDIR; + memset(data2, 0, sizeof(*data2)); + data2->id1 = mea->mea_ids[i]; + data2->create_mode = MDS_MODE_DONT_LOCK | S_IFDIR; - if (lmv->tgts[id_group(&data2.id1)].ltd_exp == NULL) + if (lmv->tgts[id_group(&data2->id1)].ltd_exp == NULL) continue; - rc = md_unlink(lmv->tgts[id_group(&data2.id1)].ltd_exp, - &data2, req); + rc = md_unlink(lmv->tgts[id_group(&data2->id1)].ltd_exp, + data2, req); CDEBUG(D_OTHER, "unlink slave "DLID4" -> %d\n", OLID4(&mea->mea_ids[i]), rc); @@ -1465,14 +1542,15 @@ int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data, if (rc) RETURN(rc); } + OBD_FREE(data2, sizeof(*data2)); RETURN(rc); } int lmv_delete_inode(struct obd_export *exp, struct lustre_id *id) { - LASSERT(exp && id); - ENTRY; + + LASSERT(exp && id); if (lmv_delete_obj(exp, id)) { CDEBUG(D_OTHER, "lmv object "DLID4" is destroyed.\n", OLID4(id)); @@ -1521,7 +1599,7 @@ int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data, } struct obd_device *lmv_get_real_obd(struct obd_export *exp, - char *name, int len) + struct lustre_id *id) { struct obd_device *obd = exp->exp_obd; struct lmv_obd *lmv = &obd->u.lmv; @@ -1531,7 +1609,7 @@ struct obd_device *lmv_get_real_obd(struct obd_export *exp, rc = lmv_check_connect(obd); if (rc) RETURN(ERR_PTR(rc)); - obd = lmv->tgts[0].ltd_exp->exp_obd; + obd = lmv->tgts[id_group(id)].ltd_exp->exp_obd; EXIT; return obd; @@ -1576,6 +1654,7 @@ int lmv_init_ea_size(struct obd_export *exp, int easize, } int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa, + void *acl, int acl_size, struct lov_stripe_md **ea, struct obd_trans_info *oti) { struct obd_device *obd = exp->exp_obd; @@ -1588,8 +1667,8 @@ int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa, LASSERT(ea == NULL); LASSERT(oa->o_mds < lmv->desc.ld_tgt_count); - rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, - oa, &obj_mdp, oti); + rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, oa, + acl, acl_size, &obj_mdp, oti); RETURN(rc); } @@ -1609,6 +1688,7 @@ int lmv_getready(struct obd_export *exp) * values for "master" object, as it will be used. */ int lmv_obd_create(struct obd_export *exp, struct obdo *oa, + void *acl, int acl_size, struct lov_stripe_md **ea, struct obd_trans_info *oti) { struct obd_device *obd = exp->exp_obd; @@ -1625,12 +1705,15 @@ int lmv_obd_create(struct obd_export *exp, struct obdo *oa, LASSERT(oa != NULL); if (ea == NULL) { - rc = lmv_obd_create_single(exp, oa, NULL, oti); + rc = lmv_obd_create_single(exp, oa, acl, acl_size, NULL, oti); if (rc) CERROR("Can't create object, rc = %d\n", rc); RETURN(rc); } + /* acl is only suppied when mds create single remote obj */ + LASSERT(acl == NULL && acl_size == 0); + if (*ea == NULL) { rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea); if (rc < 0) { @@ -1683,7 +1766,8 @@ int lmv_obd_create(struct obd_export *exp, struct obdo *oa, oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID; - rc = obd_create(lmv->tgts[c].ltd_exp, oa, &obj_mdp, oti); + rc = obd_create(lmv->tgts[c].ltd_exp, oa, NULL, 0, + &obj_mdp, oti); if (rc) { CERROR("obd_create() failed on MDT target %d, " "error %d\n", c, rc); @@ -1791,6 +1875,26 @@ static int lmv_get_info(struct obd_export *exp, __u32 keylen, struct lmv_desc *desc_ret = val; *desc_ret = lmv->desc; RETURN(0); + } else if (keylen == strlen("remote_flag") && + !strcmp(key, "remote_flag")) { + struct lmv_tgt_desc *tgts; + int i; + + LASSERT(*vallen == sizeof(__u32)); + for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; + i++, tgts++) { + + /* all tgts should be connected when this get called. */ + if (!tgts || !tgts->ltd_exp) { + CERROR("target not setup?\n"); + continue; + } + + if (!obd_get_info(tgts->ltd_exp, keylen, key, + vallen, val)) + RETURN(0); + } + RETURN(-EINVAL); } CDEBUG(D_IOCTL, "invalid key\n"); @@ -1800,8 +1904,9 @@ static int lmv_get_info(struct obd_export *exp, __u32 keylen, int lmv_set_info(struct obd_export *exp, obd_count keylen, void *key, obd_count vallen, void *val) { - struct obd_device *obd; - struct lmv_obd *lmv; + struct lmv_tgt_desc *tgt; + struct obd_device *obd; + struct lmv_obd *lmv; ENTRY; obd = class_exp2obd(exp); @@ -1817,7 +1922,62 @@ int lmv_set_info(struct obd_export *exp, obd_count keylen, lmv_set_timeouts(obd); RETURN(0); } - + + /* maybe this could be default */ + if ((keylen == strlen("sec") && strcmp(key, "sec") == 0) || + (keylen == strlen("nllu") && strcmp(key, "nllu") == 0)) { + struct obd_export *exp; + int rc = 0, err, i; + + spin_lock(&lmv->lmv_lock); + for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; + i++, tgt++) { + exp = tgt->ltd_exp; + /* during setup time the connections to mdc might + * haven't been established. + */ + if (exp == NULL) { + struct obd_device *tgt_obd; + + tgt_obd = class_find_client_obd(&tgt->uuid, + LUSTRE_MDC_NAME, + &obd->obd_uuid); + if (!tgt_obd) { + CERROR("can't set info %s, " + "device %s not attached?\n", + (char *) key, tgt->uuid.uuid); + rc = -EINVAL; + continue; + } + exp = tgt_obd->obd_self_export; + } + + err = obd_set_info(exp, keylen, key, vallen, val); + if (!rc) + rc = err; + } + spin_unlock(&lmv->lmv_lock); + + RETURN(rc); + } + + if ((keylen == strlen("flush_cred") && + strcmp(key, "flush_cred") == 0)) { + int rc = 0, i; + + for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; + i++, tgt++) { + if (!tgt->ltd_exp) + continue; + rc = obd_set_info(tgt->ltd_exp, + keylen, key, vallen, val); + if (rc) + RETURN(rc); + } + + RETURN(0); + } + RETURN(-EINVAL); } @@ -1853,6 +2013,10 @@ int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, lsmp = (struct mea *)lsm; meap = (struct mea *)*lmmp; + if (lsmp->mea_magic != MEA_MAGIC_LAST_CHAR && + lsmp->mea_magic != MEA_MAGIC_ALL_CHARS) + RETURN(-EINVAL); + meap->mea_magic = cpu_to_le32(lsmp->mea_magic); meap->mea_count = cpu_to_le32(lsmp->mea_count); meap->mea_master = cpu_to_le32(lsmp->mea_master); @@ -1865,45 +2029,69 @@ int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp, RETURN(mea_size); } -int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt, - struct lov_mds_md *disk_src, int mdsize) +int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp, + struct lov_mds_md *lmm, int lmm_size) { struct obd_device *obd = class_exp2obd(exp); - struct mea **tmea = (struct mea **)mem_tgt; - struct mea *mea = (struct mea *)disk_src; + struct mea **tmea = (struct mea **)lsmp; + struct mea *mea = (struct mea *)lmm; struct lmv_obd *lmv = &obd->u.lmv; - int mea_size, i; + int mea_size, i, rc = 0; + __u32 magic; ENTRY; - mea_size = sizeof(struct lustre_id) * + mea_size = sizeof(struct lustre_id) * lmv->desc.ld_tgt_count + sizeof(struct mea); - if (mem_tgt == NULL) + + if (lsmp == NULL) return mea_size; - if (*mem_tgt != NULL && disk_src == NULL) { + if (*lsmp != NULL && lmm == NULL) { OBD_FREE(*tmea, mea_size); RETURN(0); } - LASSERT(mea_size == mdsize); + LASSERT(mea_size == lmm_size); OBD_ALLOC(*tmea, mea_size); if (*tmea == NULL) RETURN(-ENOMEM); - if (!disk_src) + if (!lmm) RETURN(mea_size); - (*tmea)->mea_magic = le32_to_cpu(mea->mea_magic); + if (mea->mea_magic == MEA_MAGIC_LAST_CHAR || + mea->mea_magic == MEA_MAGIC_ALL_CHARS) + { + magic = le32_to_cpu(mea->mea_magic); + } else { + struct mea_old *old = (struct mea_old *)lmm; + + mea_size = sizeof(struct lustre_id) * old->mea_count + + sizeof(struct mea_old); + + if (old->mea_count > 256 || old->mea_master > 256 || + lmm_size < mea_size || old->mea_master > old->mea_count) { + CWARN("bad MEA: count %u, master %u, size %u\n", + old->mea_count, old->mea_master, mea_size); + GOTO(out_free_mea, rc = -EINVAL); + } + magic = MEA_MAGIC_LAST_CHAR; + } + + (*tmea)->mea_magic = magic; (*tmea)->mea_count = le32_to_cpu(mea->mea_count); (*tmea)->mea_master = le32_to_cpu(mea->mea_master); - for (i = 0; i < lmv->desc.ld_tgt_count; i++) { + for (i = 0; i < (*tmea)->mea_count; i++) { (*tmea)->mea_ids[i] = mea->mea_ids[i]; id_le_to_cpu(&(*tmea)->mea_ids[i]); } - RETURN(mea_size); + +out_free_mea: + OBD_FREE(*tmea, mea_size); + return rc; } int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa, @@ -1929,6 +2117,29 @@ int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa, RETURN(err); } +static int lmv_cancel_unused(struct obd_export *exp, + struct lov_stripe_md *lsm, + int flags, void *opaque) +{ + struct obd_device *obd = exp->exp_obd; + struct lmv_obd *lmv = &obd->u.lmv; + int rc = 0, err, i; + ENTRY; + + LASSERT(lsm == NULL); + + for (i = 0; i < lmv->desc.ld_tgt_count; i++) { + if (!lmv->tgts[i].ltd_exp || !lmv->tgts[i].active) + continue; + + err = obd_cancel_unused(lmv->tgts[i].ltd_exp, + NULL, flags, opaque); + if (!rc) + rc = err; + } + RETURN(rc); +} + struct obd_ops lmv_obd_ops = { .o_owner = THIS_MODULE, .o_attach = lmv_attach, @@ -1950,6 +2161,7 @@ struct obd_ops lmv_obd_ops = { .o_notify = lmv_notify, .o_iocontrol = lmv_iocontrol, .o_getready = lmv_getready, + .o_cancel_unused = lmv_cancel_unused, }; struct md_ops lmv_md_ops = {