X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Fmds%2Fmds_open.c;h=4dbc8176a93d8c4c2ac89ab2577588450b7e1d12;hp=457bbcf1919ebfab536a435e5bd9525d455c546d;hb=e44e9b278432a1df83482b1cd83b2081fabe94dc;hpb=efc75006b820c9b8e186c7650fc24edd5d0509af diff --git a/lustre/mds/mds_open.c b/lustre/mds/mds_open.c index 457bbcf..4dbc817 100644 --- a/lustre/mds/mds_open.c +++ b/lustre/mds/mds_open.c @@ -28,6 +28,7 @@ #endif #define DEBUG_SUBSYSTEM S_MDS +#include #include #include #include @@ -54,7 +55,7 @@ * mds_mfd_close - for force closing files when a client dies */ -/* +/* * MDS file data handling: file data holds a handle for a file opened * by a client. */ @@ -132,7 +133,7 @@ static void mds_free_filterdata(struct inode *inode) iput(inode); } -/* Write access to a file: executors cause a negative count, +/* Write access to a file: executors cause a negative count, * writers a positive count. The semaphore is needed to perform * a check for the sign and then increment or decrement atomically. * @@ -243,7 +244,7 @@ static struct mds_file_data *mds_dentry_open(struct dentry *dentry, struct mds_body *body; int error; ENTRY; - + mfd = mds_mfd_new(); if (mfd == NULL) { CERROR("mds: out of memory\n"); @@ -303,13 +304,15 @@ static void mds_objids_from_lmm(obd_id *ids, struct lov_mds_md *lmm, static int mds_create_objects(struct ptlrpc_request *req, int offset, struct mds_update_record *rec, struct mds_obd *mds, struct obd_device *obd, - struct inode *inode, void **handle, obd_id **ids) + struct dentry *dchild, void **handle, + obd_id **ids) { struct obdo *oa; struct obd_trans_info oti = { 0 }; struct mds_body *body; struct lov_stripe_md *lsm = NULL; struct lov_mds_md *lmm = NULL; + struct inode *inode = dchild->d_inode; void *lmm_buf; int rc, lmm_bufsize, lmm_size; ENTRY; @@ -339,7 +342,8 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset, } /* replay case */ - if (rec->ur_fid2->id) { + if(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) { + LASSERT (rec->ur_fid2->id); body->valid |= OBD_MD_FLBLKSZ | OBD_MD_FLEASIZE; lmm_size = rec->ur_eadatalen; lmm = rec->ur_eadata; @@ -358,43 +362,59 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset, RETURN(0); } + if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_ALLOC_OBDO)) + GOTO(out_ids, rc = -ENOMEM); + oa = obdo_alloc(); if (oa == NULL) GOTO(out_ids, rc = -ENOMEM); oa->o_mode = S_IFREG | 0600; oa->o_id = inode->i_ino; + oa->o_gr = FILTER_GROUP_FIRST_MDS + mds->mds_num; oa->o_generation = inode->i_generation; oa->o_uid = 0; /* must have 0 uid / gid on OST */ oa->o_gid = 0; oa->o_valid = OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FLTYPE | - OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID; + OBD_MD_FLMODE | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLGROUP; oa->o_size = 0; obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|OBD_MD_FLMTIME| OBD_MD_FLCTIME); - /* check if things like lstripe/lfs stripe are sending us the ea */ - if (rec->ur_flags & MDS_OPEN_HAS_EA) { - rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, mds->mds_osc_exp, + if (!(rec->ur_flags & MDS_OPEN_HAS_OBJS)) { + /* check if things like lfs setstripe are sending us the ea */ + if (rec->ur_flags & MDS_OPEN_HAS_EA) { + rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, + mds->mds_osc_exp, + 0, &lsm, rec->ur_eadata); + if (rc) + GOTO(out_oa, rc); + } + LASSERT(oa->o_gr >= FILTER_GROUP_FIRST_MDS); + rc = obd_create(mds->mds_osc_exp, oa, &lsm, &oti); + if (rc) { + int level = D_ERROR; + if (rc == -ENOSPC) + level = D_INODE; + CDEBUG(level, "error creating objects for " + "inode %lu: rc = %d\n", + inode->i_ino, rc); + if (rc > 0) { + CERROR("obd_create returned invalid " + "rc %d\n", rc); + rc = -EIO; + } + GOTO(out_oa, rc); + } + } else { + rc = obd_iocontrol(OBD_IOC_LOV_SETEA, mds->mds_osc_exp, 0, &lsm, rec->ur_eadata); - if (rc) + if (rc) { GOTO(out_oa, rc); - } - - rc = obd_create(mds->mds_osc_exp, oa, &lsm, &oti); - if (rc) { - int level = D_ERROR; - if (rc == -ENOSPC) - level = D_INODE; - CDEBUG(level, "error creating objects for inode %lu: rc = %d\n", - inode->i_ino, rc); - if (rc > 0) { - CERROR("obd_create returned invalid rc %d\n", rc); - rc = -EIO; } - GOTO(out_oa, rc); + lsm->lsm_object_id = oa->o_id; + lsm->lsm_object_gr = oa->o_gr; } - if (inode->i_size) { oa->o_size = inode->i_size; obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME| @@ -445,7 +465,6 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, struct ptlrpc_request *req, struct lustre_handle *child_lockh) { - struct ptlrpc_request *oldreq = req->rq_export->exp_outstanding_reply; struct mds_export_data *med = &req->rq_export->exp_mds_data; struct mds_client_data *mcd = med->med_mcd; struct mds_obd *mds = mds_req2mds(req); @@ -494,8 +513,8 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, /* get lock (write for O_CREAT, read otherwise) */ - mds_pack_inode2fid(&body->fid1, child->d_inode); - mds_pack_inode2body(body, child->d_inode); + mds_pack_inode2fid(obd, &body->fid1, child->d_inode); + mds_pack_inode2body(obd, body, child->d_inode); if (S_ISREG(child->d_inode->i_mode)) { rc = mds_pack_md(obd, req->rq_repmsg, 2, body, child->d_inode, 1); @@ -543,10 +562,11 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, mfd = NULL; } - if (oldreq != NULL) { - /* if we're not recovering, it had better be found */ - LASSERT(mfd != NULL); - } else if (mfd == NULL) { + /* #warning "XXX fixme" bug 2991 */ + /* Here it used to LASSERT(mfd) if exp_outstanding_reply != NULL. + * Now that exp_outstanding_reply is a list, it's just using mfd != NULL + * to detect a re-open */ + if (mfd == NULL) { mntget(mds->mds_vfsmnt); CERROR("Re-opened file \n"); mfd = mds_dentry_open(child, mds->mds_vfsmnt, @@ -556,6 +576,10 @@ static void reconstruct_open(struct mds_update_record *rec, int offset, GOTO(out_dput, req->rq_status = -ENOMEM); } put_child = 0; + } else { + body->handle.cookie = mfd->mfd_handle.h_cookie; + CDEBUG(D_INODE, "resend mfd %p, cookie "LPX64"\n", mfd, + mfd->mfd_handle.h_cookie); } out_dput: @@ -588,13 +612,15 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild, struct obd_device *obd = req->rq_export->exp_obd; struct mds_file_data *mfd = NULL; obd_id *ids = NULL; /* object IDs created */ + unsigned mode; int rc = 0; ENTRY; /* atomically create objects if necessary */ down(&dchild->d_inode->i_sem); - if (S_ISREG(dchild->d_inode->i_mode) && - !(body->valid & OBD_MD_FLEASIZE)) { + mode = dchild->d_inode->i_mode; + if ((S_ISREG(mode) && !(body->valid & OBD_MD_FLEASIZE)) || + (S_ISDIR(mode) && !(body->valid & OBD_MD_FLDIREA))) { rc = mds_pack_md(obd, req->rq_repmsg, 2, body, dchild->d_inode, 0); if (rc) { @@ -605,7 +631,7 @@ static int mds_finish_open(struct ptlrpc_request *req, struct dentry *dchild, if (rec != NULL) { /* no EA: create objects */ rc = mds_create_objects(req, 2, rec, mds, obd, - dchild->d_inode, handle, &ids); + dchild, handle, &ids); if (rc) { CERROR("mds_create_objects: rc = %d\n", rc); up(&dchild->d_inode->i_sem); @@ -661,8 +687,8 @@ static int mds_open_by_fid(struct ptlrpc_request *req, struct ll_fid *fid, if (dchild->d_inode != NULL) { up(&pending_dir->i_sem); mds_inode_set_orphan(dchild->d_inode); - mds_pack_inode2fid(&body->fid1, dchild->d_inode); - mds_pack_inode2body(body, dchild->d_inode); + mds_pack_inode2fid(req2obd(req), &body->fid1, dchild->d_inode); + mds_pack_inode2body(req2obd(req), body, dchild->d_inode); intent_set_disposition(rep, DISP_LOOKUP_EXECD); intent_set_disposition(rep, DISP_LOOKUP_POS); CWARN("Orphan %s found and opened in PENDING directory\n", @@ -678,8 +704,8 @@ static int mds_open_by_fid(struct ptlrpc_request *req, struct ll_fid *fid, if (IS_ERR(dchild)) RETURN(PTR_ERR(dchild)); - mds_pack_inode2fid(&body->fid1, dchild->d_inode); - mds_pack_inode2body(body, dchild->d_inode); + mds_pack_inode2fid(req2obd(req), &body->fid1, dchild->d_inode); + mds_pack_inode2body(req2obd(req), body, dchild->d_inode); intent_set_disposition(rep, DISP_LOOKUP_EXECD); intent_set_disposition(rep, DISP_LOOKUP_POS); @@ -697,7 +723,7 @@ int mds_pin(struct ptlrpc_request *req) { struct obd_device *obd = req->rq_export->exp_obd; struct mds_body *request_body, *reply_body; - struct obd_run_ctxt saved; + struct lvfs_run_ctxt saved; int rc, size = sizeof(*reply_body); ENTRY; @@ -708,10 +734,10 @@ int mds_pin(struct ptlrpc_request *req) RETURN(rc); reply_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply_body)); - push_ctxt(&saved, &obd->obd_ctxt, NULL); + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); rc = mds_open_by_fid(req, &request_body->fid1, reply_body, request_body->flags, NULL, NULL); - pop_ctxt(&saved, &obd->obd_ctxt, NULL); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); RETURN(rc); } @@ -730,16 +756,31 @@ int mds_lock_new_child(struct obd_device *obd, struct inode *inode, if (child_lockh == NULL) child_lockh = &lockh; - rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL, - child_res_id, LDLM_PLAIN, NULL, 0, - LCK_EX, &lock_flags, ldlm_completion_ast, - mds_blocking_ast, NULL, child_lockh); + rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, child_res_id, + LDLM_PLAIN, NULL, LCK_EX, &lock_flags, + mds_blocking_ast, ldlm_completion_ast, NULL, NULL, + NULL, 0, NULL, child_lockh); if (rc != ELDLM_OK) CERROR("ldlm_cli_enqueue: %d\n", rc); else if (child_lockh == &lockh) ldlm_lock_decref(child_lockh, LCK_EX); - return rc; + RETURN(rc); +} + +static int is_mount_object(struct dentry *dparent) +{ + struct dentry *dchild; + + if (!(dparent->d_inode->i_mode & S_ISUID)) + return 0; + + dchild = lookup_one_len(".mntinfo", dparent, strlen(".mntinfo")); + if (IS_ERR(dchild) || dchild == NULL) + return 0; + + dput(dchild); + return 1; } int mds_open(struct mds_update_record *rec, int offset, @@ -752,13 +793,18 @@ int mds_open(struct mds_update_record *rec, int offset, struct mds_body *body = NULL; struct dentry *dchild = NULL, *dparent = NULL; struct mds_export_data *med; - struct lustre_handle parent_lockh; + struct lustre_handle parent_lockh[2]; int rc = 0, cleanup_phase = 0, acc_mode, created = 0; int parent_mode = LCK_PR; void *handle = NULL; struct dentry_params dp; + struct mea *mea = NULL; + int mea_size, update_mode; ENTRY; + parent_lockh[0].cookie = 0; + parent_lockh[1].cookie = 0; + if (offset == 2) { /* intent */ rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep)); body = lustre_msg_buf(req->rq_repmsg, 1, sizeof (*body)); @@ -774,7 +820,12 @@ int mds_open(struct mds_update_record *rec, int offset, /* Step 0: If we are passed a fid, then we assume the client already * opened this file and is only replaying the RPC, so we open the * inode by fid (at some large expense in security). */ - if (rec->ur_fid2->id) { + if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) { + DEBUG_REQ(D_HA, req, "open replay, disp: "LPX64"\n", + rep->lock_policy_res1); + + LASSERT(rec->ur_fid2->id); + rc = mds_open_by_fid(req, rec->ur_fid2, body, rec->ur_flags, rec, rep); if (rc != -ENOENT) @@ -782,7 +833,10 @@ int mds_open(struct mds_update_record *rec, int offset, /* We didn't find the correct inode on disk either, so we * need to re-create it via a regular replay. */ LASSERT(rec->ur_flags & MDS_OPEN_CREAT); + } else { + LASSERT(!rec->ur_fid2->id); } + LASSERT(offset == 2); /* If we got here, we must be called via intent */ med = &req->rq_export->exp_mds_data; @@ -794,11 +848,32 @@ int mds_open(struct mds_update_record *rec, int offset, acc_mode = accmode(rec->ur_flags); /* Step 1: Find and lock the parent */ - if (rec->ur_flags & O_CREAT) + if (rec->ur_flags & O_CREAT) { + /* XXX Well, in fact we only need this lock mode change if + in addition to O_CREAT, the file does not exist. + But we do not know if it exists or not yet */ parent_mode = LCK_PW; + } + + if (rec->ur_namelen == 1) { + /* client (LMV) wants to open the file by fid */ + CDEBUG(D_OTHER, "OPEN by fid %u/%u/%u\n", + (unsigned) rec->ur_fid1->mds, + (unsigned) rec->ur_fid1->id, + (unsigned) rec->ur_fid1->generation); + dchild = mds_fid2dentry(mds, rec->ur_fid1, NULL); + if (IS_ERR(dchild)) { + rc = PTR_ERR(dparent); + CERROR("child lookup by a fid error %d\n", rc); + GOTO(cleanup, rc); + } + goto got_child; + } + dparent = mds_fid2locked_dentry(obd, rec->ur_fid1, NULL, parent_mode, - &parent_lockh, rec->ur_name, - rec->ur_namelen - 1); + parent_lockh, &update_mode, rec->ur_name, + rec->ur_namelen - 1, + MDS_INODELOCK_UPDATE); if (IS_ERR(dparent)) { rc = PTR_ERR(dparent); CERROR("parent lookup error %d\n", rc); @@ -808,6 +883,23 @@ int mds_open(struct mds_update_record *rec, int offset, cleanup_phase = 1; /* parent dentry and lock */ + /* try to retrieve MEA data for this dir */ + rc = mds_get_lmv_attr(obd, dparent->d_inode, &mea, &mea_size); + if (rc) + GOTO(cleanup, rc); + + if (mea != NULL) { + /* dir is already splitted, check is requested filename + * should live at this MDS or at another one */ + int i; + i = mea_name2idx(mea, rec->ur_name, rec->ur_namelen - 1); + if (mea->mea_master != i) { + CERROR("inapropriate MDS(%d) for %s. should be %d\n", + mea->mea_master, rec->ur_name, i); + GOTO(cleanup, rc = -ERESTART); + } + } + /* Step 2: Lookup the child */ dchild = ll_lookup_one_len(rec->ur_name, dparent, rec->ur_namelen - 1); if (IS_ERR(dchild)) { @@ -816,9 +908,45 @@ int mds_open(struct mds_update_record *rec, int offset, GOTO(cleanup, rc); } +got_child: cleanup_phase = 2; /* child dentry */ intent_set_disposition(rep, DISP_LOOKUP_EXECD); + + if (dchild->d_flags & DCACHE_CROSS_REF) { + struct ldlm_res_id res_id = { . name = {0} }; + ldlm_policy_data_t policy; + int flags = 0; + CDEBUG(D_OTHER, "cross reference: %lu/%lu/%lu\n", + (unsigned long) dchild->d_mdsnum, + (unsigned long) dchild->d_inum, + (unsigned long) dchild->d_generation); + body->valid |= OBD_MD_FLID | OBD_MD_MDS; + body->fid1.id = dchild->d_inum; + body->fid1.mds = dchild->d_mdsnum; + body->fid1.generation = dchild->d_generation; + intent_set_disposition(rep, DISP_LOOKUP_POS); + res_id.name[0] = dchild->d_inum; + res_id.name[1] = dchild->d_generation; + policy.l_inodebits.bits = MDS_INODELOCK_LOOKUP; + rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, + res_id, LDLM_IBITS, &policy, + LCK_PR, &flags, + mds_blocking_ast, + ldlm_completion_ast, NULL, NULL, + NULL, 0, NULL, child_lockh); +#ifdef S_PDIROPS + if (parent_lockh[1].cookie != 0) + ldlm_lock_decref(parent_lockh + 1, update_mode); +#endif + ldlm_lock_decref(parent_lockh, parent_mode); + if (mea) + OBD_FREE(mea, mea_size); + l_dput(dchild); + l_dput(dparent); + RETURN(rc); + } + if (dchild->d_inode) intent_set_disposition(rep, DISP_LOOKUP_POS); else @@ -830,6 +958,16 @@ int mds_open(struct mds_update_record *rec, int offset, struct iattr iattr; struct inode *inode; + if ((rc = mds_try_to_split_dir(obd, dparent, &mea, 0))) { + if (rc > 0) { + /* dir got splitted */ + GOTO(cleanup, rc = -ERESTART); + } else { + /* error happened during spitting */ + GOTO(cleanup, rc); + } + } + if (!(rec->ur_flags & MDS_OPEN_CREAT)) { /* It's negative and we weren't supposed to create it */ GOTO(cleanup, rc = -ENOENT); @@ -865,15 +1003,15 @@ int mds_open(struct mds_update_record *rec, int offset, } created = 1; - LTIME_S(iattr.ia_atime) = rec->ur_time; - LTIME_S(iattr.ia_ctime) = rec->ur_time; - LTIME_S(iattr.ia_mtime) = rec->ur_time; + LTIME_S(iattr.ia_atime) = LTIME_S(rec->ur_time); + LTIME_S(iattr.ia_ctime) = LTIME_S(rec->ur_time); + LTIME_S(iattr.ia_mtime) = LTIME_S(rec->ur_time); - iattr.ia_uid = rec->ur_fsuid; + iattr.ia_uid = rec->_ur_fsuid; if (dparent->d_inode->i_mode & S_ISGID) iattr.ia_gid = dparent->d_inode->i_gid; else - iattr.ia_gid = rec->ur_fsgid; + iattr.ia_gid = rec->_ur_fsgid; iattr.ia_valid = ATTR_UID | ATTR_GID | ATTR_ATIME | ATTR_MTIME | ATTR_CTIME; @@ -888,13 +1026,13 @@ int mds_open(struct mds_update_record *rec, int offset, if (rc) CERROR("error on parent setattr: rc = %d\n", rc); - acc_mode = 0; /* Don't check for permissions */ + acc_mode = 0; /* Don't check for permissions */ } LASSERT(!mds_inode_is_orphan(dchild->d_inode)); - mds_pack_inode2fid(&body->fid1, dchild->d_inode); - mds_pack_inode2body(body, dchild->d_inode); + mds_pack_inode2fid(obd, &body->fid1, dchild->d_inode); + mds_pack_inode2body(obd, body, dchild->d_inode); if (S_ISREG(dchild->d_inode->i_mode)) { /* Check permissions etc */ @@ -929,6 +1067,41 @@ int mds_open(struct mds_update_record *rec, int offset, !S_ISDIR(dchild->d_inode->i_mode)) GOTO(cleanup, rc = -ENOTDIR); + if (S_ISDIR(dchild->d_inode->i_mode)) { + if (rec->ur_flags & MDS_OPEN_CREAT || + rec->ur_flags & FMODE_WRITE) { + /*we are trying to create or write a exist dir*/ + GOTO(cleanup, rc = -EISDIR); + } + if (ll_permission(dchild->d_inode, acc_mode, NULL)) { + GOTO(cleanup, rc = -EACCES); + } + if (is_mount_object(dchild)) { + CERROR("Found possible GNS mount object %*s; not " + "opening.\n", dchild->d_name.len, + dchild->d_name.name); + GOTO(cleanup, rc = 0); // success, but don't really open + } + } + + if (rc == 0) { + struct ldlm_res_id res_id = { . name = {0} }; + ldlm_policy_data_t policy; + int flags = 0; + res_id.name[0] = dchild->d_inode->i_ino; + res_id.name[1] = dchild->d_inode->i_generation; + policy.l_inodebits.bits = MDS_INODELOCK_LOOKUP | + MDS_INODELOCK_UPDATE; + rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, + res_id, LDLM_IBITS, &policy, + LCK_PR, &flags, + mds_blocking_ast, + ldlm_completion_ast, NULL, NULL, + NULL, 0, NULL, child_lockh); + if (rc == 0) + cleanup_phase = 3; + } + /* Step 5: mds_open it */ rc = mds_finish_open(req, dchild, body, rec->ur_flags, &handle, rec, rep); @@ -939,6 +1112,9 @@ int mds_open(struct mds_update_record *rec, int offset, req, rc, rep ? rep->lock_policy_res1 : 0); switch (cleanup_phase) { + case 3: + if (rc) + ldlm_lock_decref(child_lockh, LCK_PR); case 2: if (rc && created) { int err = vfs_unlink(dparent->d_inode, dchild); @@ -956,13 +1132,21 @@ int mds_open(struct mds_update_record *rec, int offset, break; l_dput(dparent); +#ifdef S_PDIROPS + if (parent_lockh[1].cookie != 0) + ldlm_lock_decref(parent_lockh + 1, update_mode); +#endif if (rc) - ldlm_lock_decref(&parent_lockh, parent_mode); + ldlm_lock_decref(parent_lockh, parent_mode); else - ldlm_put_lock_into_req(req, &parent_lockh, parent_mode); + ptlrpc_save_lock (req, parent_lockh, parent_mode); } if (rc == 0) atomic_inc(&mds->mds_open_count); + if (mea) + OBD_FREE(mea, mea_size); + if ((cleanup_phase != 3) && !rc) + rc = ENOLCK; RETURN(rc); } @@ -985,16 +1169,17 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd, struct mds_obd *mds = &obd->u.mds; struct inode *pending_dir = mds->mds_pending_dir->d_inode; void *handle = NULL; - struct mds_body *request_body = NULL, *reply_body; + struct mds_body *request_body = NULL, *reply_body = NULL; struct dentry_params dp; + struct iattr iattr = { 0 }; ENTRY; - if (req != NULL) { + if (req && req->rq_reqmsg != NULL) request_body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*request_body)); + if (req && req->rq_repmsg != NULL) reply_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply_body)); - } fidlen = ll_fid2str(fidname, inode->i_ino, inode->i_generation); @@ -1010,9 +1195,17 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd, } if (last_orphan && unlink_orphan) { + struct lov_mds_md *lmm = NULL; + int stripe_count = 0; LASSERT(rc == 0); /* mds_put_write_access must have succeeded */ - CWARN("destroying orphan object %s\n", fidname); + if (obd->obd_recovering) { + CDEBUG(D_HA, "not remove orphan %s until recovery" + " is over\n", fidname); + GOTO(out, rc); + } + + CDEBUG(D_HA, "destroying orphan object %s\n", fidname); /* Sadly, there is no easy way to save pending_child from * mds_reint_unlink() into mfd, so we need to re-lookup, @@ -1027,22 +1220,28 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd, LASSERT(pending_child->d_inode != NULL); cleanup_phase = 2; /* dput(pending_child) when finished */ - handle = fsfilt_start(obd, pending_dir, FSFILT_OP_UNLINK_LOG, - NULL); + if (req != NULL && req->rq_repmsg != NULL) { + lmm = lustre_msg_buf(req->rq_repmsg, 1, 0); + stripe_count = le32_to_cpu(lmm->lmm_stripe_count); + } + + handle = fsfilt_start_log(obd, pending_dir, FSFILT_OP_UNLINK, + NULL, stripe_count); if (IS_ERR(handle)) { rc = PTR_ERR(handle); handle = NULL; GOTO(cleanup, rc); } -#ifdef ENABLE_ORPHANS - if (req != NULL && + if (req != NULL && req->rq_repmsg != NULL && (reply_body->valid & OBD_MD_FLEASIZE) && - mds_log_op_unlink(obd, pending_child->d_inode, - req->rq_repmsg, 1) > 0) { + mds_log_op_unlink(obd, pending_child->d_inode, lmm, + req->rq_repmsg->buflens[1], + lustre_msg_buf(req->rq_repmsg, 2, 0), + req->rq_repmsg->buflens[2]) > 0) { reply_body->valid |= OBD_MD_FLCOOKIE; } -#endif + pending_child->d_fsdata = (void *) &dp; dp.p_inum = 0; dp.p_ptr = req; @@ -1052,32 +1251,65 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd, rc = vfs_unlink(pending_dir, pending_child); if (rc) CERROR("error unlinking orphan %s: rc %d\n",fidname,rc); - } else if (mfd->mfd_mode & FMODE_WRITE && rc == 0) { + + goto out; /* Don't bother updating attrs on unlinked inode */ + } + + if (request_body != NULL && mfd->mfd_mode & FMODE_WRITE && rc == 0) { /* Update the on-disk attributes if this was the last write * close, and all information was provided (i.e., rc == 0) * * XXX this should probably be abstracted with mds_reint_setattr */ + #if 0 - struct iattr iattr; + if (request_body->valid & OBD_MD_FLMTIME && + LTIME_S(request_body->mtime) > LTIME_S(inode->i_mtime)) { + LTIME_S(iattr.ia_mtime) = LTIME_S(request_body->mtime); + iattr.ia_valid |= ATTR_MTIME; + } + if (request_body->valid & OBD_MD_FLCTIME && + LTIME_S(request_body->ctime) > LTIME_S(inode->i_ctime)) { + LTIME_S(iattr.ia_ctime) = LTIME_S(request_body->ctime); + iattr.ia_valid |= ATTR_CTIME; + } /* XXX can't set block count with fsfilt_setattr (!) */ - iattr.ia_valid = ATTR_CTIME | ATTR_ATIME | - ATTR_MTIME | ATTR_SIZE; - iattr.ia_atime = request_body->atime; - iattr.ia_ctime = request_body->ctime; - iattr.ia_mtime = request_body->mtime; - iattr.ia_size = request_body->size; - /* iattr.ia_blocks = request_body->blocks */ + if (request_body->valid & OBD_MD_FLSIZE) { + iattr.ia_valid |= ATTR_SIZE; + iattr.ia_size = request_body->size; + } + /* if (request_body->valid & OBD_MD_FLBLOCKS) { + iattr.ia_valid |= ATTR_BLOCKS; + iattr.ia_blocks = request_body->blocks + } */ +#endif + } + + if (request_body != NULL && request_body->valid & OBD_MD_FLATIME) { + /* Only start a transaction to write out only the atime if + * it is more out-of-date than the specified limit. If we + * are already going to write out the atime then do it anyway. + * */ + if ((LTIME_S(request_body->atime) > + LTIME_S(inode->i_atime) + MAX_ATIME_DIFF) || + (iattr.ia_valid != 0 && + LTIME_S(request_body->atime) > LTIME_S(inode->i_atime))) { + LTIME_S(iattr.ia_atime) = LTIME_S(request_body->atime); + iattr.ia_valid |= ATTR_ATIME; + } + } + + if (iattr.ia_valid != 0) { handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL); if (IS_ERR(handle)) GOTO(cleanup, rc = PTR_ERR(handle)); rc = fsfilt_setattr(obd, mfd->mfd_dentry, handle, &iattr, 0); if (rc) CERROR("error in setattr(%s): rc %d\n", fidname, rc); -#endif } +out: /* If other clients have this file open for write, rc will be > 0 */ if (rc > 0) rc = 0; @@ -1086,10 +1318,10 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd, cleanup: atomic_dec(&mds->mds_open_count); - if (req) { + if (req != NULL && reply_body != NULL) { rc = mds_finish_transno(mds, pending_dir, handle, req, rc, 0); } else if (handle) { - int err = fsfilt_commit(obd, pending_dir, handle, 0); + int err = fsfilt_commit(obd, mds->mds_sb, pending_dir, handle, 0); if (err) { CERROR("error committing close: %d\n", err); if (!rc) @@ -1112,7 +1344,7 @@ int mds_close(struct ptlrpc_request *req) struct obd_device *obd = req->rq_export->exp_obd; struct mds_body *body; struct mds_file_data *mfd; - struct obd_run_ctxt saved; + struct lvfs_run_ctxt saved; struct inode *inode; int rc, repsize[3] = {sizeof(struct mds_body), obd->u.mds.mds_max_mdsize, @@ -1150,17 +1382,17 @@ int mds_close(struct ptlrpc_request *req) body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body)); LASSERT(body != NULL); - mds_pack_inode2fid(&body->fid1, inode); - mds_pack_inode2body(body, inode); + mds_pack_inode2fid(obd, &body->fid1, inode); + mds_pack_inode2body(obd, body, inode); mds_pack_md(obd, req->rq_repmsg, 1, body, inode, 1); } spin_lock(&med->med_open_lock); list_del(&mfd->mfd_list); spin_unlock(&med->med_open_lock); - push_ctxt(&saved, &obd->obd_ctxt, NULL); - req->rq_status = mds_mfd_close(rc ? NULL : req, obd, mfd, 1); - pop_ctxt(&saved, &obd->obd_ctxt, NULL); + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + req->rq_status = mds_mfd_close(req, obd, mfd, 1); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); if (OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) { CERROR("test case OBD_FAIL_MDS_CLOSE_PACK\n");