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/namei.h>
43 #include <linux/ext3_fs.h>
44 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
45 # include <linux/smp_lock.h>
46 # include <linux/buffer_head.h>
47 # include <linux/workqueue.h>
48 # include <linux/mount.h>
50 # include <linux/locks.h>
52 #include <linux/obd_lov.h>
53 #include <linux/obd_ost.h>
54 #include <linux/lustre_mds.h>
55 #include <linux/lustre_fsfilt.h>
56 #include <linux/lprocfs_status.h>
57 #include <linux/lustre_commit_confd.h>
59 #include <linux/lustre_acl.h>
60 #include "mds_internal.h"
62 static int mds_intent_policy(struct ldlm_namespace *ns,
63 struct ldlm_lock **lockp, void *req_cookie,
64 ldlm_mode_t mode, int flags, void *data);
65 static int mds_postsetup(struct obd_device *obd);
66 static int mds_cleanup(struct obd_device *obd, int flags);
69 /* Assumes caller has already pushed into the kernel filesystem context */
70 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
71 loff_t offset, int count)
73 struct ptlrpc_bulk_desc *desc;
74 struct l_wait_info lwi;
76 int rc = 0, npages, i, tmpcount, tmpsize = 0;
79 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
81 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
82 OBD_ALLOC(pages, sizeof(*pages) * npages);
84 GOTO(out, rc = -ENOMEM);
86 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
89 GOTO(out_free, rc = -ENOMEM);
91 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
92 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
94 pages[i] = alloc_pages(GFP_KERNEL, 0);
96 GOTO(cleanup_buf, rc = -ENOMEM);
98 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
101 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
102 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
103 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
104 tmpsize, offset, file->f_dentry->d_inode->i_ino,
105 file->f_dentry->d_inode->i_size);
107 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
108 kmap(pages[i]), tmpsize, &offset);
112 GOTO(cleanup_buf, rc = -EIO);
115 LASSERT(desc->bd_nob == count);
117 rc = ptlrpc_start_bulk_transfer(desc);
119 GOTO(cleanup_buf, rc);
121 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
122 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
123 OBD_FAIL_MDS_SENDPAGE, rc = -EIO);
124 GOTO(abort_bulk, rc);
127 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
128 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
129 LASSERT (rc == 0 || rc == -ETIMEDOUT);
132 if (desc->bd_success &&
133 desc->bd_nob_transferred == count)
134 GOTO(cleanup_buf, rc);
136 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
139 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
140 (rc == -ETIMEDOUT) ? "timeout" : "network error",
141 desc->bd_nob_transferred, count,
142 req->rq_export->exp_client_uuid.uuid,
143 req->rq_export->exp_connection->c_remote_uuid.uuid);
145 ptlrpc_fail_export(req->rq_export);
149 ptlrpc_abort_bulk (desc);
151 for (i = 0; i < npages; i++)
153 __free_pages(pages[i], 0);
155 ptlrpc_free_bulk(desc);
157 OBD_FREE(pages, sizeof(*pages) * npages);
162 extern char *ldlm_lockname[];
164 int mds_lock_mode_for_dir(struct obd_device *obd,
165 struct dentry *dentry, int mode)
167 int ret_mode = 0, split;
169 /* any dir access needs couple locks:
170 * 1) on part of dir we gonna lookup/modify in
171 * 2) on a whole dir to protect it from concurrent splitting
172 * and to flush client's cache for readdir()
173 * so, for a given mode and dentry this routine decides what
174 * lock mode to use for lock #2:
175 * 1) if caller's gonna lookup in dir then we need to protect
176 * dir from being splitted only - LCK_CR
177 * 2) if caller's gonna modify dir then we need to protect
178 * dir from being splitted and to flush cache - LCK_CW
179 * 3) if caller's gonna modify dir and that dir seems ready
180 * for splitting then we need to protect it from any
181 * type of access (lookup/modify/split) - LCK_EX -bzzz */
183 split = mds_splitting_expected(obd, dentry);
186 * it is important to check here only for MDS_NO_SPLITTABLE. The reason
187 * is that MDS_NO_SPLITTABLE means dir is not splittable in principle
188 * and another thread will not split it on the quiet. But if we have
189 * MDS_NO_SPLIT_EXPECTED, this means, that dir may be splitted anytime,
190 * but not now (for current thread) and we should consider that it can
191 * happen soon and go that branch which can yield LCK_EX to protect from
192 * possible splitting.
194 if (split == MDS_NO_SPLITTABLE) {
196 * this inode won't be splitted. so we need not to protect from
197 * just flush client's cache on modification.
204 if (mode == LCK_EX) {
206 } else if (mode == LCK_PR) {
208 } else if (mode == LCK_PW) {
210 * caller gonna modify directory. We use concurrent
211 * write lock here to retract client's cache for
214 if (split == MDS_EXPECT_SPLIT) {
216 * splitting possible. serialize any access the
217 * idea is that first one seen dir is splittable
218 * is given exclusive lock and split
219 * directory. caller passes lock mode to
220 * mds_try_to_split_dir() and splitting would be
221 * done with exclusive lock only -bzzz.
223 CDEBUG(D_OTHER, "%s: gonna split %lu/%lu\n",
225 (unsigned long)dentry->d_inode->i_ino,
226 (unsigned long)dentry->d_inode->i_generation);
237 /* only valid locked dentries or errors should be returned */
238 struct dentry *mds_id2locked_dentry(struct obd_device *obd, struct lustre_id *id,
239 struct vfsmount **mnt, int lock_mode,
240 struct lustre_handle *lockh, int *mode,
241 char *name, int namelen, __u64 lockpart)
243 struct dentry *de = mds_id2dentry(obd, id, mnt), *retval = de;
244 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
245 struct ldlm_res_id res_id = { .name = {0} };
253 res_id.name[0] = id_fid(id);
254 res_id.name[1] = id_group(id);
257 if (name && IS_PDIROPS(de->d_inode)) {
258 ldlm_policy_data_t cpolicy =
259 { .l_inodebits = { MDS_INODELOCK_UPDATE } };
260 LASSERT(mode != NULL);
261 *mode = mds_lock_mode_for_dir(obd, de, lock_mode);
263 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
265 &cpolicy, *mode, &flags,
267 ldlm_completion_ast, NULL, NULL,
268 NULL, 0, NULL, lockh + 1);
269 if (rc != ELDLM_OK) {
271 RETURN(ERR_PTR(-ENOLCK));
276 res_id.name[2] = full_name_hash(name, namelen);
278 CDEBUG(D_INFO, "take lock on "DLID4":"LPX64"\n",
279 OLID4(id), res_id.name[2]);
282 #warning "No PDIROPS support in the kernel"
284 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
285 LDLM_IBITS, &policy, lock_mode, &flags,
286 mds_blocking_ast, ldlm_completion_ast,
287 NULL, NULL, NULL, 0, NULL, lockh);
288 if (rc != ELDLM_OK) {
290 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
293 ldlm_lock_decref(lockh + 1, *mode);
300 #ifndef DCACHE_DISCONNECTED
301 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
304 /* Look up an entry by inode number. This function ONLY returns valid dget'd
305 * dentries with an initialized inode or errors */
306 struct dentry *mds_id2dentry(struct obd_device *obd, struct lustre_id *id,
307 struct vfsmount **mnt)
309 unsigned long ino = (unsigned long)id_ino(id);
310 __u32 generation = (__u32)id_gen(id);
311 struct mds_obd *mds = &obd->u.mds;
312 struct dentry *result;
317 RETURN(ERR_PTR(-ESTALE));
319 snprintf(idname, sizeof(idname), "0x%lx", ino);
321 CDEBUG(D_DENTRY, "--> mds_id2dentry: ino/gen %lu/%u, sb %p\n",
322 ino, generation, mds->mds_sb);
324 /* under ext3 this is neither supposed to return bad inodes nor NULL
326 result = ll_lookup_one_len(idname, mds->mds_id_de,
331 inode = result->d_inode;
333 RETURN(ERR_PTR(-ENOENT));
335 if (is_bad_inode(inode)) {
336 CERROR("bad inode returned %lu/%u\n",
337 inode->i_ino, inode->i_generation);
339 RETURN(ERR_PTR(-ENOENT));
342 /* here we disabled generation check, as root inode i_generation
343 * of cache mds and real mds are different. */
344 if (inode->i_ino != id_ino(&mds->mds_rootid) && generation &&
345 inode->i_generation != generation) {
346 /* we didn't find the right inode.. */
347 CERROR("bad inode %lu, link: %lu, ct: %d, generation %u/%u\n",
348 inode->i_ino, (unsigned long)inode->i_nlink,
349 atomic_read(&inode->i_count), inode->i_generation,
352 RETURN(ERR_PTR(-ENOENT));
356 *mnt = mds->mds_vfsmnt;
364 /* Establish a connection to the MDS.
366 * This will set up an export structure for the client to hold state data about
367 * that client, like open files, the last operation number it did on the server,
370 static int mds_connect(struct lustre_handle *conn, struct obd_device *obd,
371 struct obd_uuid *cluuid, unsigned long flags)
373 struct mds_export_data *med;
374 struct mds_client_data *mcd;
375 struct obd_export *exp;
379 if (!conn || !obd || !cluuid)
382 /* XXX There is a small race between checking the list and adding a new
383 * connection for the same UUID, but the real threat (list corruption
384 * when multiple different clients connect) is solved.
386 * There is a second race between adding the export to the list, and
387 * filling in the client data below. Hence skipping the case of NULL
388 * mcd above. We should already be controlling multiple connects at the
389 * client, and we can't hold the spinlock over memory allocations
390 * without risk of deadlocking.
392 rc = class_connect(conn, obd, cluuid);
395 exp = class_conn2export(conn);
397 LASSERT(exp != NULL);
398 med = &exp->exp_mds_data;
400 OBD_ALLOC(mcd, sizeof(*mcd));
402 CERROR("%s: out of memory for client data.\n",
404 GOTO(out, rc = -ENOMEM);
407 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
410 rc = mds_client_add(obd, &obd->u.mds, med, -1);
418 OBD_FREE(mcd, sizeof(*mcd));
419 class_disconnect(exp, 0);
421 class_export_put(exp);
426 static int mds_connect_post(struct obd_export *exp, unsigned long flags)
428 struct obd_device *obd = exp->exp_obd;
429 struct mds_obd *mds = &obd->u.mds;
433 if (!(flags & OBD_OPT_MDS_CONNECTION)) {
434 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
435 atomic_inc(&mds->mds_real_clients);
436 CDEBUG(D_OTHER,"%s: peer from %s is real client (%d)\n",
437 obd->obd_name, exp->exp_client_uuid.uuid,
438 atomic_read(&mds->mds_real_clients));
439 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
441 if (mds->mds_md_name)
442 rc = mds_md_connect(obd, mds->mds_md_name);
447 static int mds_init_export(struct obd_export *exp)
449 struct mds_export_data *med = &exp->exp_mds_data;
451 INIT_LIST_HEAD(&med->med_open_head);
452 spin_lock_init(&med->med_open_lock);
456 static int mds_destroy_export(struct obd_export *export)
458 struct obd_device *obd = export->exp_obd;
459 struct mds_export_data *med;
460 struct lvfs_run_ctxt saved;
464 med = &export->exp_mds_data;
465 target_destroy_export(export);
467 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
470 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
472 /* Close any open files (which may also cause orphan unlinking). */
473 spin_lock(&med->med_open_lock);
474 while (!list_empty(&med->med_open_head)) {
475 struct list_head *tmp = med->med_open_head.next;
476 struct mds_file_data *mfd =
477 list_entry(tmp, struct mds_file_data, mfd_list);
478 struct lustre_id sid;
480 BDEVNAME_DECLARE_STORAGE(btmp);
482 /* bug 1579: fix force-closing for 2.5 */
483 struct dentry *dentry = mfd->mfd_dentry;
485 list_del(&mfd->mfd_list);
486 spin_unlock(&med->med_open_lock);
488 down(&dentry->d_inode->i_sem);
489 rc = mds_read_inode_sid(obd, dentry->d_inode, &sid);
490 up(&dentry->d_inode->i_sem);
492 CERROR("Can't read inode self id, inode %lu, "
493 "rc %d\n", dentry->d_inode->i_ino, rc);
494 memset(&sid, 0, sizeof(sid));
497 /* If you change this message, be sure to update
498 * replay_single:test_46 */
499 CERROR("force closing client file handle for %.*s (%s:"
500 DLID4")\n", dentry->d_name.len, dentry->d_name.name,
501 ll_bdevname(dentry->d_inode->i_sb, btmp),
504 /* child inode->i_alloc_sem protects orphan_dec_test and
505 * is_orphan race, mds_mfd_close drops it */
506 DOWN_WRITE_I_ALLOC_SEM(dentry->d_inode);
507 rc = mds_mfd_close(NULL, 0, obd, mfd,
508 !(export->exp_flags & OBD_OPT_FAILOVER));
510 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
511 spin_lock(&med->med_open_lock);
513 spin_unlock(&med->med_open_lock);
514 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
518 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
522 static int mds_disconnect(struct obd_export *exp, unsigned long flags)
524 unsigned long irqflags;
525 struct obd_device *obd;
530 LASSERT(exp != NULL);
531 obd = class_exp2obd(exp);
533 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
534 exp->exp_handle.h_cookie);
540 * suppress any inter-mds requests durring disconnecting lmv if this is
541 * detected --force mode. This is needed to avoid endless recovery.
543 if (atomic_read(&mds->mds_real_clients) > 0 &&
544 !(exp->exp_flags & OBD_OPT_REAL_CLIENT))
545 flags |= OBD_OPT_FORCE;
547 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
548 && !atomic_read(&mds->mds_real_clients)) {
549 /* there was no client at all */
550 mds_md_disconnect(obd, flags);
553 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
554 && atomic_dec_and_test(&mds->mds_real_clients)) {
555 /* time to drop LMV connections */
556 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
557 "Disconnnect from LMV now\n",
558 obd->obd_name, exp->exp_client_uuid.uuid);
559 mds_md_disconnect(obd, flags);
562 spin_lock_irqsave(&exp->exp_lock, irqflags);
563 exp->exp_flags = flags;
564 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
566 /* disconnect early so that clients can't keep using export */
567 rc = class_disconnect(exp, flags);
568 ldlm_cancel_locks_for_export(exp);
570 /* complete all outstanding replies */
571 spin_lock_irqsave(&exp->exp_lock, irqflags);
572 while (!list_empty(&exp->exp_outstanding_replies)) {
573 struct ptlrpc_reply_state *rs =
574 list_entry(exp->exp_outstanding_replies.next,
575 struct ptlrpc_reply_state, rs_exp_list);
576 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
578 spin_lock(&svc->srv_lock);
579 list_del_init(&rs->rs_exp_list);
580 ptlrpc_schedule_difficult_reply(rs);
581 spin_unlock(&svc->srv_lock);
583 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
587 static int mds_getstatus(struct ptlrpc_request *req)
589 struct mds_obd *mds = mds_req2mds(req);
590 struct mds_body *body;
594 size = sizeof(*body);
596 rc = lustre_pack_reply(req, 1, &size, NULL);
597 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
598 CERROR("mds: out of memory for message: size=%d\n", size);
599 req->rq_status = -ENOMEM; /* superfluous? */
603 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
604 body->valid |= OBD_MD_FID;
606 memcpy(&body->id1, &mds->mds_rootid, sizeof(body->id1));
609 * the last_committed and last_xid fields are filled in for all replies
610 * already - no need to do so here also.
615 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
616 void *data, int flag)
621 if (flag == LDLM_CB_CANCELING) {
622 /* Don't need to do anything here. */
626 /* XXX layering violation! -phil */
627 l_lock(&lock->l_resource->lr_namespace->ns_lock);
630 * get this: if mds_blocking_ast is racing with mds_intent_policy, such
631 * that mds_blocking_ast is called just before l_i_p takes the ns_lock,
632 * then by the time we get the lock, we might not be the correct
633 * blocking function anymore. So check, and return early, if so.
635 if (lock->l_blocking_ast != mds_blocking_ast) {
636 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
640 lock->l_flags |= LDLM_FL_CBPENDING;
641 do_ast = (!lock->l_readers && !lock->l_writers);
642 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
645 struct lustre_handle lockh;
648 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
649 ldlm_lock2handle(lock, &lockh);
650 rc = ldlm_cli_cancel(&lockh);
652 CERROR("ldlm_cli_cancel: %d\n", rc);
654 LDLM_DEBUG(lock, "Lock still has references, will be "
660 static int mds_convert_md(struct obd_device *obd, struct inode *inode,
661 void *md, int size, int mea)
665 if (S_ISREG(inode->i_mode)) {
666 rc = mds_convert_lov_ea(obd, inode, md, size);
667 } else if (S_ISDIR(inode->i_mode)) {
669 rc = mds_convert_mea_ea(obd, inode, md, size);
671 rc = mds_convert_lov_ea(obd, inode, md, size);
674 CERROR("Invalid EA format (nor LOV or MEA) "
675 "is detected. Inode %lu/%u\n",
676 inode->i_ino, inode->i_generation);
682 int mds_get_md(struct obd_device *obd, struct inode *inode,
683 void *md, int *size, int lock, int mea)
692 rc = fsfilt_get_md(obd, inode, md, *size,
693 (mea ? EA_MEA : EA_LOV));
695 CERROR("Error %d reading eadata for ino %lu\n",
699 rc = mds_convert_md(obd, inode, md,
715 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
716 * Call with lock=0 if the caller has already taken the i_sem. */
717 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
718 struct mds_body *body, struct inode *inode, int lock, int mea)
720 struct mds_obd *mds = &obd->u.mds;
726 lmm = lustre_msg_buf(msg, offset, 0);
728 /* Some problem with getting eadata when I sized the reply
730 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
734 lmm_size = msg->buflens[offset];
736 /* I don't really like this, but it is a sanity check on the client
737 * MD request. However, if the client doesn't know how much space
738 * to reserve for the MD, it shouldn't be bad to have too much space.
740 if (lmm_size > mds->mds_max_mdsize) {
741 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
742 inode->i_ino, lmm_size, mds->mds_max_mdsize);
746 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, mea);
748 if (S_ISDIR(inode->i_mode))
749 body->valid |= OBD_MD_FLDIREA;
751 body->valid |= OBD_MD_FLEASIZE;
754 body->valid |= OBD_MD_MEA;
756 body->eadatasize = lmm_size;
762 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
763 struct mds_body *repbody, int reply_off)
765 struct inode *inode = dentry->d_inode;
770 symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
771 LASSERT(symname != NULL);
772 len = req->rq_repmsg->buflens[reply_off + 1];
774 rc = inode->i_op->readlink(dentry, symname, len);
776 CERROR("readlink failed: %d\n", rc);
777 } else if (rc != len - 1) {
778 CERROR ("Unexpected readlink rc %d: expecting %d\n",
782 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
783 repbody->valid |= OBD_MD_LINKNAME;
784 repbody->eadatasize = rc + 1;
785 symname[rc] = 0; /* NULL terminate */
792 int mds_pack_ea(struct dentry *dentry, struct ptlrpc_request *req,
793 struct mds_body *repbody, int req_off, int reply_off)
795 struct inode *inode = dentry->d_inode;
801 ea_name = lustre_msg_string(req->rq_reqmsg, req_off + 1, 0);
802 len = req->rq_repmsg->buflens[reply_off + 1];
804 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
807 if (inode->i_op && inode->i_op->getxattr)
808 rc = inode->i_op->getxattr(dentry, ea_name, value, len);
811 if (rc != -ENODATA && rc != -EOPNOTSUPP)
812 CERROR("getxattr failed: %d", rc);
814 repbody->valid |= OBD_MD_FLEA;
815 repbody->eadatasize = rc;
822 int mds_pack_ealist(struct dentry *dentry, struct ptlrpc_request *req,
823 struct mds_body *repbody, int reply_off)
825 struct inode *inode = dentry->d_inode;
830 len = req->rq_repmsg->buflens[reply_off + 1];
832 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
835 if (inode->i_op && inode->i_op->getxattr)
836 rc = inode->i_op->listxattr(dentry, value, len);
839 CERROR("listxattr failed: %d", rc);
841 repbody->valid |= OBD_MD_FLEALIST;
842 repbody->eadatasize = rc;
848 int mds_pack_acl(struct obd_device *obd, struct lustre_msg *repmsg, int offset,
849 struct mds_body *body, struct inode *inode)
851 struct dentry de = { .d_inode = inode };
852 __u32 buflen, *sizep;
857 if (!inode->i_op->getxattr)
860 buflen = repmsg->buflens[offset + 1];
861 buf = lustre_msg_buf(repmsg, offset + 1, buflen);
863 size = inode->i_op->getxattr(&de, XATTR_NAME_ACL_ACCESS, buf, buflen);
864 if (size == -ENODATA || size == -EOPNOTSUPP)
870 sizep = lustre_msg_buf(repmsg, offset, 4);
872 CERROR("can't locate returned acl size buf\n");
876 *sizep = cpu_to_le32(size);
877 body->valid |= OBD_MD_FLACL_ACCESS;
883 * we only take care of fsuid/fsgid.
885 void mds_squash_root(struct mds_obd *mds, struct mds_req_sec_desc *rsd,
888 if (!mds->mds_squash_uid || rsd->rsd_fsuid)
891 if (*peernid == mds->mds_nosquash_nid)
894 CDEBUG(D_SEC, "squash req from 0x%llx, (%d:%d/%x)=>(%d:%d/%x)\n",
895 *peernid, rsd->rsd_fsuid, rsd->rsd_fsgid, rsd->rsd_cap,
896 mds->mds_squash_uid, mds->mds_squash_gid,
897 (rsd->rsd_cap & ~CAP_FS_MASK));
899 rsd->rsd_fsuid = mds->mds_squash_uid;
900 rsd->rsd_fsgid = mds->mds_squash_gid;
901 rsd->rsd_cap &= ~CAP_FS_MASK;
904 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
905 struct ptlrpc_request *req, int req_off,
906 struct mds_body *reqbody, int reply_off)
908 struct inode *inode = dentry->d_inode;
909 struct mds_body *body;
913 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
916 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
917 LASSERT(body != NULL); /* caller prepped reply */
919 if (dentry->d_flags & DCACHE_CROSS_REF) {
920 mds_pack_dentry2body(obd, body, dentry,
921 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
922 CDEBUG(D_OTHER, "cross reference: "DLID4"\n",
927 mds_pack_inode2body(obd, body, inode,
928 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
930 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
931 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
932 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1, body,
933 inode, 1, (reqbody->valid & OBD_MD_MEA) ? 1 : 0);
935 /* if we have LOV EA data, the OST holds size, atime, mtime. */
936 if (!(body->valid & OBD_MD_FLEASIZE) &&
937 !(body->valid & OBD_MD_FLDIREA))
938 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
939 OBD_MD_FLATIME | OBD_MD_FLMTIME);
940 } else if (S_ISLNK(inode->i_mode) &&
941 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
942 rc = mds_pack_link(dentry, req, body, reply_off);
943 } else if (reqbody->valid & OBD_MD_FLEA) {
944 rc = mds_pack_ea(dentry, req, body, req_off, reply_off);
945 } else if (reqbody->valid & OBD_MD_FLEALIST) {
946 rc = mds_pack_ealist(dentry, req, body, reply_off);
949 if (reqbody->valid & OBD_MD_FLACL_ACCESS) {
950 int inc = (reqbody->valid & OBD_MD_FLEASIZE) ? 2 : 1;
951 rc = mds_pack_acl(obd, req->rq_repmsg, reply_off + inc,
955 /* do reverse uid/gid mapping if needed */
956 if (rc == 0 && req->rq_remote)
957 mds_reverse_map_ugid(req, body);
962 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
963 struct dentry *dentry,
966 int rc = 0, size[1] = {sizeof(struct mds_body)};
969 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
970 CERROR("failed MDS_GETATTR_PACK test\n");
971 req->rq_status = -ENOMEM;
975 rc = lustre_pack_reply(req, 1, size, NULL);
977 CERROR("lustre_pack_reply failed: rc %d\n", rc);
978 GOTO(out, req->rq_status = rc);
986 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct dentry *de,
989 struct inode *inode = de->d_inode;
990 struct mds_obd *mds = mds_req2mds(req);
991 struct mds_body *body;
992 int rc = 0, size[4] = {sizeof(*body)}, bufcount = 1;
995 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
996 LASSERT(body != NULL); /* checked by caller */
997 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
999 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
1000 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
1003 down(&inode->i_sem);
1004 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
1005 ((body->valid & OBD_MD_MEA) ? EA_MEA : EA_LOV));
1008 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1009 CERROR("error getting inode %lu MD: rc = %d\n",
1012 } else if (rc > mds->mds_max_mdsize) {
1014 CERROR("MD size %d larger than maximum possible %u\n",
1015 rc, mds->mds_max_mdsize);
1017 size[bufcount] = rc;
1020 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
1021 if (inode->i_size + 1 != body->eadatasize)
1022 CERROR("symlink size: %Lu, reply space: %d\n",
1023 inode->i_size + 1, body->eadatasize);
1024 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
1026 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
1027 inode->i_size + 1, body->eadatasize);
1028 } else if ((body->valid & OBD_MD_FLEA)) {
1029 char *ea_name = lustre_msg_string(req->rq_reqmsg,
1032 if (inode->i_op && inode->i_op->getxattr)
1033 rc = inode->i_op->getxattr(de, ea_name, NULL, 0);
1036 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1037 CERROR("error getting inode %lu EA: rc = %d\n",
1041 size[bufcount] = min_t(int, body->eadatasize, rc);
1044 } else if (body->valid & OBD_MD_FLEALIST) {
1046 if (inode->i_op && inode->i_op->getxattr)
1047 rc = inode->i_op->listxattr(de, NULL, 0);
1050 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1051 CERROR("error getting inode %lu EA: rc = %d\n",
1055 size[bufcount] = min_t(int, body->eadatasize, rc);
1060 /* may co-exist with OBD_MD_FLEASIZE */
1061 if (body->valid & OBD_MD_FLACL_ACCESS) {
1062 size[bufcount++] = 4;
1063 size[bufcount++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
1066 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1067 CERROR("failed MDS_GETATTR_PACK test\n");
1068 req->rq_status = -ENOMEM;
1069 GOTO(out, rc = -ENOMEM);
1072 rc = lustre_pack_reply(req, bufcount, size, NULL);
1074 CERROR("out of memory\n");
1075 GOTO(out, req->rq_status = rc);
1083 int mds_check_mds_num(struct obd_device *obd, struct inode *inode,
1084 char *name, int namelen)
1086 struct mea *mea = NULL;
1087 int mea_size, rc = 0;
1090 rc = mds_md_get_attr(obd, inode, &mea, &mea_size);
1095 * dir is already splitted, check if requested filename should
1096 * live at this MDS or at another one.
1098 int i = mea_name2idx(mea, name, namelen - 1);
1099 if (mea->mea_master != id_group(&mea->mea_ids[i])) {
1101 "inapropriate MDS(%d) for %s. should be "
1102 "%lu(%d)\n", mea->mea_master, name,
1103 (unsigned long)id_group(&mea->mea_ids[i]), i);
1109 OBD_FREE(mea, mea_size);
1113 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
1114 struct lustre_handle *child_lockh, int child_part)
1116 struct obd_device *obd = req->rq_export->exp_obd;
1117 struct mds_obd *mds = &obd->u.mds;
1118 struct ldlm_reply *rep = NULL;
1119 struct lvfs_run_ctxt saved;
1120 struct mds_req_sec_desc *rsd;
1121 struct mds_body *body;
1122 struct dentry *dparent = NULL, *dchild = NULL;
1123 struct lvfs_ucred uc = {NULL, NULL,};
1124 struct lustre_handle parent_lockh[2] = {{0}, {0}};
1125 unsigned int namesize;
1126 int rc = 0, cleanup_phase = 0, resent_req = 0, update_mode, reply_offset;
1130 LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME));
1131 MD_COUNTER_INCREMENT(obd, getattr_lock);
1133 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1135 CERROR("Can't unpack security desc\n");
1139 /* swab now, before anyone looks inside the request. */
1140 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1141 lustre_swab_mds_body);
1143 CERROR("Can't swab mds_body\n");
1144 GOTO(cleanup, rc = -EFAULT);
1147 LASSERT_REQSWAB(req, offset + 1);
1148 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
1150 CERROR("Can't unpack name\n");
1151 GOTO(cleanup, rc = -EFAULT);
1153 namesize = req->rq_reqmsg->buflens[offset + 1];
1155 /* namesize less than 2 means we have empty name, probably came from
1156 revalidate by cfid, so no point in having name to be set */
1160 LASSERT (offset == 1 || offset == 3);
1162 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
1168 rc = mds_init_ucred(&uc, req, rsd);
1170 CERROR("can't init ucred\n");
1174 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1175 cleanup_phase = 1; /* kernel context */
1176 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
1178 LASSERT(namesize > 0);
1179 if (child_lockh->cookie != 0) {
1180 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1185 if (body->valid == OBD_MD_FLID) {
1186 struct mds_body *mds_reply;
1187 int size = sizeof(*mds_reply);
1191 dparent = mds_id2dentry(obd, &body->id1, NULL);
1192 if (IS_ERR(dparent)) {
1193 rc = PTR_ERR(dparent);
1198 * the user requested ONLY the inode number, so do a raw lookup.
1200 rc = lustre_pack_reply(req, 1, &size, NULL);
1202 CERROR("out of memory\n");
1206 dir = dparent->d_inode;
1207 LASSERT(dir->i_op->lookup_raw != NULL);
1208 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
1210 mds_reply = lustre_msg_buf(req->rq_repmsg, 0,
1211 sizeof(*mds_reply));
1213 id_ino(&mds_reply->id1) = inum;
1214 mds_reply->valid = OBD_MD_FLID;
1219 if (resent_req == 0) {
1220 LASSERT(id_fid(&body->id1) != 0);
1222 rc = mds_get_parent_child_locked(obd, mds, &body->id1,
1223 parent_lockh, &dparent,
1225 MDS_INODELOCK_UPDATE,
1228 child_lockh, &dchild,
1229 LCK_PR, child_part);
1233 cleanup_phase = 2; /* dchild, dparent, locks */
1236 * let's make sure this name should leave on this mds
1239 rc = mds_check_mds_num(obd, dparent->d_inode, name, namesize);
1243 /* we have no dentry here, drop LOOKUP bit */
1244 /* FIXME: we need MDS_INODELOCK_LOOKUP or not. */
1245 child_part &= ~MDS_INODELOCK_LOOKUP;
1246 CDEBUG(D_OTHER, "%s: retrieve attrs for "DLID4"\n",
1247 obd->obd_name, OLID4(&body->id1));
1249 dchild = mds_id2locked_dentry(obd, &body->id1, NULL,
1250 LCK_PR, parent_lockh,
1253 MDS_INODELOCK_UPDATE);
1254 if (IS_ERR(dchild)) {
1255 CERROR("can't find inode with id "DLID4", err = %d\n",
1256 OLID4(&body->id1), (int)PTR_ERR(dchild));
1257 GOTO(cleanup, rc = PTR_ERR(dchild));
1259 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
1262 struct ldlm_lock *granted_lock;
1264 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
1265 granted_lock = ldlm_handle2lock(child_lockh);
1267 LASSERTF(granted_lock != NULL, LPU64"/%lu lockh "LPX64"\n",
1268 id_fid(&body->id1), (unsigned long)id_group(&body->id1),
1269 child_lockh->cookie);
1272 /* usual named request */
1273 dparent = mds_id2dentry(obd, &body->id1, NULL);
1274 LASSERT(!IS_ERR(dparent));
1275 dchild = ll_lookup_one_len(name, dparent, namesize - 1);
1276 if (IS_ERR(dchild)) {
1277 DEBUG_REQ(D_ERROR, req, "resent, not enqueuing new locks");
1278 CDEBUG(D_ERROR, "lock against [%lu:%lu]/%*s\n",
1279 (unsigned long) id_ino(&body->id1),
1280 (unsigned long) id_gen(&body->id1),
1281 namesize - 1, name);
1283 LASSERT(!IS_ERR(dchild));
1285 /* client wants to get attr. by id */
1286 dchild = mds_id2dentry(obd, &body->id1, NULL);
1287 if (IS_ERR(dchild)) {
1288 DEBUG_REQ(D_ERROR, req, "resent, not enqueuing new locks");
1289 CDEBUG(D_ERROR, "lock against [%lu:%lu]\n",
1290 (unsigned long) id_ino(&body->id1),
1291 (unsigned long) id_gen(&body->id1));
1293 LASSERT(!IS_ERR(dchild));
1295 LDLM_LOCK_PUT(granted_lock);
1298 cleanup_phase = 2; /* dchild, dparent, locks */
1300 if (!DENTRY_VALID(dchild)) {
1301 intent_set_disposition(rep, DISP_LOOKUP_NEG);
1303 * in the intent case, the policy clears this error: the
1304 * disposition is enough.
1309 intent_set_disposition(rep, DISP_LOOKUP_POS);
1312 if (req->rq_repmsg == NULL) {
1313 if (dchild->d_flags & DCACHE_CROSS_REF)
1314 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
1316 rc = mds_getattr_pack_msg(req, dchild, offset);
1318 CERROR ("mds_getattr_pack_msg: %d\n", rc);
1323 rc = mds_getattr_internal(obd, dchild, req, offset, body, reply_offset);
1324 GOTO(cleanup, rc); /* returns the lock to the client */
1327 switch (cleanup_phase) {
1329 if (resent_req == 0) {
1330 if (rc && DENTRY_VALID(dchild))
1331 ldlm_lock_decref(child_lockh, LCK_PR);
1333 ldlm_lock_decref(parent_lockh, LCK_PR);
1335 if (parent_lockh[1].cookie != 0)
1336 ldlm_lock_decref(parent_lockh + 1, update_mode);
1343 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1345 mds_exit_ucred(&uc);
1350 static int mds_getattr(struct ptlrpc_request *req, int offset)
1352 struct obd_device *obd = req->rq_export->exp_obd;
1353 struct lvfs_run_ctxt saved;
1355 struct mds_req_sec_desc *rsd;
1356 struct mds_body *body;
1357 struct lvfs_ucred uc = {NULL, NULL,};
1361 MD_COUNTER_INCREMENT(obd, getattr);
1363 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1365 CERROR("Can't unpack security desc\n");
1369 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1370 lustre_swab_mds_body);
1372 CERROR ("Can't unpack body\n");
1376 rc = mds_init_ucred(&uc, req, rsd);
1378 mds_exit_ucred(&uc);
1379 CERROR("can't init ucred\n");
1383 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1384 de = mds_id2dentry(obd, &body->id1, NULL);
1386 rc = req->rq_status = PTR_ERR(de);
1390 rc = mds_getattr_pack_msg(req, de, offset);
1392 CERROR("mds_getattr_pack_msg: %d\n", rc);
1396 req->rq_status = mds_getattr_internal(obd, de, req, offset, body, 0);
1401 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1402 mds_exit_ucred(&uc);
1406 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1407 unsigned long max_age)
1412 spin_lock(&obd->obd_osfs_lock);
1413 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
1415 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1416 spin_unlock(&obd->obd_osfs_lock);
1421 static int mds_statfs(struct ptlrpc_request *req)
1423 struct obd_device *obd = req->rq_export->exp_obd;
1424 int rc, size = sizeof(struct obd_statfs);
1427 /* This will trigger a watchdog timeout */
1428 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1429 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1431 rc = lustre_pack_reply(req, 1, &size, NULL);
1432 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1433 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1437 OBD_COUNTER_INCREMENT(obd, statfs);
1439 /* We call this so that we can cache a bit - 1 jiffie worth */
1440 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
1443 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1449 req->rq_status = rc;
1453 static int mds_sync(struct ptlrpc_request *req, int offset)
1455 struct obd_device *obd = req->rq_export->exp_obd;
1456 struct mds_obd *mds = &obd->u.mds;
1457 struct mds_body *body;
1458 int rc, size = sizeof(*body);
1461 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1462 lustre_swab_mds_body);
1464 GOTO(out, rc = -EPROTO);
1466 rc = lustre_pack_reply(req, 1, &size, NULL);
1467 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1468 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1472 if (id_ino(&body->id1) == 0) {
1473 /* an id of zero is taken to mean "sync whole filesystem" */
1474 rc = fsfilt_sync(obd, mds->mds_sb);
1478 /* just any file to grab fsync method - "file" arg unused */
1479 struct file *file = mds->mds_rcvd_filp;
1480 struct mds_body *rep_body;
1483 de = mds_id2dentry(obd, &body->id1, NULL);
1485 GOTO(out, rc = PTR_ERR(de));
1487 rc = file->f_op->fsync(NULL, de, 1);
1491 rep_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_body));
1492 mds_pack_inode2body(obd, rep_body, de->d_inode,
1493 (body->valid & OBD_MD_FID) ? 1 : 0);
1499 req->rq_status = rc;
1503 /* mds_readpage does not take a DLM lock on the inode, because the client must
1504 * already have a PR lock.
1506 * If we were to take another one here, a deadlock will result, if another
1507 * thread is already waiting for a PW lock. */
1508 static int mds_readpage(struct ptlrpc_request *req, int offset)
1510 struct obd_device *obd = req->rq_export->exp_obd;
1511 struct vfsmount *mnt;
1514 struct mds_req_sec_desc *rsd;
1515 struct mds_body *body, *repbody;
1516 struct lvfs_run_ctxt saved;
1517 int rc, size = sizeof(*repbody);
1518 struct lvfs_ucred uc = {NULL, NULL,};
1521 rc = lustre_pack_reply(req, 1, &size, NULL);
1522 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1523 CERROR("mds: out of memory\n");
1524 GOTO(out, rc = -ENOMEM);
1527 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1529 CERROR("Can't unpack security desc\n");
1530 GOTO (out, rc = -EFAULT);
1533 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1534 lustre_swab_mds_body);
1536 CERROR("Can't unpack body\n");
1537 GOTO (out, rc = -EFAULT);
1540 rc = mds_init_ucred(&uc, req, rsd);
1542 CERROR("can't init ucred\n");
1546 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1547 de = mds_id2dentry(obd, &body->id1, &mnt);
1549 GOTO(out_pop, rc = PTR_ERR(de));
1551 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1553 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1554 /* note: in case of an error, dentry_open puts dentry */
1556 GOTO(out_pop, rc = PTR_ERR(file));
1558 /* body->size is actually the offset -eeb */
1559 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1560 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1561 body->size, de->d_inode->i_blksize);
1562 GOTO(out_file, rc = -EFAULT);
1565 /* body->nlink is actually the #bytes to read -eeb */
1566 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1567 CERROR("size %u is not multiple of blocksize %lu\n",
1568 body->nlink, de->d_inode->i_blksize);
1569 GOTO(out_file, rc = -EFAULT);
1572 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
1573 repbody->size = file->f_dentry->d_inode->i_size;
1574 repbody->valid = OBD_MD_FLSIZE;
1576 /* to make this asynchronous make sure that the handling function
1577 doesn't send a reply when this function completes. Instead a
1578 callback function would send the reply */
1579 /* body->size is actually the offset -eeb */
1580 rc = mds_sendpage(req, file, body->size, body->nlink);
1584 filp_close(file, 0);
1586 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1588 mds_exit_ucred(&uc);
1589 req->rq_status = rc;
1593 /* update master MDS ID, which is stored in local inode EA. */
1594 int mds_update_mid(struct obd_device *obd, struct lustre_id *id,
1595 void *data, int data_len)
1597 struct mds_obd *mds = &obd->u.mds;
1598 struct dentry *dentry;
1606 dentry = mds_id2dentry(obd, id, NULL);
1608 GOTO(out, rc = PTR_ERR(dentry));
1610 if (!dentry->d_inode) {
1611 CERROR("Can't find object "DLID4".\n",
1613 GOTO(out_dentry, rc = -EINVAL);
1616 handle = fsfilt_start(obd, dentry->d_inode,
1617 FSFILT_OP_SETATTR, NULL);
1619 GOTO(out_dentry, rc = PTR_ERR(handle));
1621 rc = mds_update_inode_mid(obd, dentry->d_inode, handle,
1622 (struct lustre_id *)data);
1624 CERROR("Can't update inode "DLID4" master id, "
1625 "error = %d.\n", OLID4(id), rc);
1626 GOTO(out_commit, rc);
1631 fsfilt_commit(obd, mds->mds_sb, dentry->d_inode,
1638 EXPORT_SYMBOL(mds_update_mid);
1640 /* read master MDS ID, which is stored in local inode EA. */
1641 int mds_read_mid(struct obd_device *obd, struct lustre_id *id,
1642 void *data, int data_len)
1644 struct dentry *dentry;
1651 dentry = mds_id2dentry(obd, id, NULL);
1653 GOTO(out, rc = PTR_ERR(dentry));
1655 if (!dentry->d_inode) {
1656 CERROR("Can't find object "DLID4".\n",
1658 GOTO(out_dentry, rc = -EINVAL);
1661 down(&dentry->d_inode->i_sem);
1662 rc = mds_read_inode_mid(obd, dentry->d_inode,
1663 (struct lustre_id *)data);
1664 up(&dentry->d_inode->i_sem);
1666 CERROR("Can't read inode "DLID4" master id, "
1667 "error = %d.\n", OLID4(id), rc);
1668 GOTO(out_dentry, rc);
1677 EXPORT_SYMBOL(mds_read_mid);
1679 int mds_reint(struct ptlrpc_request *req, int offset,
1680 struct lustre_handle *lockh)
1682 struct mds_update_record *rec;
1683 struct mds_req_sec_desc *rsd;
1687 OBD_ALLOC(rec, sizeof(*rec));
1691 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1693 CERROR("Can't unpack security desc\n");
1694 GOTO(out, rc = -EFAULT);
1697 rc = mds_update_unpack(req, offset, rec);
1698 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1699 CERROR("invalid record\n");
1700 GOTO(out, req->rq_status = -EINVAL);
1703 rc = mds_init_ucred(&rec->ur_uc, req, rsd);
1705 CERROR("can't init ucred\n");
1709 /* rc will be used to interrupt a for loop over multiple records */
1710 rc = mds_reint_rec(rec, offset, req, lockh);
1712 /* do reverse uid/gid mapping if needed */
1713 if (rc == 0 && req->rq_remote &&
1714 (rec->ur_opcode == REINT_SETATTR ||
1715 rec->ur_opcode == REINT_OPEN)) {
1716 struct mds_body *body;
1719 if (rec->ur_opcode == REINT_SETATTR)
1722 bodyoff = (offset == 3 ? 1 : 0);
1723 body = lustre_msg_buf(req->rq_repmsg, bodyoff, sizeof(*body));
1726 mds_reverse_map_ugid(req, body);
1729 mds_exit_ucred(&rec->ur_uc);
1730 OBD_FREE(rec, sizeof(*rec));
1734 static int mds_filter_recovery_request(struct ptlrpc_request *req,
1735 struct obd_device *obd, int *process)
1737 switch (req->rq_reqmsg->opc) {
1738 case MDS_CONNECT: /* This will never get here, but for completeness. */
1739 case OST_CONNECT: /* This will never get here, but for completeness. */
1740 case MDS_DISCONNECT:
1741 case OST_DISCONNECT:
1746 case MDS_SYNC: /* used in unmounting */
1751 *process = target_queue_recovery_request(req, obd);
1755 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1757 /* XXX what should we set rq_status to here? */
1758 req->rq_status = -EAGAIN;
1759 RETURN(ptlrpc_error(req));
1763 static char *reint_names[] = {
1764 [REINT_SETATTR] "setattr",
1765 [REINT_CREATE] "create",
1766 [REINT_LINK] "link",
1767 [REINT_UNLINK] "unlink",
1768 [REINT_RENAME] "rename",
1769 [REINT_OPEN] "open",
1772 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER | \
1773 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ| \
1774 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME| \
1777 static void reconstruct_create(struct ptlrpc_request *req)
1779 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1780 struct mds_client_data *mcd = med->med_mcd;
1781 struct dentry *dentry;
1782 struct ost_body *body;
1783 struct lustre_id id;
1787 /* copy rc, transno and disp; steal locks */
1788 mds_req_from_mcd(req, mcd);
1789 if (req->rq_status) {
1797 id_ino(&id) = mcd->mcd_last_data;
1798 LASSERT(id_ino(&id) != 0);
1800 dentry = mds_id2dentry(req2obd(req), &id, NULL);
1801 if (IS_ERR(dentry)) {
1802 CERROR("can't find inode "LPU64"\n", id_ino(&id));
1803 req->rq_status = PTR_ERR(dentry);
1808 CWARN("reconstruct reply for x"LPU64" (remote ino) "LPU64" -> %lu/%u\n",
1809 req->rq_xid, id_ino(&id), dentry->d_inode->i_ino,
1810 dentry->d_inode->i_generation);
1812 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
1813 obdo_from_inode(&body->oa, dentry->d_inode, FILTER_VALID_FLAGS);
1814 body->oa.o_id = dentry->d_inode->i_ino;
1815 body->oa.o_generation = dentry->d_inode->i_generation;
1816 body->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
1818 down(&dentry->d_inode->i_sem);
1819 rc = mds_read_inode_sid(req2obd(req), dentry->d_inode, &id);
1820 up(&dentry->d_inode->i_sem);
1822 CERROR("Can't read inode self id, inode %lu, "
1823 "rc %d\n", dentry->d_inode->i_ino, rc);
1827 body->oa.o_fid = id_fid(&id);
1828 body->oa.o_mds = id_group(&id);
1834 static int mdt_obj_create(struct ptlrpc_request *req)
1836 struct obd_device *obd = req->rq_export->exp_obd;
1837 struct mds_obd *mds = &obd->u.mds;
1838 struct ost_body *body, *repbody;
1839 char idname[LL_ID_NAMELEN];
1840 int size = sizeof(*repbody);
1841 struct inode *parent_inode;
1842 struct lvfs_run_ctxt saved;
1843 int rc, cleanup_phase = 0;
1844 struct dentry *new = NULL;
1845 struct dentry_params dp;
1846 int mealen, flags = 0;
1847 struct lvfs_ucred uc;
1848 struct lustre_id id;
1850 void *handle = NULL;
1851 unsigned long cr_inum = 0;
1854 DEBUG_REQ(D_HA, req, "create remote object");
1855 parent_inode = mds->mds_unnamed_dir->d_inode;
1857 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
1858 lustre_swab_ost_body);
1862 rc = lustre_pack_reply(req, 1, &size, NULL);
1866 MDS_CHECK_RESENT(req, reconstruct_create(req));
1869 * this only serve to inter-mds request, don't need check group database
1873 uc.luc_ginfo = NULL;
1874 uc.luc_uid = body->oa.o_uid;
1875 uc.luc_fsuid = body->oa.o_uid;
1876 uc.luc_fsgid = body->oa.o_gid;
1878 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1879 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
1881 /* in REPLAY case inum should be given (client or other MDS fills it) */
1882 if (body->oa.o_id && ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
1883 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY))) {
1885 * this is re-create request from MDS holding directory name.
1886 * we have to lookup given ino/gen first. if it exists (good
1887 * case) then there is nothing to do. if it does not then we
1888 * have to recreate it.
1890 id_ino(&id) = body->oa.o_id;
1891 id_gen(&id) = body->oa.o_generation;
1893 new = mds_id2dentry(obd, &id, NULL);
1894 if (!IS_ERR(new) && new->d_inode) {
1895 struct lustre_id sid;
1897 CWARN("mkdir() repairing is on its way: %lu/%lu\n",
1898 (unsigned long)id_ino(&id), (unsigned long)id_gen(&id));
1900 obdo_from_inode(&repbody->oa, new->d_inode,
1901 FILTER_VALID_FLAGS);
1903 repbody->oa.o_id = new->d_inode->i_ino;
1904 repbody->oa.o_generation = new->d_inode->i_generation;
1905 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
1908 down(&new->d_inode->i_sem);
1909 rc = mds_read_inode_sid(obd, new->d_inode, &sid);
1910 up(&new->d_inode->i_sem);
1912 CERROR("Can't read inode self id "
1913 "inode %lu, rc %d.\n",
1914 new->d_inode->i_ino, rc);
1918 repbody->oa.o_fid = id_fid(&sid);
1919 repbody->oa.o_mds = id_group(&sid);
1920 LASSERT(id_fid(&sid) != 0);
1923 * here we could use fid passed in body->oa.o_fid and
1924 * thus avoid mds_read_inode_sid().
1926 cr_inum = new->d_inode->i_ino;
1927 GOTO(cleanup, rc = 0);
1931 down(&parent_inode->i_sem);
1932 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
1933 if (IS_ERR(handle)) {
1934 up(&parent_inode->i_sem);
1935 CERROR("fsfilt_start() failed, rc = %d\n",
1936 (int)PTR_ERR(handle));
1937 GOTO(cleanup, rc = PTR_ERR(handle));
1939 cleanup_phase = 1; /* transaction */
1942 rc = sprintf(idname, "%u.%u", ll_insecure_random_int(), current->pid);
1943 new = lookup_one_len(idname, mds->mds_unnamed_dir, rc);
1945 CERROR("%s: can't lookup new inode (%s) for mkdir: %d\n",
1946 obd->obd_name, idname, (int) PTR_ERR(new));
1947 fsfilt_commit(obd, mds->mds_sb, new->d_inode, handle, 0);
1948 up(&parent_inode->i_sem);
1949 RETURN(PTR_ERR(new));
1950 } else if (new->d_inode) {
1951 CERROR("%s: name exists. repeat\n", obd->obd_name);
1955 new->d_fsdata = (void *)&dp;
1959 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) ||
1960 (body->oa.o_flags & OBD_FL_RECREATE_OBJS)) {
1961 LASSERT(body->oa.o_id != 0);
1962 dp.p_inum = body->oa.o_id;
1963 DEBUG_REQ(D_HA, req, "replay create obj %lu/%lu",
1964 (unsigned long)body->oa.o_id,
1965 (unsigned long)body->oa.o_generation);
1968 rc = vfs_mkdir(parent_inode, new, body->oa.o_mode);
1970 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
1971 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
1972 new->d_inode->i_generation = body->oa.o_generation;
1973 mark_inode_dirty(new->d_inode);
1976 * avoiding asserts in cache flush case, as
1977 * @body->oa.o_id should be zero.
1979 if (body->oa.o_id) {
1980 LASSERTF(body->oa.o_id == new->d_inode->i_ino,
1981 "BUG 3550: failed to recreate obj "
1982 LPU64" -> %lu\n", body->oa.o_id,
1983 new->d_inode->i_ino);
1985 LASSERTF(body->oa.o_generation ==
1986 new->d_inode->i_generation,
1987 "BUG 3550: failed to recreate obj/gen "
1988 LPU64"/%u -> %lu/%u\n", body->oa.o_id,
1989 body->oa.o_generation,
1990 new->d_inode->i_ino,
1991 new->d_inode->i_generation);
1995 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
1996 repbody->oa.o_id = new->d_inode->i_ino;
1997 repbody->oa.o_generation = new->d_inode->i_generation;
1998 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FID;
2000 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2001 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2002 id_group(&id) = mds->mds_num;
2004 LASSERT(body->oa.o_fid != 0);
2005 id_fid(&id) = body->oa.o_fid;
2007 LASSERT(body->oa.o_id != 0);
2008 id_ino(&id) = repbody->oa.o_id;
2009 id_gen(&id) = repbody->oa.o_generation;
2011 down(&new->d_inode->i_sem);
2012 rc = mds_update_inode_sid(obd, new->d_inode, handle, &id);
2013 up(&new->d_inode->i_sem);
2016 * make sure, that fid is up-to-date.
2018 mds_set_last_fid(obd, id_fid(&id));
2021 * allocate new sid, as object is created from scratch
2022 * and this is not replay.
2024 down(&new->d_inode->i_sem);
2025 rc = mds_alloc_inode_sid(obd, new->d_inode, handle, &id);
2026 up(&new->d_inode->i_sem);
2029 CERROR("Can't update lustre ID for inode %lu, "
2030 "error = %d\n", new->d_inode->i_ino, rc);
2034 /* initializing o_fid after it is allocated. */
2035 repbody->oa.o_fid = id_fid(&id);
2036 repbody->oa.o_mds = id_group(&id);
2038 rc = fsfilt_del_dir_entry(obd, new);
2039 up(&parent_inode->i_sem);
2041 CERROR("can't remove name for object: %d\n", rc);
2045 cleanup_phase = 2; /* created directory object */
2047 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
2048 (unsigned long)new->d_inode->i_ino,
2049 (unsigned long)new->d_inode->i_generation,
2050 (unsigned)new->d_inode->i_mode);
2051 cr_inum = new->d_inode->i_ino;
2053 up(&parent_inode->i_sem);
2054 CERROR("%s: can't create dirobj: %d\n", obd->obd_name, rc);
2058 if (body->oa.o_valid & OBD_MD_FLID) {
2059 /* this is new object for splitted dir. We have to prevent
2060 * recursive splitting on it -bzzz */
2061 mealen = obd_size_diskmd(mds->mds_md_exp, NULL);
2063 OBD_ALLOC(mea, mealen);
2065 GOTO(cleanup, rc = -ENOMEM);
2067 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2068 mea->mea_master = 0;
2071 down(&new->d_inode->i_sem);
2072 rc = fsfilt_set_md(obd, new->d_inode, handle,
2073 mea, mealen, EA_MEA);
2074 up(&new->d_inode->i_sem);
2076 CERROR("fsfilt_set_md() failed, "
2079 OBD_FREE(mea, mealen);
2081 CDEBUG(D_OTHER, "%s: mark non-splittable %lu/%u - %d\n",
2082 obd->obd_name, new->d_inode->i_ino,
2083 new->d_inode->i_generation, flags);
2084 } else if (body->oa.o_easize) {
2085 /* we pass LCK_EX to split routine to signal that we have
2086 * exclusive access to the directory. simple because nobody
2087 * knows it already exists -bzzz */
2088 rc = mds_try_to_split_dir(obd, new, NULL,
2089 body->oa.o_easize, LCK_EX);
2091 CERROR("Can't split directory %lu, error = %d.\n",
2092 new->d_inode->i_ino, rc);
2100 switch (cleanup_phase) {
2101 case 2: /* object has been created, but we'll may want to replay it later */
2103 ptlrpc_require_repack(req);
2104 case 1: /* transaction */
2105 rc = mds_finish_transno(mds, parent_inode, handle,
2110 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2114 static int mdt_get_info(struct ptlrpc_request *req)
2116 struct obd_export *exp = req->rq_export;
2121 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2123 DEBUG_REQ(D_HA, req, "no get_info key");
2126 keylen = req->rq_reqmsg->buflens[0];
2128 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
2129 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
2130 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0))
2133 if (keylen >= strlen("rootid") && !strcmp(key, "rootid")) {
2134 struct lustre_id *reply;
2135 int size = sizeof(*reply);
2137 rc = lustre_pack_reply(req, 1, &size, NULL);
2141 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2142 rc = obd_get_info(exp, keylen, key, &size, reply);
2145 int size = sizeof(*reply);
2147 rc = lustre_pack_reply(req, 1, &size, NULL);
2151 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2152 rc = obd_get_info(exp, keylen, key, &size, reply);
2155 req->rq_repmsg->status = 0;
2159 static int mds_set_info(struct obd_export *exp, __u32 keylen,
2160 void *key, __u32 vallen, void *val)
2162 struct obd_device *obd;
2163 struct mds_obd *mds;
2167 obd = class_exp2obd(exp);
2169 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2170 exp->exp_handle.h_cookie);
2175 if (keylen >= strlen("mds_type") &&
2176 memcmp(key, "mds_type", keylen) == 0) {
2180 CDEBUG(D_IOCTL, "set mds type to %x\n", *(int*)val);
2182 mds->mds_obd_type = *(int*)val;
2183 group = FILTER_GROUP_FIRST_MDS + mds->mds_obd_type;
2184 valsize = sizeof(group);
2186 /* mds number has been changed, so the corresponding obdfilter
2187 * exp need to be changed too. */
2188 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
2189 "mds_conn", valsize, &group);
2192 CDEBUG(D_IOCTL, "invalid key\n");
2196 static int mdt_set_info(struct ptlrpc_request *req)
2199 struct obd_export *exp = req->rq_export;
2200 int keylen, rc = 0, vallen;
2203 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2205 DEBUG_REQ(D_HA, req, "no set_info key");
2208 keylen = req->rq_reqmsg->buflens[0];
2210 if (keylen == strlen("mds_type") &&
2211 memcmp(key, "mds_type", keylen) == 0) {
2212 rc = lustre_pack_reply(req, 0, NULL, NULL);
2216 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2217 vallen = req->rq_reqmsg->buflens[1];
2219 rc = obd_set_info(exp, keylen, key, vallen, val);
2220 req->rq_repmsg->status = 0;
2223 CDEBUG(D_IOCTL, "invalid key\n");
2227 static int mds_init_export_data(struct ptlrpc_request *req)
2229 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
2232 nllu = lustre_msg_buf(req->rq_reqmsg, 4, sizeof(__u32) * 2);
2234 CERROR("failed to extract nllu, use 99:99\n");
2238 if (lustre_msg_swabbed(req->rq_reqmsg)) {
2239 __swab32s(&nllu[0]);
2240 __swab32s(&nllu[1]);
2242 med->med_nllu = nllu[0];
2243 med->med_nllg = nllu[1];
2246 if (req->rq_remote) {
2247 CWARN("exp %p, peer "LPX64": set as remote\n",
2248 req->rq_export, req->rq_peer.peer_id.nid);
2253 LASSERT(med->med_idmap == NULL);
2254 spin_lock_init(&med->med_idmap_lock);
2259 static int mds_msg_check_version(struct lustre_msg *msg)
2265 case MDS_DISCONNECT:
2267 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2269 CERROR("bad opc %u version %08x, expecting %08x\n",
2270 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2275 case MDS_GETATTR_LOCK:
2279 case MDS_DONE_WRITING:
2282 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2284 CERROR("bad opc %u version %08x, expecting %08x\n",
2285 msg->opc, msg->version, LUSTRE_MDS_VERSION);
2289 case LDLM_BL_CALLBACK:
2290 case LDLM_CP_CALLBACK:
2291 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2293 CERROR("bad opc %u version %08x, expecting %08x\n",
2294 msg->opc, msg->version, LUSTRE_DLM_VERSION);
2296 case OBD_LOG_CANCEL:
2297 case LLOG_ORIGIN_HANDLE_OPEN:
2298 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2299 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2300 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2301 case LLOG_ORIGIN_HANDLE_CLOSE:
2303 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2305 CERROR("bad opc %u version %08x, expecting %08x\n",
2306 msg->opc, msg->version, LUSTRE_LOG_VERSION);
2312 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2314 CERROR("bad opc %u version %08x, expecting %08x\n",
2315 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2318 case SEC_INIT_CONTINUE:
2323 CERROR("MDS unknown opcode %d\n", msg->opc);
2331 int mds_handle(struct ptlrpc_request *req)
2333 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
2334 struct obd_device *obd = NULL;
2335 struct mds_obd *mds = NULL; /* quell gcc overwarning */
2339 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2341 rc = mds_msg_check_version(req->rq_reqmsg);
2343 CERROR("MDS drop mal-formed request\n");
2347 /* Security opc should NOT trigger any recovery events */
2348 if (req->rq_reqmsg->opc == SEC_INIT ||
2349 req->rq_reqmsg->opc == SEC_INIT_CONTINUE ||
2350 req->rq_reqmsg->opc == SEC_FINI) {
2354 LASSERT(current->journal_info == NULL);
2355 /* XXX identical to OST */
2356 if (req->rq_reqmsg->opc != MDS_CONNECT) {
2357 struct mds_export_data *med;
2360 if (req->rq_export == NULL) {
2361 CERROR("operation %d on unconnected MDS from %s\n",
2362 req->rq_reqmsg->opc,
2364 req->rq_status = -ENOTCONN;
2365 GOTO(out, rc = -ENOTCONN);
2368 med = &req->rq_export->exp_mds_data;
2369 obd = req->rq_export->exp_obd;
2372 /* sanity check: if the xid matches, the request must
2373 * be marked as a resent or replayed */
2374 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
2375 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid)) {
2376 LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
2377 (MSG_RESENT | MSG_REPLAY),
2378 "rq_xid "LPU64" matches last_xid, "
2379 "expected RESENT flag\n",
2382 /* else: note the opposite is not always true; a
2383 * RESENT req after a failover will usually not match
2384 * the last_xid, since it was likely never
2385 * committed. A REPLAYed request will almost never
2386 * match the last xid, however it could for a
2387 * committed, but still retained, open. */
2389 spin_lock_bh(&obd->obd_processing_task_lock);
2390 recovering = obd->obd_recovering;
2391 spin_unlock_bh(&obd->obd_processing_task_lock);
2393 rc = mds_filter_recovery_request(req, obd,
2395 if (rc || should_process == 0) {
2397 } else if (should_process < 0) {
2398 req->rq_status = should_process;
2399 rc = ptlrpc_error(req);
2405 switch (req->rq_reqmsg->opc) {
2407 DEBUG_REQ(D_INODE, req, "connect");
2408 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
2409 rc = target_handle_connect(req);
2411 /* Now that we have an export, set mds. */
2412 mds = mds_req2mds(req);
2413 mds_init_export_data(req);
2417 case MDS_DISCONNECT:
2418 DEBUG_REQ(D_INODE, req, "disconnect");
2419 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
2420 rc = target_handle_disconnect(req);
2421 req->rq_status = rc; /* superfluous? */
2425 DEBUG_REQ(D_INODE, req, "getstatus");
2426 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
2427 rc = mds_getstatus(req);
2431 DEBUG_REQ(D_INODE, req, "getattr");
2432 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
2433 rc = mds_getattr(req, MDS_REQ_REC_OFF);
2436 case MDS_GETATTR_LOCK: {
2437 struct lustre_handle lockh;
2438 DEBUG_REQ(D_INODE, req, "getattr_lock");
2439 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_LOCK_NET, 0);
2441 /* If this request gets a reconstructed reply, we won't be
2442 * acquiring any new locks in mds_getattr_lock, so we don't
2446 rc = mds_getattr_lock(req, MDS_REQ_REC_OFF, &lockh,
2447 MDS_INODELOCK_UPDATE);
2448 /* this non-intent call (from an ioctl) is special */
2449 req->rq_status = rc;
2450 if (rc == 0 && lockh.cookie)
2451 ldlm_lock_decref(&lockh, LCK_PR);
2455 DEBUG_REQ(D_INODE, req, "statfs");
2456 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
2457 rc = mds_statfs(req);
2461 DEBUG_REQ(D_INODE, req, "readpage");
2462 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
2463 rc = mds_readpage(req, MDS_REQ_REC_OFF);
2465 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
2466 if (req->rq_reply_state) {
2467 lustre_free_reply_state (req->rq_reply_state);
2468 req->rq_reply_state = NULL;
2475 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
2478 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
2479 mds->mds_max_cookiesize};
2482 /* NB only peek inside req now; mds_reint() will swab it */
2484 CERROR ("Can't inspect opcode\n");
2489 if (lustre_msg_swabbed (req->rq_reqmsg))
2492 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
2493 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
2494 reint_names[opc] == NULL) ? reint_names[opc] :
2497 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
2499 if (opc == REINT_UNLINK || opc == REINT_RENAME)
2501 else if (opc == REINT_OPEN)
2506 rc = lustre_pack_reply(req, bufcount, size, NULL);
2510 rc = mds_reint(req, MDS_REQ_REC_OFF, NULL);
2511 fail = OBD_FAIL_MDS_REINT_NET_REP;
2516 DEBUG_REQ(D_INODE, req, "close");
2517 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
2518 rc = mds_close(req, MDS_REQ_REC_OFF);
2521 case MDS_DONE_WRITING:
2522 DEBUG_REQ(D_INODE, req, "done_writing");
2523 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
2524 rc = mds_done_writing(req, MDS_REQ_REC_OFF);
2528 DEBUG_REQ(D_INODE, req, "pin");
2529 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
2530 rc = mds_pin(req, MDS_REQ_REC_OFF);
2534 DEBUG_REQ(D_INODE, req, "sync");
2535 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
2536 rc = mds_sync(req, MDS_REQ_REC_OFF);
2540 DEBUG_REQ(D_INODE, req, "ping");
2541 rc = target_handle_ping(req);
2544 case OBD_LOG_CANCEL:
2545 CDEBUG(D_INODE, "log cancel\n");
2546 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
2547 rc = -ENOTSUPP; /* la la la */
2551 DEBUG_REQ(D_INODE, req, "enqueue");
2552 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
2553 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2554 ldlm_server_blocking_ast, NULL);
2555 fail = OBD_FAIL_LDLM_REPLY;
2558 DEBUG_REQ(D_INODE, req, "convert");
2559 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
2560 rc = ldlm_handle_convert(req);
2562 case LDLM_BL_CALLBACK:
2563 case LDLM_CP_CALLBACK:
2564 DEBUG_REQ(D_INODE, req, "callback");
2565 CERROR("callbacks should not happen on MDS\n");
2567 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
2569 case LLOG_ORIGIN_HANDLE_OPEN:
2570 DEBUG_REQ(D_INODE, req, "llog_init");
2571 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2572 rc = llog_origin_handle_open(req);
2574 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2575 DEBUG_REQ(D_INODE, req, "llog next block");
2576 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2577 rc = llog_origin_handle_next_block(req);
2579 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2580 DEBUG_REQ(D_INODE, req, "llog prev block");
2581 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2582 rc = llog_origin_handle_prev_block(req);
2584 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2585 DEBUG_REQ(D_INODE, req, "llog read header");
2586 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2587 rc = llog_origin_handle_read_header(req);
2589 case LLOG_ORIGIN_HANDLE_CLOSE:
2590 DEBUG_REQ(D_INODE, req, "llog close");
2591 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2592 rc = llog_origin_handle_close(req);
2595 DEBUG_REQ(D_INODE, req, "ost_create");
2596 rc = mdt_obj_create(req);
2599 DEBUG_REQ(D_INODE, req, "get_info");
2600 rc = mdt_get_info(req);
2603 DEBUG_REQ(D_INODE, req, "set_info");
2604 rc = mdt_set_info(req);
2607 CDEBUG(D_INODE, "write\n");
2608 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
2609 rc = ost_brw_write(req, NULL);
2610 LASSERT(current->journal_info == NULL);
2611 /* mdt_brw sends its own replies */
2615 DEBUG_REQ(D_INODE, req, "llog catinfo");
2616 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2617 rc = llog_catinfo(req);
2620 req->rq_status = -ENOTSUPP;
2621 rc = ptlrpc_error(req);
2625 LASSERT(current->journal_info == NULL);
2629 /* If we're DISCONNECTing, the mds_export_data is already freed */
2630 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
2631 struct mds_export_data *med = &req->rq_export->exp_mds_data;
2632 struct obd_device *obd = list_entry(mds, struct obd_device,
2634 req->rq_repmsg->last_xid =
2635 le64_to_cpu(med->med_mcd->mcd_last_xid);
2637 if (!obd->obd_no_transno) {
2638 req->rq_repmsg->last_committed =
2639 obd->obd_last_committed;
2641 DEBUG_REQ(D_IOCTL, req,
2642 "not sending last_committed update");
2644 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
2646 mds->mds_last_transno, obd->obd_last_committed,
2651 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
2652 if (obd && obd->obd_recovering) {
2653 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
2654 return target_queue_final_reply(req, rc);
2656 /* Lost a race with recovery; let the error path DTRT. */
2657 rc = req->rq_status = -ENOTCONN;
2660 target_send_reply(req, rc, fail);
2664 /* Update the server data on disk. This stores the new mount_count and also the
2665 * last_rcvd value to disk. If we don't have a clean shutdown, then the server
2666 * last_rcvd value may be less than that of the clients. This will alert us
2667 * that we may need to do client recovery.
2669 * Also assumes for mds_last_transno that we are not modifying it (no locking).
2671 int mds_update_server_data(struct obd_device *obd, int force_sync)
2673 struct mds_obd *mds = &obd->u.mds;
2674 struct mds_server_data *msd = mds->mds_server_data;
2675 struct file *filp = mds->mds_rcvd_filp;
2676 struct lvfs_run_ctxt saved;
2681 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2682 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
2684 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
2685 mds->mds_mount_count, mds->mds_last_transno);
2686 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off, force_sync);
2688 CERROR("error writing MDS server data: rc = %d\n", rc);
2689 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2694 /* saves last allocated fid counter to file. */
2695 int mds_update_last_fid(struct obd_device *obd, void *handle,
2698 struct mds_obd *mds = &obd->u.mds;
2699 struct file *filp = mds->mds_fid_filp;
2700 struct lvfs_run_ctxt saved;
2706 spin_lock(&mds->mds_last_fid_lock);
2707 last_fid = mds->mds_last_fid;
2708 spin_unlock(&mds->mds_last_fid_lock);
2710 CDEBUG(D_SUPER, "MDS last_fid is #"LPU64"\n",
2714 fsfilt_add_journal_cb(obd, mds->mds_sb, last_fid,
2715 handle, mds_commit_last_fid_cb,
2719 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2720 rc = fsfilt_write_record(obd, filp, &last_fid, sizeof(last_fid),
2722 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2725 CERROR("error writing MDS last_fid #"LPU64
2726 ", err = %d\n", last_fid, rc);
2730 CDEBUG(D_SUPER, "wrote fid #"LPU64" at idx "
2731 "%llu: err = %d\n", last_fid, off, rc);
2736 void mds_set_last_fid(struct obd_device *obd, __u64 fid)
2738 struct mds_obd *mds = &obd->u.mds;
2740 spin_lock(&mds->mds_last_fid_lock);
2741 if (fid > mds->mds_last_fid)
2742 mds->mds_last_fid = fid;
2743 spin_unlock(&mds->mds_last_fid_lock);
2746 void mds_commit_last_transno_cb(struct obd_device *obd,
2747 __u64 transno, void *data,
2750 obd_transno_commit_cb(obd, transno, error);
2753 void mds_commit_last_fid_cb(struct obd_device *obd,
2754 __u64 fid, void *data,
2758 CERROR("%s: fid "LPD64" commit error: %d\n",
2759 obd->obd_name, fid, error);
2763 CDEBUG(D_HA, "%s: fid "LPD64" committed\n",
2764 obd->obd_name, fid);
2767 __u64 mds_alloc_fid(struct obd_device *obd)
2769 struct mds_obd *mds = &obd->u.mds;
2772 spin_lock(&mds->mds_last_fid_lock);
2773 fid = ++mds->mds_last_fid;
2774 spin_unlock(&mds->mds_last_fid_lock);
2780 * allocates new lustre_id on passed @inode and saves it to inode EA.
2782 int mds_alloc_inode_sid(struct obd_device *obd, struct inode *inode,
2783 void *handle, struct lustre_id *id)
2785 struct mds_obd *mds = &obd->u.mds;
2786 int alloc = 0, rc = 0;
2789 LASSERT(obd != NULL);
2790 LASSERT(inode != NULL);
2793 OBD_ALLOC(id, sizeof(*id));
2799 id_group(id) = mds->mds_num;
2800 id_fid(id) = mds_alloc_fid(obd);
2801 id_ino(id) = inode->i_ino;
2802 id_gen(id) = inode->i_generation;
2803 id_type(id) = (S_IFMT & inode->i_mode);
2805 rc = mds_update_inode_sid(obd, inode, handle, id);
2807 CERROR("Can't update inode FID EA, "
2812 OBD_FREE(id, sizeof(*id));
2817 * reads inode self id from inode EA. Probably later this should be replaced by
2818 * caching inode self id to avoid raeding it every time it is needed.
2820 int mds_read_inode_sid(struct obd_device *obd, struct inode *inode,
2821 struct lustre_id *id)
2826 LASSERT(id != NULL);
2827 LASSERT(obd != NULL);
2828 LASSERT(inode != NULL);
2830 rc = fsfilt_get_md(obd, inode, &id->li_fid,
2831 sizeof(id->li_fid), EA_SID);
2833 CERROR("fsfilt_get_md() failed, "
2846 /* updates inode self id in EA. */
2847 int mds_update_inode_sid(struct obd_device *obd, struct inode *inode,
2848 void *handle, struct lustre_id *id)
2853 LASSERT(id != NULL);
2854 LASSERT(obd != NULL);
2855 LASSERT(inode != NULL);
2857 rc = fsfilt_set_md(obd, inode, handle, &id->li_fid,
2858 sizeof(id->li_fid), EA_SID);
2860 CERROR("fsfilt_set_md() failed, rc = %d\n", rc);
2868 * reads inode id on master MDS. This is usualy done by CMOBD to update requests
2869 * to master MDS by correct store cookie, needed to find inode on master MDS
2872 int mds_read_inode_mid(struct obd_device *obd, struct inode *inode,
2873 struct lustre_id *id)
2878 LASSERT(id != NULL);
2879 LASSERT(obd != NULL);
2880 LASSERT(inode != NULL);
2882 rc = fsfilt_get_md(obd, inode, id, sizeof(*id), EA_MID);
2884 CERROR("fsfilt_get_md() failed, rc = %d\n", rc);
2897 * updates master inode id. Usualy this is done by CMOBD after an inode is
2898 * created and relationship between cache MDS and master one should be
2901 int mds_update_inode_mid(struct obd_device *obd, struct inode *inode,
2902 void *handle, struct lustre_id *id)
2907 LASSERT(id != NULL);
2908 LASSERT(obd != NULL);
2909 LASSERT(inode != NULL);
2911 rc = fsfilt_set_md(obd, inode, handle, id,
2912 sizeof(*id), EA_MID);
2914 CERROR("fsfilt_set_md() failed, "
2922 /* mount the file system (secretly) */
2923 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
2925 struct lustre_cfg* lcfg = buf;
2926 struct mds_obd *mds = &obd->u.mds;
2927 struct lvfs_obd_ctxt *lvfs_ctxt = NULL;
2928 char *options = NULL;
2929 struct vfsmount *mnt;
2936 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
2937 RETURN(rc = -EINVAL);
2939 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
2940 if (IS_ERR(obd->obd_fsops))
2941 RETURN(rc = PTR_ERR(obd->obd_fsops));
2943 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
2945 page = __get_free_page(GFP_KERNEL);
2949 options = (char *)page;
2950 memset(options, 0, PAGE_SIZE);
2953 * here we use "iopen_nopriv" hardcoded, because it affects MDS utility
2954 * and the rest of options are passed by mount options. Probably this
2955 * should be moved to somewhere else like startup scripts or lconf. */
2956 sprintf(options, "iopen_nopriv,acl,user_xattr");
2957 if (lcfg->lcfg_inllen4 > 0 && lcfg->lcfg_inlbuf4)
2958 sprintf(options + strlen(options), ",%s",
2959 lcfg->lcfg_inlbuf4);
2961 /* we have to know mdsnum before touching underlying fs -bzzz */
2962 atomic_set(&mds->mds_open_count, 0);
2963 sema_init(&mds->mds_md_sem, 1);
2964 mds->mds_md_connected = 0;
2965 mds->mds_md_name = NULL;
2967 if (lcfg->lcfg_inllen5 > 0 && lcfg->lcfg_inlbuf5 &&
2968 strncmp(lcfg->lcfg_inlbuf5, "dumb", lcfg->lcfg_inllen5)) {
2971 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
2972 obd->obd_name, lcfg->lcfg_inlbuf5);
2974 generate_random_uuid(uuid);
2975 class_uuid_unparse(uuid, &mds->mds_md_uuid);
2977 OBD_ALLOC(mds->mds_md_name, lcfg->lcfg_inllen5);
2978 if (mds->mds_md_name == NULL)
2979 RETURN(rc = -ENOMEM);
2981 memcpy(mds->mds_md_name, lcfg->lcfg_inlbuf5,
2982 lcfg->lcfg_inllen5);
2984 rc = mds_md_connect(obd, mds->mds_md_name);
2986 OBD_FREE(mds->mds_md_name, lcfg->lcfg_inllen5);
2991 mds->mds_obd_type = MDS_MASTER_OBD;
2993 if (lcfg->lcfg_inllen6 > 0 && lcfg->lcfg_inlbuf6 &&
2994 strncmp(lcfg->lcfg_inlbuf6, "dumb", lcfg->lcfg_inllen6)) {
2995 if (!memcmp(lcfg->lcfg_inlbuf6, "master", strlen("master"))) {
2996 mds->mds_obd_type = MDS_MASTER_OBD;
2997 } else if (!memcmp(lcfg->lcfg_inlbuf6, "cache", strlen("cache"))) {
2998 mds->mds_obd_type = MDS_CACHE_OBD;
3002 rc = lvfs_mount_fs(lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2,
3003 options, 0, &lvfs_ctxt);
3007 if (rc || !lvfs_ctxt) {
3008 CERROR("lvfs_mount_fs failed: rc = %d\n", rc);
3012 mnt = lvfs_ctxt->loc_mnt;
3013 mds->mds_lvfs_ctxt = lvfs_ctxt;
3014 ll_clear_rdonly(ll_sbdev(mnt->mnt_sb));
3016 CDEBUG(D_SUPER, "%s: mnt = %p\n", lcfg->lcfg_inlbuf1, mnt);
3018 sema_init(&mds->mds_epoch_sem, 1);
3019 atomic_set(&mds->mds_real_clients, 0);
3020 spin_lock_init(&mds->mds_transno_lock);
3021 spin_lock_init(&mds->mds_last_fid_lock);
3022 sema_init(&mds->mds_orphan_recovery_sem, 1);
3023 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
3025 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
3026 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
3028 if (obd->obd_namespace == NULL) {
3029 mds_cleanup(obd, 0);
3030 GOTO(err_put, rc = -ENOMEM);
3032 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
3034 rc = mds_fs_setup(obd, mnt);
3036 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
3041 rc = llog_start_commit_thread();
3045 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3046 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)) {
3049 generate_random_uuid(uuid);
3050 class_uuid_unparse(uuid, &mds->mds_dt_uuid);
3052 OBD_ALLOC(mds->mds_profile, lcfg->lcfg_inllen3);
3053 if (mds->mds_profile == NULL)
3054 GOTO(err_fs, rc = -ENOMEM);
3056 memcpy(mds->mds_profile, lcfg->lcfg_inlbuf3,
3057 lcfg->lcfg_inllen3);
3061 * setup root dir and files ID dir if lmv already connected, or there is
3064 if (mds->mds_md_exp || (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3065 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)))
3067 rc = mds_fs_setup_rootid(obd);
3071 rc = mds_fs_setup_virtid(obd);
3076 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3077 "mds_ldlm_client", &obd->obd_ldlm_client);
3078 obd->obd_replayable = 1;
3080 rc = mds_postsetup(obd);
3087 /* No extra cleanup needed for llog_init_commit_thread() */
3088 mds_fs_cleanup(obd, 0);
3090 ldlm_namespace_free(obd->obd_namespace, 0);
3091 obd->obd_namespace = NULL;
3094 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3098 fsfilt_put_ops(obd->obd_fsops);
3102 static int mds_postsetup(struct obd_device *obd)
3104 struct mds_obd *mds = &obd->u.mds;
3108 rc = obd_llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
3109 obd, 0, NULL, &llog_lvfs_ops);
3113 if (mds->mds_profile) {
3114 struct llog_ctxt *lgctxt;
3115 struct lvfs_run_ctxt saved;
3116 struct lustre_profile *lprof;
3117 struct config_llog_instance cfg;
3119 cfg.cfg_instance = NULL;
3120 cfg.cfg_uuid = mds->mds_dt_uuid;
3121 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3123 lgctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
3125 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3126 GOTO(err_llog, rc = -EINVAL);
3129 rc = class_config_process_llog(lgctxt, mds->mds_profile, &cfg);
3130 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3135 lprof = class_get_profile(mds->mds_profile);
3136 if (lprof == NULL) {
3137 CERROR("No profile found: %s\n", mds->mds_profile);
3138 GOTO(err_cleanup, rc = -ENOENT);
3140 rc = mds_dt_connect(obd, lprof->lp_lov);
3142 GOTO(err_cleanup, rc);
3144 rc = mds_md_postsetup(obd);
3146 GOTO(err_cleanup, rc);
3153 obd_llog_cleanup(llog_get_context(&obd->obd_llogs,
3154 LLOG_CONFIG_ORIG_CTXT));
3158 int mds_postrecov(struct obd_device *obd)
3160 struct mds_obd *mds = &obd->u.mds;
3161 struct llog_ctxt *ctxt;
3162 int rc, item = 0, valsize;
3166 LASSERT(!obd->obd_recovering);
3167 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
3168 LASSERT(ctxt != NULL);
3170 /* set nextid first, so we are sure it happens */
3171 rc = mds_dt_set_nextid(obd);
3173 CERROR("%s: mds_dt_set_nextid() failed\n", obd->obd_name);
3177 /* clean PENDING dir */
3178 rc = mds_cleanup_orphans(obd);
3183 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
3184 valsize = sizeof(group);
3185 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"), "mds_conn",
3190 rc = llog_connect(ctxt, obd->u.mds.mds_dt_desc.ld_tgt_count,
3193 CERROR("%s: failed at llog_origin_connect: %d\n",
3198 /* remove the orphaned precreated objects */
3199 rc = mds_dt_clearorphans(mds, NULL /* all OSTs */);
3204 RETURN(rc < 0 ? rc : item);
3207 /* cleanup all llogging subsystems */
3208 rc = obd_llog_finish(obd, &obd->obd_llogs,
3209 mds->mds_dt_desc.ld_tgt_count);
3211 CERROR("%s: failed to cleanup llogging subsystems\n",
3216 int mds_dt_clean(struct obd_device *obd)
3218 struct mds_obd *mds = &obd->u.mds;
3221 if (mds->mds_profile) {
3223 struct llog_ctxt *llctx;
3224 struct lvfs_run_ctxt saved;
3225 struct config_llog_instance cfg;
3226 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
3228 OBD_ALLOC(cln_prof, len);
3229 sprintf(cln_prof, "%s-clean", mds->mds_profile);
3231 cfg.cfg_instance = NULL;
3232 cfg.cfg_uuid = mds->mds_dt_uuid;
3234 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3235 llctx = llog_get_context(&obd->obd_llogs,
3236 LLOG_CONFIG_ORIG_CTXT);
3237 class_config_process_llog(llctx, cln_prof, &cfg);
3238 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3240 OBD_FREE(cln_prof, len);
3241 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
3242 mds->mds_profile = NULL;
3247 int mds_md_clean(struct obd_device *obd)
3249 struct mds_obd *mds = &obd->u.mds;
3252 if (mds->mds_md_name) {
3253 OBD_FREE(mds->mds_md_name, strlen(mds->mds_md_name) + 1);
3254 mds->mds_md_name = NULL;
3259 static int mds_precleanup(struct obd_device *obd, int flags)
3265 mds_dt_disconnect(obd, flags);
3267 obd_llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
3271 extern void lgss_svc_cache_purge_all(void);
3272 static int mds_cleanup(struct obd_device *obd, int flags)
3274 struct mds_obd *mds = &obd->u.mds;
3277 if (mds->mds_sb == NULL)
3280 mds_update_server_data(obd, 1);
3281 mds_update_last_fid(obd, NULL, 1);
3283 if (mds->mds_dt_objids != NULL) {
3284 int size = mds->mds_dt_desc.ld_tgt_count *
3286 OBD_FREE(mds->mds_dt_objids, size);
3288 mds_fs_cleanup(obd, flags);
3292 /* 2 seems normal on mds, (may_umount() also expects 2
3293 fwiw), but we only see 1 at this point in obdfilter. */
3294 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3298 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
3300 spin_lock_bh(&obd->obd_processing_task_lock);
3301 if (obd->obd_recovering) {
3302 target_cancel_recovery_timer(obd);
3303 obd->obd_recovering = 0;
3305 spin_unlock_bh(&obd->obd_processing_task_lock);
3308 fsfilt_put_ops(obd->obd_fsops);
3312 lgss_svc_cache_purge_all();
3317 static int set_security(const char *value, char **sec)
3321 if (!strcmp(value, "null"))
3323 else if (!strcmp(value, "krb5i"))
3325 else if (!strcmp(value, "krb5p"))
3328 CERROR("Unrecognized value, force use NULL\n");
3335 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
3337 struct lustre_cfg *lcfg = buf;
3338 struct mds_obd *mds = &obd->u.mds;
3342 switch(lcfg->lcfg_command) {
3343 case LCFG_SET_SECURITY: {
3344 if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inllen2)
3345 GOTO(out, rc = -EINVAL);
3347 if (!strcmp(lcfg->lcfg_inlbuf1, "mds_mds_sec"))
3348 rc = set_security(lcfg->lcfg_inlbuf2,
3350 else if (!strcmp(lcfg->lcfg_inlbuf1, "mds_ost_sec"))
3351 rc = set_security(lcfg->lcfg_inlbuf2,
3354 CERROR("Unrecognized key\n");
3360 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
3361 GOTO(out, rc = -EINVAL);
3369 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
3371 struct ldlm_lock *new_lock,
3372 struct ldlm_lock **old_lock,
3373 struct lustre_handle *lockh)
3375 struct obd_export *exp = req->rq_export;
3376 struct obd_device *obd = exp->exp_obd;
3377 struct ldlm_request *dlmreq =
3378 lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq));
3379 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
3380 struct list_head *iter;
3382 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3385 l_lock(&obd->obd_namespace->ns_lock);
3386 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
3387 struct ldlm_lock *lock;
3388 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
3389 if (lock == new_lock)
3391 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
3392 lockh->cookie = lock->l_handle.h_cookie;
3393 LDLM_DEBUG(lock, "restoring lock cookie");
3394 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
3397 *old_lock = LDLM_LOCK_GET(lock);
3398 l_unlock(&obd->obd_namespace->ns_lock);
3402 l_unlock(&obd->obd_namespace->ns_lock);
3404 /* If the xid matches, then we know this is a resent request,
3405 * and allow it. (It's probably an OPEN, for which we don't
3408 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
3412 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
3415 /* This remote handle isn't enqueued, so we never received or
3416 * processed this request. Clear MSG_RESENT, because it can
3417 * be handled like any normal request now. */
3419 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3421 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
3425 int intent_disposition(struct ldlm_reply *rep, int flag)
3429 return (rep->lock_policy_res1 & flag);
3432 void intent_set_disposition(struct ldlm_reply *rep, int flag)
3436 rep->lock_policy_res1 |= flag;
3439 static int mds_intent_policy(struct ldlm_namespace *ns,
3440 struct ldlm_lock **lockp, void *req_cookie,
3441 ldlm_mode_t mode, int flags, void *data)
3443 struct ptlrpc_request *req = req_cookie;
3444 struct ldlm_lock *lock = *lockp;
3445 struct ldlm_intent *it;
3446 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
3447 struct ldlm_reply *rep;
3448 struct lustre_handle lockh[2] = {{0}, {0}};
3449 struct ldlm_lock *new_lock = NULL;
3450 int getattr_part = MDS_INODELOCK_UPDATE;
3451 int rc, reply_buffers;
3452 int repsize[5] = {sizeof(struct ldlm_reply),
3453 sizeof(struct mds_body),
3454 mds->mds_max_mdsize};
3456 int offset = MDS_REQ_INTENT_REC_OFF;
3459 LASSERT(req != NULL);
3460 MD_COUNTER_INCREMENT(req->rq_export->exp_obd, intent_lock);
3462 if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) {
3463 /* No intent was provided */
3464 int size = sizeof(struct ldlm_reply);
3465 rc = lustre_pack_reply(req, 1, &size, NULL);
3470 it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it),
3471 lustre_swab_ldlm_intent);
3473 CERROR("Intent missing\n");
3474 RETURN(req->rq_status = -EFAULT);
3477 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
3480 if (it->opc & ( IT_OPEN | IT_GETATTR | IT_LOOKUP | IT_CHDIR )) {
3483 repsize[4] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
3486 rc = lustre_pack_reply(req, reply_buffers, repsize, NULL);
3488 RETURN(req->rq_status = rc);
3490 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
3491 LASSERT(rep != NULL);
3493 intent_set_disposition(rep, DISP_IT_EXECD);
3495 /* execute policy */
3496 switch ((long)it->opc) {
3498 case IT_CREAT|IT_OPEN:
3499 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3501 /* XXX swab here to assert that an mds_open reint
3502 * packet is following */
3503 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3505 rep->lock_policy_res2 = mds_reint(req, offset, lockh);
3507 if (rep->lock_policy_res2) {
3509 * mds_open() returns ENOLCK where it should return
3510 * zero, but it has no lock to return.
3512 if (rep->lock_policy_res2 == ENOLCK)
3513 rep->lock_policy_res2 = 0;
3515 RETURN(ELDLM_LOCK_ABORTED);
3519 * IT_OPEN may return lock on cross-node dentry that we want to
3520 * hold during attr retrival -bzzz
3522 if (lockh[0].cookie == 0)
3523 RETURN(ELDLM_LOCK_ABORTED);
3527 getattr_part = MDS_INODELOCK_LOOKUP;
3530 getattr_part |= MDS_INODELOCK_LOOKUP;
3532 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3533 lock, &new_lock, lockh);
3534 rep->lock_policy_res2 = mds_getattr_lock(req, offset, lockh,
3536 /* FIXME: LDLM can set req->rq_status. MDS sets
3537 policy_res{1,2} with disposition and status.
3538 - replay: returns 0 & req->status is old status
3539 - otherwise: returns req->status */
3540 if (intent_disposition(rep, DISP_LOOKUP_NEG))
3541 rep->lock_policy_res2 = 0;
3542 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
3543 rep->lock_policy_res2)
3544 RETURN(ELDLM_LOCK_ABORTED);
3545 if (req->rq_status != 0) {
3547 rep->lock_policy_res2 = req->rq_status;
3548 RETURN(ELDLM_LOCK_ABORTED);
3552 rc = mds_lock_and_check_slave(offset, req, lockh);
3553 if ((rep->lock_policy_res2 = rc)) {
3555 rep->lock_policy_res2 = 0;
3556 RETURN(ELDLM_LOCK_ABORTED);
3560 CERROR("Unhandled intent "LPD64"\n", it->opc);
3564 /* By this point, whatever function we called above must have either
3565 * filled in 'lockh', been an intent replay, or returned an error. We
3566 * want to allow replayed RPCs to not get a lock, since we would just
3567 * drop it below anyways because lock replay is done separately by the
3568 * client afterwards. For regular RPCs we want to give the new lock to
3569 * the client instead of whatever lock it was about to get. */
3570 if (new_lock == NULL)
3571 new_lock = ldlm_handle2lock(&lockh[0]);
3572 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
3575 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
3576 it->opc, lockh[0].cookie);
3578 /* If we've already given this lock to a client once, then we should
3579 * have no readers or writers. Otherwise, we should have one reader
3580 * _or_ writer ref (which will be zeroed below) before returning the
3581 * lock to a client. */
3582 if (new_lock->l_export == req->rq_export) {
3583 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3585 LASSERT(new_lock->l_export == NULL);
3586 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3591 if (new_lock->l_export == req->rq_export) {
3592 /* Already gave this to the client, which means that we
3593 * reconstructed a reply. */
3594 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3596 RETURN(ELDLM_LOCK_REPLACED);
3599 /* Fixup the lock to be given to the client */
3600 l_lock(&new_lock->l_resource->lr_namespace->ns_lock);
3601 new_lock->l_readers = 0;
3602 new_lock->l_writers = 0;
3604 new_lock->l_export = class_export_get(req->rq_export);
3605 list_add(&new_lock->l_export_chain,
3606 &new_lock->l_export->exp_ldlm_data.led_held_locks);
3608 new_lock->l_blocking_ast = lock->l_blocking_ast;
3609 new_lock->l_completion_ast = lock->l_completion_ast;
3611 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
3612 sizeof(lock->l_remote_handle));
3614 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3616 LDLM_LOCK_PUT(new_lock);
3617 l_unlock(&new_lock->l_resource->lr_namespace->ns_lock);
3619 RETURN(ELDLM_LOCK_REPLACED);
3622 int mds_attach(struct obd_device *dev, obd_count len, void *data)
3624 struct lprocfs_static_vars lvars;
3627 lprocfs_init_multi_vars(0, &lvars);
3629 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
3633 return lprocfs_alloc_md_stats(dev, 0);
3636 int mds_detach(struct obd_device *dev)
3638 lprocfs_free_md_stats(dev);
3639 return lprocfs_obd_detach(dev);
3642 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
3644 struct lprocfs_static_vars lvars;
3646 lprocfs_init_multi_vars(1, &lvars);
3647 return lprocfs_obd_attach(dev, lvars.obd_vars);
3650 int mdt_detach(struct obd_device *dev)
3652 return lprocfs_obd_detach(dev);
3655 static int mdt_setup(struct obd_device *obd, obd_count len, void *buf)
3657 struct mds_obd *mds = &obd->u.mds;
3662 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3663 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
3664 MDS_SERVICE_WATCHDOG_TIMEOUT,
3665 mds_handle, "mds", obd->obd_proc_entry);
3667 if (!mds->mds_service) {
3668 CERROR("failed to start service\n");
3672 rc = ptlrpc_start_n_threads(obd, mds->mds_service, MDT_NUM_THREADS,
3675 GOTO(err_thread, rc);
3677 mds->mds_setattr_service =
3678 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3679 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
3680 MDS_SERVICE_WATCHDOG_TIMEOUT,
3681 mds_handle, "mds_setattr",
3682 obd->obd_proc_entry);
3683 if (!mds->mds_setattr_service) {
3684 CERROR("failed to start getattr service\n");
3685 GOTO(err_thread, rc = -ENOMEM);
3688 rc = ptlrpc_start_n_threads(obd, mds->mds_setattr_service,
3689 MDT_NUM_THREADS, "ll_mdt_attr");
3691 GOTO(err_thread2, rc);
3693 mds->mds_readpage_service =
3694 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3695 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
3696 MDS_SERVICE_WATCHDOG_TIMEOUT,
3697 mds_handle, "mds_readpage",
3698 obd->obd_proc_entry);
3699 if (!mds->mds_readpage_service) {
3700 CERROR("failed to start readpage service\n");
3701 GOTO(err_thread2, rc = -ENOMEM);
3704 rc = ptlrpc_start_n_threads(obd, mds->mds_readpage_service,
3705 MDT_NUM_THREADS, "ll_mdt_rdpg");
3708 GOTO(err_thread3, rc);
3713 ptlrpc_unregister_service(mds->mds_readpage_service);
3715 ptlrpc_unregister_service(mds->mds_setattr_service);
3717 ptlrpc_unregister_service(mds->mds_service);
3721 static int mdt_cleanup(struct obd_device *obd, int flags)
3723 struct mds_obd *mds = &obd->u.mds;
3726 ptlrpc_stop_all_threads(mds->mds_readpage_service);
3727 ptlrpc_unregister_service(mds->mds_readpage_service);
3729 ptlrpc_stop_all_threads(mds->mds_setattr_service);
3730 ptlrpc_unregister_service(mds->mds_setattr_service);
3732 ptlrpc_stop_all_threads(mds->mds_service);
3733 ptlrpc_unregister_service(mds->mds_service);
3738 static struct dentry *mds_lvfs_id2dentry(__u64 ino, __u32 gen,
3739 __u64 gr, void *data)
3741 struct lustre_id id;
3742 struct obd_device *obd = data;
3746 return mds_id2dentry(obd, &id, NULL);
3749 static int mds_get_info(struct obd_export *exp, __u32 keylen,
3750 void *key, __u32 *valsize, void *val)
3752 struct obd_device *obd;
3753 struct mds_obd *mds;
3756 obd = class_exp2obd(exp);
3760 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
3761 exp->exp_handle.h_cookie);
3765 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
3766 /* get log_context handle. */
3767 unsigned long *llh_handle = val;
3768 *valsize = sizeof(unsigned long);
3769 *llh_handle = (unsigned long)obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT];
3772 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
3773 /* get log_context handle. */
3774 unsigned long *sb = val;
3775 *valsize = sizeof(unsigned long);
3776 *sb = (unsigned long)obd->u.mds.mds_sb;
3780 if (keylen >= strlen("mdsize") && memcmp(key, "mdsize", keylen) == 0) {
3781 __u32 *mdsize = val;
3782 *valsize = sizeof(*mdsize);
3783 *mdsize = mds->mds_max_mdsize;
3787 if (keylen >= strlen("mdsnum") && strcmp(key, "mdsnum") == 0) {
3788 __u32 *mdsnum = val;
3789 *valsize = sizeof(*mdsnum);
3790 *mdsnum = mds->mds_num;
3794 if (keylen >= strlen("rootid") && strcmp(key, "rootid") == 0) {
3795 struct lustre_id *rootid = val;
3796 *valsize = sizeof(struct lustre_id);
3797 *rootid = mds->mds_rootid;
3801 CDEBUG(D_IOCTL, "invalid key\n");
3805 struct lvfs_callback_ops mds_lvfs_ops = {
3806 l_id2dentry: mds_lvfs_id2dentry,
3809 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
3810 int objcount, struct obd_ioobj *obj,
3811 int niocount, struct niobuf_remote *nb,
3812 struct niobuf_local *res,
3813 struct obd_trans_info *oti);
3815 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
3816 int objcount, struct obd_ioobj *obj, int niocount,
3817 struct niobuf_local *res, struct obd_trans_info *oti,
3820 /* use obd ops to offer management infrastructure */
3821 static struct obd_ops mds_obd_ops = {
3822 .o_owner = THIS_MODULE,
3823 .o_attach = mds_attach,
3824 .o_detach = mds_detach,
3825 .o_connect = mds_connect,
3826 .o_connect_post = mds_connect_post,
3827 .o_init_export = mds_init_export,
3828 .o_destroy_export = mds_destroy_export,
3829 .o_disconnect = mds_disconnect,
3830 .o_setup = mds_setup,
3831 .o_precleanup = mds_precleanup,
3832 .o_cleanup = mds_cleanup,
3833 .o_process_config = mds_process_config,
3834 .o_postrecov = mds_postrecov,
3835 .o_statfs = mds_obd_statfs,
3836 .o_iocontrol = mds_iocontrol,
3837 .o_create = mds_obd_create,
3838 .o_destroy = mds_obd_destroy,
3839 .o_llog_init = mds_llog_init,
3840 .o_llog_finish = mds_llog_finish,
3841 .o_notify = mds_notify,
3842 .o_get_info = mds_get_info,
3843 .o_set_info = mds_set_info,
3844 .o_preprw = mds_preprw,
3845 .o_commitrw = mds_commitrw,
3848 static struct obd_ops mdt_obd_ops = {
3849 .o_owner = THIS_MODULE,
3850 .o_attach = mdt_attach,
3851 .o_detach = mdt_detach,
3852 .o_setup = mdt_setup,
3853 .o_cleanup = mdt_cleanup,
3856 static int __init mds_init(void)
3858 struct lprocfs_static_vars lvars;
3860 mds_init_lsd_cache();
3862 lprocfs_init_multi_vars(0, &lvars);
3863 class_register_type(&mds_obd_ops, NULL, lvars.module_vars,
3865 lprocfs_init_multi_vars(1, &lvars);
3866 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars,
3872 static void /*__exit*/ mds_exit(void)
3874 mds_cleanup_lsd_cache();
3876 class_unregister_type(LUSTRE_MDS_NAME);
3877 class_unregister_type(LUSTRE_MDT_NAME);
3880 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
3881 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
3882 MODULE_LICENSE("GPL");
3884 module_init(mds_init);
3885 module_exit(mds_exit);