1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (mds) request handler
7 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
8 * Author: Peter Braam <braam@clusterfs.com>
9 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * Author: Phil Schwan <phil@clusterfs.com>
11 * Author: Mike Shaver <shaver@clusterfs.com>
13 * This file is part of Lustre, http://www.lustre.org.
15 * Lustre is free software; you can redistribute it and/or
16 * modify it under the terms of version 2 of the GNU General Public
17 * License as published by the Free Software Foundation.
19 * Lustre is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Lustre; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_MDS
34 #include <linux/module.h>
35 #include <linux/lustre_mds.h>
36 #include <linux/lustre_dlm.h>
37 #include <linux/init.h>
38 #include <linux/obd_class.h>
39 #include <linux/random.h>
41 #include <linux/jbd.h>
42 #include <linux/ext3_fs.h>
43 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
44 # include <linux/smp_lock.h>
45 # include <linux/buffer_head.h>
46 # include <linux/workqueue.h>
47 # include <linux/mount.h>
49 # include <linux/locks.h>
51 #include <linux/obd_lov.h>
52 #include <linux/lustre_mds.h>
53 #include <linux/lustre_fsfilt.h>
54 #include <linux/lprocfs_status.h>
55 #include <linux/lustre_commit_confd.h>
57 #include "mds_internal.h"
59 static int mds_intent_policy(struct ldlm_namespace *ns,
60 struct ldlm_lock **lockp, void *req_cookie,
61 ldlm_mode_t mode, int flags, void *data);
62 static int mds_postsetup(struct obd_device *obd);
63 static int mds_cleanup(struct obd_device *obd, int flags);
65 /* Assumes caller has already pushed into the kernel filesystem context */
66 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
67 loff_t offset, int count)
69 struct ptlrpc_bulk_desc *desc;
70 struct l_wait_info lwi;
72 int rc = 0, npages, i, tmpcount, tmpsize = 0;
75 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
77 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
78 OBD_ALLOC(pages, sizeof(*pages) * npages);
80 GOTO(out, rc = -ENOMEM);
82 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
85 GOTO(out_free, rc = -ENOMEM);
87 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
88 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
90 pages[i] = alloc_pages(GFP_KERNEL, 0);
92 GOTO(cleanup_buf, rc = -ENOMEM);
94 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
97 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
98 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
99 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
100 tmpsize, offset, file->f_dentry->d_inode->i_ino,
101 file->f_dentry->d_inode->i_size);
103 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
104 page_address(pages[i]), tmpsize, &offset);
107 GOTO(cleanup_buf, rc = -EIO);
110 LASSERT(desc->bd_nob == count);
112 rc = ptlrpc_start_bulk_transfer(desc);
114 GOTO(cleanup_buf, rc);
116 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
117 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
118 OBD_FAIL_MDS_SENDPAGE, rc);
119 GOTO(abort_bulk, rc);
122 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
123 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
124 LASSERT (rc == 0 || rc == -ETIMEDOUT);
127 if (desc->bd_success &&
128 desc->bd_nob_transferred == count)
129 GOTO(cleanup_buf, rc);
131 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
134 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
135 (rc == -ETIMEDOUT) ? "timeout" : "network error",
136 desc->bd_nob_transferred, count,
137 req->rq_export->exp_client_uuid.uuid,
138 req->rq_export->exp_connection->c_remote_uuid.uuid);
140 ptlrpc_fail_export(req->rq_export);
144 ptlrpc_abort_bulk (desc);
146 for (i = 0; i < npages; i++)
148 __free_pages(pages[i], 0);
150 ptlrpc_free_bulk(desc);
152 OBD_FREE(pages, sizeof(*pages) * npages);
157 /* only valid locked dentries or errors should be returned */
158 struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
159 struct vfsmount **mnt, int lock_mode,
160 struct lustre_handle *lockh,
161 char *name, int namelen, __u64 lockpart)
163 struct mds_obd *mds = &obd->u.mds;
164 struct dentry *de = mds_fid2dentry(mds, fid, mnt), *retval = de;
165 struct ldlm_res_id res_id = { .name = {0} };
167 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
174 res_id.name[0] = de->d_inode->i_ino;
175 res_id.name[1] = de->d_inode->i_generation;
178 if (name && IS_PDIROPS(de->d_inode)) {
179 ldlm_policy_data_t cpolicy =
180 { .l_inodebits = { MDS_INODELOCK_UPDATE } };
181 /* lock just dir { ino, generation } to flush client cache */
182 if (lock_mode == LCK_PW) {
183 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
185 &cpolicy, LCK_CW, &flags,
187 ldlm_completion_ast, NULL, NULL,
188 NULL, 0, NULL, lockh + 1);
189 if (rc != ELDLM_OK) {
191 RETURN(ERR_PTR(-ENOLCK));
196 res_id.name[2] = full_name_hash(name, namelen);
197 CDEBUG(D_INFO, "take lock on %lu:%u:"LPX64"\n",
198 de->d_inode->i_ino, de->d_inode->i_generation,
202 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
203 LDLM_IBITS, &policy, lock_mode, &flags,
204 mds_blocking_ast, ldlm_completion_ast, NULL, NULL,
205 NULL, 0, NULL, lockh);
206 if (rc != ELDLM_OK) {
208 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
211 ldlm_lock_decref(lockh + 1, LCK_CW);
218 #ifndef DCACHE_DISCONNECTED
219 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
223 /* Look up an entry by inode number. */
224 /* this function ONLY returns valid dget'd dentries with an initialized inode
226 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
227 struct vfsmount **mnt)
230 unsigned long ino = fid->id;
231 __u32 generation = fid->generation;
233 struct dentry *result;
236 RETURN(ERR_PTR(-ESTALE));
238 snprintf(fid_name, sizeof(fid_name), "0x%lx", ino);
240 CDEBUG(D_DENTRY, "--> mds_fid2dentry: ino/gen %lu/%u, sb %p\n",
241 ino, generation, mds->mds_sb);
243 /* under ext3 this is neither supposed to return bad inodes
245 result = ll_lookup_one_len(fid_name, mds->mds_fid_de, strlen(fid_name));
249 inode = result->d_inode;
251 RETURN(ERR_PTR(-ENOENT));
253 if (generation && inode->i_generation != generation) {
254 /* we didn't find the right inode.. */
255 CERROR("bad inode %lu, link: %lu ct: %d or generation %u/%u\n",
256 inode->i_ino, (unsigned long)inode->i_nlink,
257 atomic_read(&inode->i_count), inode->i_generation,
260 RETURN(ERR_PTR(-ENOENT));
264 *mnt = mds->mds_vfsmnt;
272 /* Establish a connection to the MDS.
274 * This will set up an export structure for the client to hold state data
275 * about that client, like open files, the last operation number it did
276 * on the server, etc.
278 static int mds_connect(struct lustre_handle *conn, struct obd_device *obd,
279 struct obd_uuid *cluuid)
281 struct obd_export *exp;
282 struct mds_export_data *med; /* */
283 struct mds_client_data *mcd;
284 int rc, abort_recovery;
287 if (!conn || !obd || !cluuid)
290 /* Check for aborted recovery. */
291 spin_lock_bh(&obd->obd_processing_task_lock);
292 abort_recovery = obd->obd_abort_recovery;
293 spin_unlock_bh(&obd->obd_processing_task_lock);
295 target_abort_recovery(obd);
297 /* XXX There is a small race between checking the list and adding a
298 * new connection for the same UUID, but the real threat (list
299 * corruption when multiple different clients connect) is solved.
301 * There is a second race between adding the export to the list,
302 * and filling in the client data below. Hence skipping the case
303 * of NULL mcd above. We should already be controlling multiple
304 * connects at the client, and we can't hold the spinlock over
305 * memory allocations without risk of deadlocking.
307 rc = class_connect(conn, obd, cluuid);
310 exp = class_conn2export(conn);
312 med = &exp->exp_mds_data;
314 OBD_ALLOC(mcd, sizeof(*mcd));
316 CERROR("mds: out of memory for client data\n");
317 GOTO(out, rc = -ENOMEM);
320 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
323 rc = mds_client_add(obd, &obd->u.mds, med, -1);
328 OBD_FREE(mcd, sizeof(*mcd));
329 class_disconnect(exp, 0);
331 class_export_put(exp);
336 static int mds_init_export(struct obd_export *exp)
338 struct mds_export_data *med = &exp->exp_mds_data;
340 INIT_LIST_HEAD(&med->med_open_head);
341 spin_lock_init(&med->med_open_lock);
345 static int mds_destroy_export(struct obd_export *export)
347 struct mds_export_data *med;
348 struct obd_device *obd = export->exp_obd;
349 struct obd_run_ctxt saved;
353 med = &export->exp_mds_data;
354 target_destroy_export(export);
356 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
359 push_ctxt(&saved, &obd->obd_ctxt, NULL);
360 /* Close any open files (which may also cause orphan unlinking). */
361 spin_lock(&med->med_open_lock);
362 while (!list_empty(&med->med_open_head)) {
363 struct list_head *tmp = med->med_open_head.next;
364 struct mds_file_data *mfd =
365 list_entry(tmp, struct mds_file_data, mfd_list);
366 BDEVNAME_DECLARE_STORAGE(btmp);
368 /* bug 1579: fix force-closing for 2.5 */
369 struct dentry *dentry = mfd->mfd_dentry;
371 list_del(&mfd->mfd_list);
372 spin_unlock(&med->med_open_lock);
374 CERROR("force closing client file handle for %*s (%s:%lu)\n",
375 dentry->d_name.len, dentry->d_name.name,
376 ll_bdevname(dentry->d_inode->i_sb, btmp),
377 dentry->d_inode->i_ino);
378 rc = mds_mfd_close(NULL, obd, mfd,
379 !(export->exp_flags & OBD_OPT_FAILOVER));
382 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
383 spin_lock(&med->med_open_lock);
385 spin_unlock(&med->med_open_lock);
386 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
389 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
394 static int mds_disconnect(struct obd_export *exp, int flags)
396 struct obd_device *obd;
398 unsigned long irqflags;
403 class_export_get(exp);
405 obd = class_exp2obd(exp);
407 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
408 exp->exp_handle.h_cookie);
413 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
414 && !atomic_read(&mds->mds_real_clients)) {
415 /* there was no client at all */
416 mds_lmv_disconnect(obd, flags);
419 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
420 && atomic_dec_and_test(&mds->mds_real_clients)) {
421 /* time to drop LMV connections */
422 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
423 "Disconnnect from LMV now\n",
424 obd->obd_name, exp->exp_client_uuid.uuid);
425 mds_lmv_disconnect(obd, flags);
428 spin_lock_irqsave(&exp->exp_lock, irqflags);
429 exp->exp_flags = flags;
430 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
432 /* Disconnect early so that clients can't keep using export */
433 rc = class_disconnect(exp, flags);
434 ldlm_cancel_locks_for_export(exp);
436 /* complete all outstanding replies */
437 spin_lock_irqsave(&exp->exp_lock, irqflags);
438 while (!list_empty(&exp->exp_outstanding_replies)) {
439 struct ptlrpc_reply_state *rs =
440 list_entry(exp->exp_outstanding_replies.next,
441 struct ptlrpc_reply_state, rs_exp_list);
442 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
444 spin_lock(&svc->srv_lock);
445 list_del_init(&rs->rs_exp_list);
446 ptlrpc_schedule_difficult_reply(rs);
447 spin_unlock(&svc->srv_lock);
449 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
451 class_export_put(exp);
455 static int mds_getstatus(struct ptlrpc_request *req)
457 struct mds_obd *mds = mds_req2mds(req);
458 struct mds_body *body;
459 int rc, size = sizeof(*body);
462 rc = lustre_pack_reply(req, 1, &size, NULL);
463 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
464 CERROR("mds: out of memory for message: size=%d\n", size);
465 req->rq_status = -ENOMEM; /* superfluous? */
469 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
470 memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
472 /* the last_committed and last_xid fields are filled in for all
473 * replies already - no need to do so here also.
478 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
479 void *data, int flag)
484 if (flag == LDLM_CB_CANCELING) {
485 /* Don't need to do anything here. */
489 /* XXX layering violation! -phil */
490 l_lock(&lock->l_resource->lr_namespace->ns_lock);
491 /* Get this: if mds_blocking_ast is racing with mds_intent_policy,
492 * such that mds_blocking_ast is called just before l_i_p takes the
493 * ns_lock, then by the time we get the lock, we might not be the
494 * correct blocking function anymore. So check, and return early, if
496 if (lock->l_blocking_ast != mds_blocking_ast) {
497 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
501 lock->l_flags |= LDLM_FL_CBPENDING;
502 do_ast = (!lock->l_readers && !lock->l_writers);
503 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
506 struct lustre_handle lockh;
509 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
510 ldlm_lock2handle(lock, &lockh);
511 rc = ldlm_cli_cancel(&lockh);
513 CERROR("ldlm_cli_cancel: %d\n", rc);
515 LDLM_DEBUG(lock, "Lock still has references, will be "
521 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
522 * Call with lock=0 if the caller has already taken the i_sem. */
523 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
524 struct mds_body *body, struct inode *inode, int lock)
526 struct mds_obd *mds = &obd->u.mds;
532 lmm = lustre_msg_buf(msg, offset, 0);
534 /* Some problem with getting eadata when I sized the reply
536 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
540 lmm_size = msg->buflens[offset];
542 /* I don't really like this, but it is a sanity check on the client
543 * MD request. However, if the client doesn't know how much space
544 * to reserve for the MD, it shouldn't be bad to have too much space.
546 if (lmm_size > mds->mds_max_mdsize) {
547 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
548 inode->i_ino, lmm_size, mds->mds_max_mdsize);
554 rc = fsfilt_get_md(obd, inode, lmm, lmm_size);
558 CERROR("Error %d reading eadata for ino %lu\n",
562 if (S_ISREG(inode->i_mode))
563 rc = mds_convert_lov_ea(obd, inode, lmm, lmm_size);
566 body->valid |= OBD_MD_FLEASIZE;
567 body->eadatasize = lmm_size;
574 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
575 struct ptlrpc_request *req,
576 struct mds_body *reqbody, int reply_off)
578 struct mds_body *body;
579 struct inode *inode = dentry->d_inode;
583 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
586 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
587 LASSERT(body != NULL); /* caller prepped reply */
589 if (dentry->d_flags & DCACHE_CROSS_REF) {
590 CDEBUG(D_OTHER, "cross reference: %lu/%lu/%lu\n",
591 (unsigned long) dentry->d_mdsnum,
592 (unsigned long) dentry->d_inum,
593 (unsigned long) dentry->d_generation);
594 body->valid |= OBD_MD_FLID | OBD_MD_MDS;
595 body->fid1.id = dentry->d_inum;
596 body->fid1.mds = dentry->d_mdsnum;
597 body->fid1.generation = dentry->d_generation;
600 mds_pack_inode2fid(obd, &body->fid1, inode);
601 mds_pack_inode2body(obd, body, inode);
603 if (S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE) != 0) {
604 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1, body,
607 /* If we have LOV EA data, the OST holds size, atime, mtime */
608 if (!(body->valid & OBD_MD_FLEASIZE))
609 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
610 OBD_MD_FLATIME | OBD_MD_FLMTIME);
611 } else if (S_ISLNK(inode->i_mode) &&
612 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
613 char *symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
616 LASSERT (symname != NULL); /* caller prepped reply */
617 len = req->rq_repmsg->buflens[reply_off + 1];
619 rc = inode->i_op->readlink(dentry, symname, len);
621 CERROR("readlink failed: %d\n", rc);
622 } else if (rc != len - 1) {
623 CERROR ("Unexpected readlink rc %d: expecting %d\n",
627 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
628 body->valid |= OBD_MD_LINKNAME;
629 body->eadatasize = rc + 1;
630 symname[rc] = 0; /* NULL terminate */
633 } else if (S_ISDIR(inode->i_mode) &&
634 (reqbody->valid & OBD_MD_FLEASIZE) != 0) {
635 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1, body,
642 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
643 struct dentry *dentry,
646 int rc = 0, size[1] = {sizeof(struct mds_body)};
649 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
650 CERROR("failed MDS_GETATTR_PACK test\n");
651 req->rq_status = -ENOMEM;
652 GOTO(out, rc = -ENOMEM);
655 rc = lustre_pack_reply(req, 1, size, NULL);
657 CERROR("out of memory\n");
658 GOTO(out, req->rq_status = rc);
666 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode,
669 struct mds_obd *mds = mds_req2mds(req);
670 struct mds_body *body;
671 int rc = 0, size[2] = {sizeof(*body)}, bufcount = 1;
674 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*body));
675 LASSERT(body != NULL); /* checked by caller */
676 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
678 if ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))
679 && (body->valid & OBD_MD_FLEASIZE)) {
682 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0);
684 CDEBUG(D_INODE, "got %d bytes MD data for inode %lu\n",
688 CERROR("error getting inode %lu MD: rc = %d\n",
691 } else if (rc > mds->mds_max_mdsize) {
693 CERROR("MD size %d larger than maximum possible %u\n",
694 rc, mds->mds_max_mdsize);
699 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
700 if (inode->i_size + 1 != body->eadatasize)
701 CERROR("symlink size: %Lu, reply space: %d\n",
702 inode->i_size + 1, body->eadatasize);
703 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
705 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
706 inode->i_size + 1, body->eadatasize);
709 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
710 CERROR("failed MDS_GETATTR_PACK test\n");
711 req->rq_status = -ENOMEM;
712 GOTO(out, rc = -ENOMEM);
715 rc = lustre_pack_reply(req, bufcount, size, NULL);
717 CERROR("out of memory\n");
718 GOTO(out, req->rq_status = rc);
726 static int mds_getattr_name(int offset, struct ptlrpc_request *req,
727 struct lustre_handle *child_lockh, int child_part)
729 struct obd_device *obd = req->rq_export->exp_obd;
730 struct ldlm_reply *rep = NULL;
731 struct obd_run_ctxt saved;
732 struct mds_body *body;
733 struct dentry *dparent = NULL, *dchild = NULL;
735 struct lustre_handle parent_lockh[2];
737 int rc = 0, cleanup_phase = 0, resent_req = 0;
741 LASSERT(!strcmp(obd->obd_type->typ_name, "mds"));
743 /* Swab now, before anyone looks inside the request */
745 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
746 lustre_swab_mds_body);
748 CERROR("Can't swab mds_body\n");
749 GOTO(cleanup, rc = -EFAULT);
752 LASSERT_REQSWAB(req, offset + 1);
753 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
755 CERROR("Can't unpack name\n");
756 GOTO(cleanup, rc = -EFAULT);
758 namesize = req->rq_reqmsg->buflens[offset + 1];
760 LASSERT (offset == 0 || offset == 2);
761 /* if requests were at offset 2, the getattr reply goes back at 1 */
763 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
767 uc.ouc_fsuid = body->fsuid;
768 uc.ouc_fsgid = body->fsgid;
769 uc.ouc_cap = body->capability;
770 uc.ouc_suppgid1 = body->suppgid;
771 uc.ouc_suppgid2 = -1;
772 push_ctxt(&saved, &obd->obd_ctxt, &uc);
773 cleanup_phase = 1; /* kernel context */
774 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
776 LASSERT(namesize > 0);
778 /* we have no dentry here, drop LOOKUP bit */
779 child_part &= ~MDS_INODELOCK_LOOKUP;
780 CDEBUG(D_OTHER, "%s: request to retrieve attrs for %lu/%lu\n",
781 obd->obd_name, (unsigned long) body->fid1.id,
782 (unsigned long) body->fid1.generation);
783 dchild = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_PR,
784 parent_lockh, NULL, 0, child_part);
785 if (IS_ERR(dchild)) {
786 CERROR("can't find inode: %d\n", (int) PTR_ERR(dchild));
787 GOTO(cleanup, rc = PTR_ERR(dchild));
789 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
791 if (parent_lockh[1].cookie)
792 ldlm_lock_decref(parent_lockh + 1, LCK_CW);
798 /* FIXME: handle raw lookup */
800 if (body->valid == OBD_MD_FLID) {
801 struct mds_body *mds_reply;
802 int size = sizeof(*mds_reply);
804 // The user requested ONLY the inode number, so do a raw lookup
805 rc = lustre_pack_reply(req, 1, &size, NULL);
807 CERROR("out of memory\n");
811 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
813 mds_reply = lustre_msg_buf(req->rq_repmsg, offset,
815 mds_reply->fid1.id = inum;
816 mds_reply->valid = OBD_MD_FLID;
821 if (child_lockh->cookie != 0) {
822 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
826 if (resent_req == 0) {
827 rc = mds_get_parent_child_locked(obd, &obd->u.mds, &body->fid1,
828 parent_lockh, &dparent,
829 LCK_PR, MDS_INODELOCK_LOOKUP,
831 child_lockh, &dchild, LCK_PR,
836 struct ldlm_lock *granted_lock;
837 struct ll_fid child_fid;
838 struct ldlm_resource *res;
839 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
840 granted_lock = ldlm_handle2lock(child_lockh);
841 LASSERT(granted_lock);
843 res = granted_lock->l_resource;
844 child_fid.id = res->lr_name.name[0];
845 child_fid.generation = res->lr_name.name[1];
846 dchild = mds_fid2dentry(&obd->u.mds, &child_fid, NULL);
848 LDLM_LOCK_PUT(granted_lock);
851 cleanup_phase = 2; /* dchild, dparent, locks */
854 if (!DENTRY_VALID(dchild)) {
855 intent_set_disposition(rep, DISP_LOOKUP_NEG);
856 /* in the intent case, the policy clears this error:
857 the disposition is enough */
858 GOTO(cleanup, rc = -ENOENT);
860 intent_set_disposition(rep, DISP_LOOKUP_POS);
863 if (req->rq_repmsg == NULL) {
864 if (dchild->d_flags & DCACHE_CROSS_REF)
865 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
867 rc = mds_getattr_pack_msg(req, dchild->d_inode, offset);
869 CERROR ("mds_getattr_pack_msg: %d\n", rc);
874 rc = mds_getattr_internal(obd, dchild, req, body, offset);
875 GOTO(cleanup, rc); /* returns the lock to the client */
878 switch (cleanup_phase) {
880 if (resent_req == 0) {
881 if (rc && DENTRY_VALID(dchild))
882 ldlm_lock_decref(child_lockh, LCK_PR);
884 ldlm_lock_decref(parent_lockh, LCK_PR);
886 if (parent_lockh[1].cookie != 0)
887 ldlm_lock_decref(parent_lockh + 1,
896 pop_ctxt(&saved, &obd->obd_ctxt, &uc);
902 static int mds_getattr(int offset, struct ptlrpc_request *req)
904 struct mds_obd *mds = mds_req2mds(req);
905 struct obd_device *obd = req->rq_export->exp_obd;
906 struct obd_run_ctxt saved;
908 struct mds_body *body;
913 body = lustre_swab_reqbuf (req, offset, sizeof (*body),
914 lustre_swab_mds_body);
916 CERROR ("Can't unpack body\n");
920 uc.ouc_fsuid = body->fsuid;
921 uc.ouc_fsgid = body->fsgid;
922 uc.ouc_cap = body->capability;
923 push_ctxt(&saved, &obd->obd_ctxt, &uc);
924 de = mds_fid2dentry(mds, &body->fid1, NULL);
926 rc = req->rq_status = -ENOENT;
927 GOTO(out_pop, PTR_ERR(de));
930 rc = mds_getattr_pack_msg(req, de->d_inode, offset);
932 CERROR ("mds_getattr_pack_msg: %d\n", rc);
936 req->rq_status = mds_getattr_internal(obd, de, req, body, 0);
941 pop_ctxt(&saved, &obd->obd_ctxt, &uc);
946 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
947 unsigned long max_age)
951 spin_lock(&obd->obd_osfs_lock);
952 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
954 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
955 spin_unlock(&obd->obd_osfs_lock);
960 static int mds_statfs(struct ptlrpc_request *req)
962 struct obd_device *obd = req->rq_export->exp_obd;
963 int rc, size = sizeof(struct obd_statfs);
966 rc = lustre_pack_reply(req, 1, &size, NULL);
967 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
968 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
972 /* We call this so that we can cache a bit - 1 jiffie worth */
973 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
976 CERROR("mds_obd_statfs failed: rc %d\n", rc);
986 static int mds_sync(struct ptlrpc_request *req)
988 struct obd_device *obd = req->rq_export->exp_obd;
989 struct mds_obd *mds = &obd->u.mds;
990 struct mds_body *body;
991 int rc, size = sizeof(*body);
994 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*body));
996 GOTO(out, rc = -EPROTO);
998 rc = lustre_pack_reply(req, 1, &size, NULL);
999 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1000 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1004 if (body->fid1.id == 0) {
1005 /* a fid of zero is taken to mean "sync whole filesystem" */
1006 rc = fsfilt_sync(obd, mds->mds_sb);
1010 /* just any file to grab fsync method - "file" arg unused */
1011 struct file *file = mds->mds_rcvd_filp;
1014 de = mds_fid2dentry(mds, &body->fid1, NULL);
1016 GOTO(out, rc = PTR_ERR(de));
1018 rc = file->f_op->fsync(NULL, de, 1);
1023 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1024 mds_pack_inode2fid(obd, &body->fid1, de->d_inode);
1025 mds_pack_inode2body(obd, body, de->d_inode);
1028 req->rq_status = rc;
1032 /* mds_readpage does not take a DLM lock on the inode, because the client must
1033 * already have a PR lock.
1035 * If we were to take another one here, a deadlock will result, if another
1036 * thread is already waiting for a PW lock. */
1037 static int mds_readpage(struct ptlrpc_request *req)
1039 struct obd_device *obd = req->rq_export->exp_obd;
1040 struct vfsmount *mnt;
1043 struct mds_body *body, *repbody;
1044 struct obd_run_ctxt saved;
1045 int rc, size = sizeof(*repbody);
1046 struct obd_ucred uc;
1049 rc = lustre_pack_reply(req, 1, &size, NULL);
1050 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1051 CERROR("mds: out of memory\n");
1052 GOTO(out, rc = -ENOMEM);
1055 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
1057 GOTO (out, rc = -EFAULT);
1059 uc.ouc_fsuid = body->fsuid;
1060 uc.ouc_fsgid = body->fsgid;
1061 uc.ouc_cap = body->capability;
1062 push_ctxt(&saved, &obd->obd_ctxt, &uc);
1063 de = mds_fid2dentry(&obd->u.mds, &body->fid1, &mnt);
1065 GOTO(out_pop, rc = PTR_ERR(de));
1067 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1069 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1070 /* note: in case of an error, dentry_open puts dentry */
1072 GOTO(out_pop, rc = PTR_ERR(file));
1074 /* body->size is actually the offset -eeb */
1075 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1076 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1077 body->size, de->d_inode->i_blksize);
1078 GOTO(out_file, rc = -EFAULT);
1081 /* body->nlink is actually the #bytes to read -eeb */
1082 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1083 CERROR("size %u is not multiple of blocksize %lu\n",
1084 body->nlink, de->d_inode->i_blksize);
1085 GOTO(out_file, rc = -EFAULT);
1088 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
1089 repbody->size = file->f_dentry->d_inode->i_size;
1090 repbody->valid = OBD_MD_FLSIZE;
1092 /* to make this asynchronous make sure that the handling function
1093 doesn't send a reply when this function completes. Instead a
1094 callback function would send the reply */
1095 /* body->size is actually the offset -eeb */
1096 rc = mds_sendpage(req, file, body->size, body->nlink);
1099 filp_close(file, 0);
1101 pop_ctxt(&saved, &obd->obd_ctxt, &uc);
1103 req->rq_status = rc;
1107 int mds_reint(struct ptlrpc_request *req, int offset,
1108 struct lustre_handle *lockh)
1110 struct mds_update_record *rec; /* 116 bytes on the stack? no sir! */
1114 OBD_ALLOC(rec, sizeof(*rec));
1118 rc = mds_update_unpack(req, offset, rec);
1119 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1120 CERROR("invalid record\n");
1121 GOTO(out, req->rq_status = -EINVAL);
1123 /* rc will be used to interrupt a for loop over multiple records */
1124 rc = mds_reint_rec(rec, offset, req, lockh);
1126 OBD_FREE(rec, sizeof(*rec));
1130 static int mds_filter_recovery_request(struct ptlrpc_request *req,
1131 struct obd_device *obd, int *process)
1133 switch (req->rq_reqmsg->opc) {
1134 case MDS_CONNECT: /* This will never get here, but for completeness. */
1135 case OST_CONNECT: /* This will never get here, but for completeness. */
1136 case MDS_DISCONNECT:
1137 case OST_DISCONNECT:
1142 case MDS_SYNC: /* used in unmounting */
1146 *process = target_queue_recovery_request(req, obd);
1150 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1152 /* XXX what should we set rq_status to here? */
1153 req->rq_status = -EAGAIN;
1154 RETURN(ptlrpc_error(req));
1158 static char *reint_names[] = {
1159 [REINT_SETATTR] "setattr",
1160 [REINT_CREATE] "create",
1161 [REINT_LINK] "link",
1162 [REINT_UNLINK] "unlink",
1163 [REINT_RENAME] "rename",
1164 [REINT_OPEN] "open",
1167 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER |\
1168 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ|\
1169 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME|\
1172 static int mdt_obj_create(struct ptlrpc_request *req)
1174 struct ldlm_res_id res_id = { .name = {0} };
1175 struct obd_export *exp = req->rq_export;
1176 struct obd_device *obd = exp->exp_obd;
1177 struct mds_obd *mds = &obd->u.mds;
1178 struct ost_body *body, *repbody;
1179 int rc, size = sizeof(*repbody);
1180 char fidname[LL_FID_NAMELEN];
1181 struct inode *parent_inode;
1182 struct lustre_handle lockh;
1183 struct obd_run_ctxt saved;
1184 ldlm_policy_data_t policy;
1185 int mealen, flags = 0;
1186 unsigned int tmpname;
1187 struct obd_ucred uc;
1193 parent_inode = mds->mds_objects_dir->d_inode;
1195 body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_ost_body);
1199 uc.ouc_fsuid = body->oa.o_uid;
1200 uc.ouc_fsgid = body->oa.o_gid;
1202 push_ctxt(&saved, &obd->obd_ctxt, &uc);
1204 rc = lustre_pack_reply(req, 1, &size, NULL);
1208 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
1211 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
1212 LASSERT(!IS_ERR(handle));
1214 tmpname = ll_insecure_random_int();
1215 sprintf(fidname, "%u", tmpname);
1216 new = simple_mkdir(mds->mds_objects_dir, fidname,
1217 body->oa.o_mode, 1);
1219 CERROR("%s: can't create new inode %s) for mkdir: %d\n",
1220 obd->obd_name, fidname, (int) PTR_ERR(new));
1221 if (PTR_ERR(new) == -EEXIST) {
1222 fsfilt_commit(obd, parent_inode, handle, 0);
1226 LASSERT(!IS_ERR(new));
1227 LASSERT(new->d_inode != NULL);
1229 if (body->oa.o_valid & OBD_MD_FLID) {
1230 /* this is new object for splitted dir. we have to
1231 * prevent recursive splitting on it -bzzz */
1232 mealen = obd_size_diskmd(mds->mds_lmv_exp, NULL);
1233 OBD_ALLOC(mea, mealen);
1234 LASSERT(mea != NULL);
1236 down(&new->d_inode->i_sem);
1237 handle = fsfilt_start(obd, new->d_inode, FSFILT_OP_SETATTR, NULL);
1238 LASSERT(!IS_ERR(handle));
1239 rc = fsfilt_set_md(obd, new->d_inode, handle, mea, mealen);
1241 fsfilt_commit(obd, new->d_inode, handle, 0);
1243 up(&new->d_inode->i_sem);
1244 OBD_FREE(mea, mealen);
1246 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
1247 repbody->oa.o_id = new->d_inode->i_ino;
1248 repbody->oa.o_generation = new->d_inode->i_generation;
1249 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
1251 down(&parent_inode->i_sem);
1252 rc = fsfilt_del_dir_entry(obd, new);
1253 up(&parent_inode->i_sem);
1256 rc = mds_finish_transno(mds, parent_inode, handle, req, rc, 0);
1259 res_id.name[0] = new->d_inode->i_ino;
1260 res_id.name[1] = new->d_inode->i_generation;
1261 policy.l_inodebits.bits = MDS_INODELOCK_UPDATE;
1262 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
1263 res_id, LDLM_IBITS, &policy,
1264 LCK_EX, &flags, mds_blocking_ast,
1265 ldlm_completion_ast, NULL, NULL,
1266 NULL, 0, NULL, &lockh);
1267 LASSERT(rc == ELDLM_OK);
1269 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
1270 (unsigned long) new->d_inode->i_ino,
1271 (unsigned long) new->d_inode->i_generation,
1272 (unsigned) new->d_inode->i_mode);
1275 pop_ctxt(&saved, &obd->obd_ctxt, &uc);
1276 ptlrpc_save_lock(req, &lockh, LCK_EX);
1280 static int mds_get_info(struct obd_export *exp, __u32 keylen,
1281 void *key, __u32 *vallen, void *val)
1283 struct obd_device *obd;
1284 struct mds_obd *mds;
1287 obd = class_exp2obd(exp);
1289 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1290 exp->exp_handle.h_cookie);
1295 keylen == strlen("mdsize");
1296 if (keylen && memcmp(key, "mdsize", keylen) == 0) {
1297 __u32 *mdsize = val;
1298 *vallen = sizeof(*mdsize);
1299 *mdsize = mds->mds_max_mdsize;
1303 CDEBUG(D_IOCTL, "invalid key\n");
1307 static int mdt_get_info(struct ptlrpc_request *req)
1310 struct obd_export *exp = req->rq_export;
1311 int keylen, rc = 0, size = sizeof(obd_id);
1315 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
1317 DEBUG_REQ(D_HA, req, "no get_info key");
1320 keylen = req->rq_reqmsg->buflens[0];
1322 if (keylen < strlen("mdsize") || memcmp(key, "mdsize", 6) != 0)
1325 rc = lustre_pack_reply(req, 1, &size, NULL);
1329 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*reply));
1330 rc = obd_get_info(exp, keylen, key, &size, reply);
1331 req->rq_repmsg->status = 0;
1335 static int mds_set_info(struct obd_export *exp, __u32 keylen,
1336 void *key, __u32 vallen, void *val)
1338 struct obd_device *obd;
1339 struct mds_obd *mds;
1343 obd = class_exp2obd(exp);
1345 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1346 exp->exp_handle.h_cookie);
1351 keylen == strlen("client");
1352 if (keylen && memcmp(key, "client", keylen) == 0) {
1353 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
1354 atomic_inc(&mds->mds_real_clients);
1355 CDEBUG(D_OTHER, "%s: peer from %s is real client (%d)\n",
1357 exp->exp_client_uuid.uuid,
1358 atomic_read(&mds->mds_real_clients));
1359 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
1361 rc = mds_lmv_connect(obd, mds->mds_lmv_name);
1366 CDEBUG(D_IOCTL, "invalid key\n");
1370 static int mdt_set_info(struct ptlrpc_request *req)
1373 struct obd_export *exp = req->rq_export;
1374 int keylen, rc = 0, size = sizeof(obd_id);
1377 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
1379 DEBUG_REQ(D_HA, req, "no get_info key");
1382 keylen = req->rq_reqmsg->buflens[0];
1384 if ((keylen < strlen("client") || memcmp(key, "client", 6) != 0))
1387 rc = lustre_pack_reply(req, 0, NULL, NULL);
1390 rc = obd_set_info(exp, keylen, key, size, NULL);
1391 req->rq_repmsg->status = 0;
1395 extern int ost_brw_write(struct ptlrpc_request *, struct obd_trans_info *);
1397 int mds_handle(struct ptlrpc_request *req)
1399 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
1401 struct mds_obd *mds = NULL; /* quell gcc overwarning */
1402 struct obd_device *obd = NULL;
1405 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
1407 LASSERT(current->journal_info == NULL);
1408 /* XXX identical to OST */
1409 if (req->rq_reqmsg->opc != MDS_CONNECT) {
1410 struct mds_export_data *med;
1411 int recovering, abort_recovery;
1413 if (req->rq_export == NULL) {
1414 CERROR("lustre_mds: operation %d on unconnected MDS\n",
1415 req->rq_reqmsg->opc);
1416 req->rq_status = -ENOTCONN;
1417 GOTO(out, rc = -ENOTCONN);
1420 med = &req->rq_export->exp_mds_data;
1421 obd = req->rq_export->exp_obd;
1424 /* Check for aborted recovery. */
1425 spin_lock_bh(&obd->obd_processing_task_lock);
1426 abort_recovery = obd->obd_abort_recovery;
1427 recovering = obd->obd_recovering;
1428 spin_unlock_bh(&obd->obd_processing_task_lock);
1429 if (abort_recovery) {
1430 target_abort_recovery(obd);
1431 } else if (recovering) {
1432 rc = mds_filter_recovery_request(req, obd,
1434 if (rc || !should_process)
1439 switch (req->rq_reqmsg->opc) {
1441 DEBUG_REQ(D_INODE, req, "connect");
1442 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
1443 rc = target_handle_connect(req, mds_handle);
1445 /* Now that we have an export, set mds. */
1446 mds = mds_req2mds(req);
1449 case MDS_DISCONNECT:
1450 DEBUG_REQ(D_INODE, req, "disconnect");
1451 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
1452 rc = target_handle_disconnect(req);
1453 req->rq_status = rc; /* superfluous? */
1457 DEBUG_REQ(D_INODE, req, "getstatus");
1458 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
1459 rc = mds_getstatus(req);
1463 DEBUG_REQ(D_INODE, req, "getattr");
1464 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
1465 rc = mds_getattr(0, req);
1468 case MDS_GETATTR_NAME: {
1469 struct lustre_handle lockh;
1470 DEBUG_REQ(D_INODE, req, "getattr_name");
1471 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NAME_NET, 0);
1473 /* If this request gets a reconstructed reply, we won't be
1474 * acquiring any new locks in mds_getattr_name, so we don't
1478 rc = mds_getattr_name(0, req, &lockh, MDS_INODELOCK_UPDATE);
1479 /* this non-intent call (from an ioctl) is special */
1480 req->rq_status = rc;
1481 if (rc == 0 && lockh.cookie)
1482 ldlm_lock_decref(&lockh, LCK_PR);
1486 DEBUG_REQ(D_INODE, req, "statfs");
1487 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
1488 rc = mds_statfs(req);
1492 DEBUG_REQ(D_INODE, req, "readpage");
1493 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
1494 rc = mds_readpage(req);
1496 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
1497 if (req->rq_reply_state) {
1498 lustre_free_reply_state (req->rq_reply_state);
1499 req->rq_reply_state = NULL;
1507 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*opcp));
1509 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
1510 mds->mds_max_cookiesize};
1513 /* NB only peek inside req now; mds_reint() will swab it */
1515 CERROR ("Can't inspect opcode\n");
1520 if (lustre_msg_swabbed (req->rq_reqmsg))
1523 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
1524 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
1525 reint_names[opc] == NULL) ? reint_names[opc] :
1528 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
1530 if (opc == REINT_UNLINK)
1532 else if (opc == REINT_OPEN || opc == REINT_RENAME)
1537 rc = lustre_pack_reply(req, bufcount, size, NULL);
1541 rc = mds_reint(req, 0, NULL);
1542 fail = OBD_FAIL_MDS_REINT_NET_REP;
1547 DEBUG_REQ(D_INODE, req, "close");
1548 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
1549 rc = mds_close(req);
1552 case MDS_DONE_WRITING:
1553 DEBUG_REQ(D_INODE, req, "done_writing");
1554 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
1555 rc = mds_done_writing(req);
1559 DEBUG_REQ(D_INODE, req, "pin");
1560 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
1565 DEBUG_REQ(D_INODE, req, "sync");
1566 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
1571 DEBUG_REQ(D_INODE, req, "ping");
1572 rc = target_handle_ping(req);
1575 case OBD_LOG_CANCEL:
1576 CDEBUG(D_INODE, "log cancel\n");
1577 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1578 rc = -ENOTSUPP; /* la la la */
1582 DEBUG_REQ(D_INODE, req, "enqueue");
1583 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1584 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1585 ldlm_server_blocking_ast, NULL);
1588 DEBUG_REQ(D_INODE, req, "convert");
1589 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1590 rc = ldlm_handle_convert(req);
1592 case LDLM_BL_CALLBACK:
1593 case LDLM_CP_CALLBACK:
1594 DEBUG_REQ(D_INODE, req, "callback");
1595 CERROR("callbacks should not happen on MDS\n");
1597 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
1599 case LLOG_ORIGIN_HANDLE_CREATE:
1600 DEBUG_REQ(D_INODE, req, "llog_init");
1601 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1602 rc = llog_origin_handle_create(req);
1604 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1605 DEBUG_REQ(D_INODE, req, "llog next block");
1606 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1607 rc = llog_origin_handle_next_block(req);
1609 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1610 DEBUG_REQ(D_INODE, req, "llog read header");
1611 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1612 rc = llog_origin_handle_read_header(req);
1614 case LLOG_ORIGIN_HANDLE_CLOSE:
1615 DEBUG_REQ(D_INODE, req, "llog close");
1616 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1617 rc = llog_origin_handle_close(req);
1620 DEBUG_REQ(D_INODE, req, "ost_create");
1621 rc = mdt_obj_create(req);
1624 DEBUG_REQ(D_INODE, req, "get_info");
1625 rc = mdt_get_info(req);
1628 DEBUG_REQ(D_INODE, req, "set_info");
1629 rc = mdt_set_info(req);
1632 CDEBUG(D_INODE, "write\n");
1633 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
1634 rc = ost_brw_write(req, NULL);
1635 LASSERT(current->journal_info == NULL);
1636 /* mdt_brw sends its own replies */
1640 DEBUG_REQ(D_INODE, req, "llog catinfo");
1641 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1642 rc = llog_catinfo(req);
1645 req->rq_status = -ENOTSUPP;
1646 rc = ptlrpc_error(req);
1650 LASSERT(current->journal_info == NULL);
1654 /* If we're DISCONNECTing, the mds_export_data is already freed */
1655 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
1656 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1657 struct obd_device *obd = list_entry(mds, struct obd_device,
1659 req->rq_repmsg->last_xid =
1660 le64_to_cpu(med->med_mcd->mcd_last_xid);
1662 if (!obd->obd_no_transno) {
1663 req->rq_repmsg->last_committed =
1664 obd->obd_last_committed;
1666 DEBUG_REQ(D_IOCTL, req,
1667 "not sending last_committed update");
1669 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
1671 mds->mds_last_transno, obd->obd_last_committed,
1676 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1677 if (obd && obd->obd_recovering) {
1678 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1679 return target_queue_final_reply(req, rc);
1681 /* Lost a race with recovery; let the error path DTRT. */
1682 rc = req->rq_status = -ENOTCONN;
1685 target_send_reply(req, rc, fail);
1689 /* Update the server data on disk. This stores the new mount_count and
1690 * also the last_rcvd value to disk. If we don't have a clean shutdown,
1691 * then the server last_rcvd value may be less than that of the clients.
1692 * This will alert us that we may need to do client recovery.
1694 * Also assumes for mds_last_transno that we are not modifying it (no locking).
1696 int mds_update_server_data(struct obd_device *obd, int force_sync)
1698 struct mds_obd *mds = &obd->u.mds;
1699 struct mds_server_data *msd = mds->mds_server_data;
1700 struct file *filp = mds->mds_rcvd_filp;
1701 struct obd_run_ctxt saved;
1706 push_ctxt(&saved, &obd->obd_ctxt, NULL);
1707 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
1709 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
1710 mds->mds_mount_count, mds->mds_last_transno);
1711 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off,force_sync);
1713 CERROR("error writing MDS server data: rc = %d\n", rc);
1714 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
1720 /* mount the file system (secretly) */
1721 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
1723 struct lustre_cfg* lcfg = buf;
1724 struct mds_obd *mds = &obd->u.mds;
1725 struct vfsmount *mnt;
1730 dev_clear_rdonly(2);
1732 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
1733 RETURN(rc = -EINVAL);
1735 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
1736 if (IS_ERR(obd->obd_fsops))
1737 RETURN(rc = PTR_ERR(obd->obd_fsops));
1739 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
1741 /* we have to know mdsnum before touching underlying fs -bzzz */
1742 if (lcfg->lcfg_inllen4 > 0 && lcfg->lcfg_inlbuf4) {
1745 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
1746 obd->obd_name, lcfg->lcfg_inlbuf4);
1748 generate_random_uuid(uuid);
1749 class_uuid_unparse(uuid, &mds->mds_lmv_uuid);
1751 OBD_ALLOC(mds->mds_lmv_name, lcfg->lcfg_inllen4);
1752 if (mds->mds_lmv_name == NULL)
1753 RETURN(rc = -ENOMEM);
1755 memcpy(mds->mds_lmv_name, lcfg->lcfg_inlbuf4,
1756 lcfg->lcfg_inllen4);
1757 rc = mds_lmv_connect(obd, mds->mds_lmv_name);
1759 OBD_FREE(mds->mds_lmv_name, lcfg->lcfg_inllen4);
1764 if (!(page = __get_free_page(GFP_KERNEL)))
1767 memset((void *)page, 0, PAGE_SIZE);
1768 sprintf((char *)page, "iopen_nopriv");
1770 mnt = do_kern_mount(lcfg->lcfg_inlbuf2, 0,
1771 lcfg->lcfg_inlbuf1, (void *)page);
1775 CERROR("do_kern_mount failed: rc = %d\n", rc);
1779 CDEBUG(D_SUPER, "%s: mnt = %p\n", lcfg->lcfg_inlbuf1, mnt);
1781 sema_init(&mds->mds_orphan_recovery_sem, 1);
1782 sema_init(&mds->mds_epoch_sem, 1);
1783 spin_lock_init(&mds->mds_transno_lock);
1784 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
1785 atomic_set(&mds->mds_open_count, 0);
1786 atomic_set(&mds->mds_real_clients, 0);
1788 obd->obd_namespace = ldlm_namespace_new(obd->obd_name,
1789 LDLM_NAMESPACE_SERVER);
1790 if (obd->obd_namespace == NULL) {
1791 mds_cleanup(obd, 0);
1792 GOTO(err_put, rc = -ENOMEM);
1794 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
1796 rc = mds_fs_setup(obd, mnt);
1798 CERROR("MDS filesystem method init failed: rc = %d\n", rc);
1802 rc = llog_start_commit_thread();
1807 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3) {
1810 generate_random_uuid(uuid);
1811 class_uuid_unparse(uuid, &mds->mds_lov_uuid);
1813 OBD_ALLOC(mds->mds_profile, lcfg->lcfg_inllen3);
1814 if (mds->mds_profile == NULL)
1815 GOTO(err_fs, rc = -ENOMEM);
1817 memcpy(mds->mds_profile, lcfg->lcfg_inlbuf3,
1818 lcfg->lcfg_inllen3);
1821 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1822 "mds_ldlm_client", &obd->obd_ldlm_client);
1823 obd->obd_replayable = 1;
1825 rc = mds_postsetup(obd);
1831 /* No extra cleanup needed for llog_init_commit_thread() */
1832 mds_fs_cleanup(obd, 0);
1834 ldlm_namespace_free(obd->obd_namespace, 0);
1835 obd->obd_namespace = NULL;
1838 mntput(mds->mds_vfsmnt);
1842 fsfilt_put_ops(obd->obd_fsops);
1846 static int mds_postsetup(struct obd_device *obd)
1848 struct mds_obd *mds = &obd->u.mds;
1849 struct llog_ctxt *ctxt;
1853 rc = llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
1854 obd, 0, NULL, &llog_lvfs_ops);
1858 if (mds->mds_profile) {
1859 struct obd_run_ctxt saved;
1860 struct lustre_profile *lprof;
1861 struct config_llog_instance cfg;
1863 cfg.cfg_instance = NULL;
1864 cfg.cfg_uuid = mds->mds_lov_uuid;
1865 push_ctxt(&saved, &obd->obd_ctxt, NULL);
1866 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
1867 rc = class_config_parse_llog(ctxt, mds->mds_profile, &cfg);
1868 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
1872 lprof = class_get_profile(mds->mds_profile);
1873 if (lprof == NULL) {
1874 CERROR("No profile found: %s\n", mds->mds_profile);
1875 GOTO(err_cleanup, rc = -ENOENT);
1877 rc = mds_lov_connect(obd, lprof->lp_osc);
1879 GOTO(err_cleanup, rc);
1881 rc = mds_lmv_postsetup(obd);
1883 GOTO(err_cleanup, rc);
1891 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
1896 static int mds_postrecov(struct obd_device *obd)
1899 struct llog_ctxt *ctxt;
1903 LASSERT(!obd->obd_recovering);
1904 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
1905 LASSERT(ctxt != NULL);
1907 rc = llog_connect(ctxt, obd->u.mds.mds_lov_desc.ld_tgt_count,
1910 CERROR("faild at llog_origin_connect: %d\n", rc);
1913 rc = mds_cleanup_orphans(obd);
1915 rc2 = mds_lov_set_nextid(obd);
1921 int mds_lov_clean(struct obd_device *obd)
1923 struct mds_obd *mds = &obd->u.mds;
1924 struct llog_ctxt *ctxt;
1926 if (mds->mds_profile) {
1928 struct config_llog_instance cfg;
1929 struct obd_run_ctxt saved;
1930 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
1932 OBD_ALLOC(cln_prof, len);
1933 sprintf(cln_prof, "%s-clean", mds->mds_profile);
1935 cfg.cfg_instance = NULL;
1936 cfg.cfg_uuid = mds->mds_lov_uuid;
1938 push_ctxt(&saved, &obd->obd_ctxt, NULL);
1939 ctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
1940 class_config_parse_llog(ctxt, cln_prof, &cfg);
1941 pop_ctxt(&saved, &obd->obd_ctxt, NULL);
1943 OBD_FREE(cln_prof, len);
1944 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
1945 mds->mds_profile = NULL;
1950 int mds_lmv_clean(struct obd_device *obd)
1952 struct mds_obd *mds = &obd->u.mds;
1954 if (mds->mds_lmv_name) {
1955 OBD_FREE(mds->mds_lmv_name, strlen(mds->mds_lmv_name) + 1);
1956 mds->mds_lmv_name = NULL;
1961 static int mds_precleanup(struct obd_device *obd, int flags)
1967 mds_lov_disconnect(obd, flags);
1969 llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
1973 static int mds_cleanup(struct obd_device *obd, int flags)
1975 struct mds_obd *mds = &obd->u.mds;
1978 if (mds->mds_sb == NULL)
1981 mds_update_server_data(obd, 1);
1982 if (mds->mds_lov_objids != NULL) {
1983 OBD_FREE(mds->mds_lov_objids,
1984 mds->mds_lov_desc.ld_tgt_count * sizeof(obd_id));
1986 mds_fs_cleanup(obd, flags);
1990 /* 2 seems normal on mds, (may_umount() also expects 2
1991 fwiw), but we only see 1 at this point in obdfilter. */
1992 if (atomic_read(&obd->u.mds.mds_vfsmnt->mnt_count) > 2)
1993 CERROR("%s: mount busy, mnt_count %d != 2\n", obd->obd_name,
1994 atomic_read(&obd->u.mds.mds_vfsmnt->mnt_count));
1996 mntput(mds->mds_vfsmnt);
2000 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
2002 spin_lock_bh(&obd->obd_processing_task_lock);
2003 if (obd->obd_recovering) {
2004 target_cancel_recovery_timer(obd);
2005 obd->obd_recovering = 0;
2007 spin_unlock_bh(&obd->obd_processing_task_lock);
2010 dev_clear_rdonly(2);
2011 fsfilt_put_ops(obd->obd_fsops);
2016 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
2017 struct ldlm_lock *new_lock,
2018 struct lustre_handle *lockh)
2020 struct obd_export *exp = req->rq_export;
2021 struct obd_device *obd = exp->exp_obd;
2022 struct ldlm_request *dlmreq =
2023 lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*dlmreq));
2024 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
2025 struct list_head *iter;
2027 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2030 l_lock(&obd->obd_namespace->ns_lock);
2031 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2032 struct ldlm_lock *lock;
2033 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2034 if (lock == new_lock)
2036 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2037 lockh->cookie = lock->l_handle.h_cookie;
2038 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
2040 l_unlock(&obd->obd_namespace->ns_lock);
2044 l_unlock(&obd->obd_namespace->ns_lock);
2046 /* This remote handle isn't enqueued, so we never received or
2047 * processed this request. Clear MSG_RESENT, because it can
2048 * be handled like any normal request now. */
2050 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2052 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
2056 int intent_disposition(struct ldlm_reply *rep, int flag)
2060 return (rep->lock_policy_res1 & flag);
2063 void intent_set_disposition(struct ldlm_reply *rep, int flag)
2067 rep->lock_policy_res1 |= flag;
2070 static int mds_intent_policy(struct ldlm_namespace *ns,
2071 struct ldlm_lock **lockp, void *req_cookie,
2072 ldlm_mode_t mode, int flags, void *data)
2074 struct ptlrpc_request *req = req_cookie;
2075 struct ldlm_lock *lock = *lockp;
2076 struct ldlm_intent *it;
2077 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
2078 struct ldlm_reply *rep;
2079 struct lustre_handle lockh = { 0 };
2080 struct ldlm_lock *new_lock;
2081 int getattr_part = MDS_INODELOCK_UPDATE;
2082 int rc, offset = 2, repsize[4] = {sizeof(struct ldlm_reply),
2083 sizeof(struct mds_body),
2084 mds->mds_max_mdsize,
2085 mds->mds_max_cookiesize};
2088 LASSERT(req != NULL);
2090 if (req->rq_reqmsg->bufcount <= 1) {
2091 /* No intent was provided */
2092 int size = sizeof(struct ldlm_reply);
2093 rc = lustre_pack_reply(req, 1, &size, NULL);
2098 it = lustre_swab_reqbuf(req, 1, sizeof(*it), lustre_swab_ldlm_intent);
2100 CERROR("Intent missing\n");
2101 RETURN(req->rq_status = -EFAULT);
2104 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
2106 rc = lustre_pack_reply(req, it->opc == IT_UNLINK ? 4 : 3, repsize,
2109 RETURN(req->rq_status = rc);
2111 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
2112 intent_set_disposition(rep, DISP_IT_EXECD);
2114 fixup_handle_for_resent_req(req, lock, &lockh);
2116 /* execute policy */
2117 switch ((long)it->opc) {
2119 case IT_CREAT|IT_OPEN:
2120 /* XXX swab here to assert that an mds_open reint
2121 * packet is following */
2122 rep->lock_policy_res2 = mds_reint(req, offset, &lockh);
2124 /* We abort the lock if the lookup was negative and
2125 * we did not make it to the OPEN portion */
2126 if (!intent_disposition(rep, DISP_LOOKUP_EXECD))
2127 RETURN(ELDLM_LOCK_ABORTED);
2128 if (intent_disposition(rep, DISP_LOOKUP_NEG) &&
2129 !intent_disposition(rep, DISP_OPEN_OPEN))
2131 if (rep->lock_policy_res2) {
2132 /* mds_open returns ENOLCK where it
2133 * should return zero, but it has no
2135 if (rep->lock_policy_res2 == ENOLCK)
2136 rep->lock_policy_res2 = 0;
2137 RETURN(ELDLM_LOCK_ABORTED);
2141 getattr_part = MDS_INODELOCK_LOOKUP;
2143 getattr_part |= MDS_INODELOCK_LOOKUP;
2145 rep->lock_policy_res2 = mds_getattr_name(offset, req, &lockh,
2147 /* FIXME: LDLM can set req->rq_status. MDS sets
2148 policy_res{1,2} with disposition and status.
2149 - replay: returns 0 & req->status is old status
2150 - otherwise: returns req->status */
2151 if (intent_disposition(rep, DISP_LOOKUP_NEG))
2152 rep->lock_policy_res2 = 0;
2153 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
2154 rep->lock_policy_res2)
2155 RETURN(ELDLM_LOCK_ABORTED);
2156 if (req->rq_status != 0) {
2158 rep->lock_policy_res2 = req->rq_status;
2159 RETURN(ELDLM_LOCK_ABORTED);
2163 CERROR("Unhandled intent "LPD64"\n", it->opc);
2167 /* By this point, whatever function we called above must have either
2168 * filled in 'lockh', been an intent replay, or returned an error. We
2169 * want to allow replayed RPCs to not get a lock, since we would just
2170 * drop it below anyways because lock replay is done separately by the
2171 * client afterwards. For regular RPCs we want to give the new lock to
2172 * the client instead of whatever lock it was about to get. */
2173 new_lock = ldlm_handle2lock(&lockh);
2174 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
2177 LASSERT(new_lock != NULL);
2179 /* If we've already given this lock to a client once, then we should
2180 * have no readers or writers. Otherwise, we should have one reader
2181 * _or_ writer ref (which will be zeroed below) before returning the
2182 * lock to a client. */
2183 if (new_lock->l_export == req->rq_export) {
2184 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2186 LASSERT(new_lock->l_export == NULL);
2187 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2192 if (new_lock->l_export == req->rq_export) {
2193 /* Already gave this to the client, which means that we
2194 * reconstructed a reply. */
2195 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2197 RETURN(ELDLM_LOCK_REPLACED);
2200 /* Fixup the lock to be given to the client */
2201 l_lock(&new_lock->l_resource->lr_namespace->ns_lock);
2202 new_lock->l_readers = 0;
2203 new_lock->l_writers = 0;
2205 new_lock->l_export = class_export_get(req->rq_export);
2206 list_add(&new_lock->l_export_chain,
2207 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2209 new_lock->l_blocking_ast = lock->l_blocking_ast;
2210 new_lock->l_completion_ast = lock->l_completion_ast;
2212 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
2213 sizeof(lock->l_remote_handle));
2215 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2217 LDLM_LOCK_PUT(new_lock);
2218 l_unlock(&new_lock->l_resource->lr_namespace->ns_lock);
2220 RETURN(ELDLM_LOCK_REPLACED);
2223 int mds_attach(struct obd_device *dev, obd_count len, void *data)
2225 struct lprocfs_static_vars lvars;
2227 lprocfs_init_multi_vars(0, &lvars);
2228 return lprocfs_obd_attach(dev, lvars.obd_vars);
2231 int mds_detach(struct obd_device *dev)
2233 return lprocfs_obd_detach(dev);
2236 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
2238 struct lprocfs_static_vars lvars;
2240 lprocfs_init_multi_vars(1, &lvars);
2241 return lprocfs_obd_attach(dev, lvars.obd_vars);
2244 int mdt_detach(struct obd_device *dev)
2246 return lprocfs_obd_detach(dev);
2249 static int mdt_setup(struct obd_device *obddev, obd_count len, void *buf)
2251 struct mds_obd *mds = &obddev->u.mds;
2256 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2257 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
2259 obddev->obd_proc_entry);
2261 if (!mds->mds_service) {
2262 CERROR("failed to start service\n");
2263 RETURN(rc = -ENOMEM);
2266 rc = ptlrpc_start_n_threads(obddev, mds->mds_service, MDT_NUM_THREADS,
2269 GOTO(err_thread, rc);
2271 mds->mds_setattr_service =
2272 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2273 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
2274 mds_handle, "mds_setattr",
2275 obddev->obd_proc_entry);
2276 if (!mds->mds_setattr_service) {
2277 CERROR("failed to start getattr service\n");
2278 GOTO(err_thread, rc = -ENOMEM);
2281 rc = ptlrpc_start_n_threads(obddev, mds->mds_setattr_service,
2282 MDT_NUM_THREADS, "ll_mdt_attr");
2284 GOTO(err_thread2, rc);
2286 mds->mds_readpage_service =
2287 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2288 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
2289 mds_handle, "mds_readpage",
2290 obddev->obd_proc_entry);
2291 if (!mds->mds_readpage_service) {
2292 CERROR("failed to start readpage service\n");
2293 GOTO(err_thread2, rc = -ENOMEM);
2296 rc = ptlrpc_start_n_threads(obddev, mds->mds_readpage_service,
2297 MDT_NUM_THREADS, "ll_mdt_rdpg");
2300 GOTO(err_thread3, rc);
2305 ptlrpc_unregister_service(mds->mds_readpage_service);
2307 ptlrpc_unregister_service(mds->mds_setattr_service);
2309 ptlrpc_unregister_service(mds->mds_service);
2314 static int mdt_cleanup(struct obd_device *obddev, int flags)
2316 struct mds_obd *mds = &obddev->u.mds;
2319 ptlrpc_stop_all_threads(mds->mds_readpage_service);
2320 ptlrpc_unregister_service(mds->mds_readpage_service);
2322 ptlrpc_stop_all_threads(mds->mds_setattr_service);
2323 ptlrpc_unregister_service(mds->mds_setattr_service);
2325 ptlrpc_stop_all_threads(mds->mds_service);
2326 ptlrpc_unregister_service(mds->mds_service);
2331 static struct dentry *mds_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr, void *data)
2333 struct obd_device *obd = data;
2336 fid.generation = gen;
2337 return mds_fid2dentry(&obd->u.mds, &fid, NULL);
2340 struct lvfs_callback_ops mds_lvfs_ops = {
2341 l_fid2dentry: mds_lvfs_fid2dentry,
2344 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
2345 int objcount, struct obd_ioobj *obj,
2346 int niocount, struct niobuf_remote *nb,
2347 struct niobuf_local *res,
2348 struct obd_trans_info *oti);
2349 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
2350 int objcount, struct obd_ioobj *obj, int niocount,
2351 struct niobuf_local *res, struct obd_trans_info *oti,
2354 /* use obd ops to offer management infrastructure */
2355 static struct obd_ops mds_obd_ops = {
2356 o_owner: THIS_MODULE,
2357 o_attach: mds_attach,
2358 o_detach: mds_detach,
2359 o_connect: mds_connect,
2360 o_init_export: mds_init_export,
2361 o_destroy_export: mds_destroy_export,
2362 o_disconnect: mds_disconnect,
2364 o_precleanup: mds_precleanup,
2365 o_cleanup: mds_cleanup,
2366 o_postrecov: mds_postrecov,
2367 o_statfs: mds_obd_statfs,
2368 o_iocontrol: mds_iocontrol,
2369 o_create: mds_obd_create,
2370 o_destroy: mds_obd_destroy,
2371 o_llog_init: mds_llog_init,
2372 o_llog_finish: mds_llog_finish,
2373 o_notify: mds_notify,
2374 o_get_info: mds_get_info,
2375 o_set_info: mds_set_info,
2376 o_preprw: mds_preprw,
2377 o_commitrw: mds_commitrw,
2380 static struct obd_ops mdt_obd_ops = {
2381 o_owner: THIS_MODULE,
2382 o_attach: mdt_attach,
2383 o_detach: mdt_detach,
2385 o_cleanup: mdt_cleanup,
2388 static int __init mds_init(void)
2390 struct lprocfs_static_vars lvars;
2392 lprocfs_init_multi_vars(0, &lvars);
2393 class_register_type(&mds_obd_ops, NULL, lvars.module_vars, LUSTRE_MDS_NAME);
2394 lprocfs_init_multi_vars(1, &lvars);
2395 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars, LUSTRE_MDT_NAME);
2400 static void /*__exit*/ mds_exit(void)
2402 class_unregister_type(LUSTRE_MDS_NAME);
2403 class_unregister_type(LUSTRE_MDT_NAME);
2406 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2407 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
2408 MODULE_LICENSE("GPL");
2410 module_init(mds_init);
2411 module_exit(mds_exit);