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>
58 #include <linux/lustre_acl.h>
59 #include "mds_internal.h"
61 static int mds_intent_policy(struct ldlm_namespace *ns,
62 struct ldlm_lock **lockp, void *req_cookie,
63 ldlm_mode_t mode, int flags, void *data);
64 static int mds_postsetup(struct obd_device *obd);
65 static int mds_cleanup(struct obd_device *obd, int flags);
68 /* Assumes caller has already pushed into the kernel filesystem context */
69 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
70 loff_t offset, int count)
72 struct ptlrpc_bulk_desc *desc;
73 struct l_wait_info lwi;
75 int rc = 0, npages, i, tmpcount, tmpsize = 0;
78 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
80 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
81 OBD_ALLOC(pages, sizeof(*pages) * npages);
83 GOTO(out, rc = -ENOMEM);
85 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
88 GOTO(out_free, rc = -ENOMEM);
90 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
91 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
93 pages[i] = alloc_pages(GFP_KERNEL, 0);
95 GOTO(cleanup_buf, rc = -ENOMEM);
97 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
100 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
101 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
102 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
103 tmpsize, offset, file->f_dentry->d_inode->i_ino,
104 file->f_dentry->d_inode->i_size);
106 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
107 kmap(pages[i]), tmpsize, &offset);
111 GOTO(cleanup_buf, rc = -EIO);
114 LASSERT(desc->bd_nob == count);
116 rc = ptlrpc_start_bulk_transfer(desc);
118 GOTO(cleanup_buf, rc);
120 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
121 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
122 OBD_FAIL_MDS_SENDPAGE, rc = -EIO);
123 GOTO(abort_bulk, rc);
126 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
127 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
128 LASSERT (rc == 0 || rc == -ETIMEDOUT);
131 if (desc->bd_success &&
132 desc->bd_nob_transferred == count)
133 GOTO(cleanup_buf, rc);
135 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
138 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
139 (rc == -ETIMEDOUT) ? "timeout" : "network error",
140 desc->bd_nob_transferred, count,
141 req->rq_export->exp_client_uuid.uuid,
142 req->rq_export->exp_connection->c_remote_uuid.uuid);
144 ptlrpc_fail_export(req->rq_export);
148 ptlrpc_abort_bulk (desc);
150 for (i = 0; i < npages; i++)
152 __free_pages(pages[i], 0);
154 ptlrpc_free_bulk(desc);
156 OBD_FREE(pages, sizeof(*pages) * npages);
161 extern char *ldlm_lockname[];
163 int mds_lock_mode_for_dir(struct obd_device *obd,
164 struct dentry *dentry, int mode)
166 int ret_mode = 0, split;
168 /* any dir access needs couple locks:
169 * 1) on part of dir we gonna lookup/modify in
170 * 2) on a whole dir to protect it from concurrent splitting
171 * and to flush client's cache for readdir()
172 * so, for a given mode and dentry this routine decides what
173 * lock mode to use for lock #2:
174 * 1) if caller's gonna lookup in dir then we need to protect
175 * dir from being splitted only - LCK_CR
176 * 2) if caller's gonna modify dir then we need to protect
177 * dir from being splitted and to flush cache - LCK_CW
178 * 3) if caller's gonna modify dir and that dir seems ready
179 * for splitting then we need to protect it from any
180 * type of access (lookup/modify/split) - LCK_EX -bzzz */
182 split = mds_splitting_expected(obd, dentry);
185 * it is important to check here only for MDS_NO_SPLITTABLE. The reason
186 * is that MDS_NO_SPLITTABLE means dir is not splittable in principle
187 * and another thread will not split it on the quiet. But if we have
188 * MDS_NO_SPLIT_EXPECTED, this means, that dir may be splitted anytime,
189 * but not now (for current thread) and we should consider that it can
190 * happen soon and go that branch which can yield LCK_EX to protect from
191 * possible splitting.
193 if (split == MDS_NO_SPLITTABLE) {
195 * this inode won't be splitted. so we need not to protect from
196 * just flush client's cache on modification.
203 if (mode == LCK_EX) {
205 } else if (mode == LCK_PR) {
207 } else if (mode == LCK_PW) {
209 * caller gonna modify directory. We use concurrent
210 * write lock here to retract client's cache for
213 if (split == MDS_EXPECT_SPLIT) {
215 * splitting possible. serialize any access the
216 * idea is that first one seen dir is splittable
217 * is given exclusive lock and split
218 * directory. caller passes lock mode to
219 * mds_try_to_split_dir() and splitting would be
220 * done with exclusive lock only -bzzz.
222 CDEBUG(D_OTHER, "%s: gonna split %lu/%lu\n",
224 (unsigned long)dentry->d_inode->i_ino,
225 (unsigned long)dentry->d_inode->i_generation);
236 /* only valid locked dentries or errors should be returned */
237 struct dentry *mds_id2locked_dentry(struct obd_device *obd, struct lustre_id *id,
238 struct vfsmount **mnt, int lock_mode,
239 struct lustre_handle *lockh, int *mode,
240 char *name, int namelen, __u64 lockpart)
242 struct dentry *de = mds_id2dentry(obd, id, mnt), *retval = de;
243 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
244 struct ldlm_res_id res_id = { .name = {0} };
252 res_id.name[0] = id_fid(id);
253 res_id.name[1] = id_group(id);
256 if (name && IS_PDIROPS(de->d_inode)) {
257 ldlm_policy_data_t cpolicy =
258 { .l_inodebits = { MDS_INODELOCK_UPDATE } };
259 LASSERT(mode != NULL);
260 *mode = mds_lock_mode_for_dir(obd, de, lock_mode);
262 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
264 &cpolicy, *mode, &flags,
266 ldlm_completion_ast, NULL, NULL,
267 NULL, 0, NULL, lockh + 1);
268 if (rc != ELDLM_OK) {
270 RETURN(ERR_PTR(-ENOLCK));
275 res_id.name[2] = full_name_hash(name, namelen);
277 CDEBUG(D_INFO, "take lock on "DLID4":"LPX64"\n",
278 OLID4(id), res_id.name[2]);
281 #warning "No PDIROPS support in the kernel"
283 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
284 LDLM_IBITS, &policy, lock_mode, &flags,
285 mds_blocking_ast, ldlm_completion_ast,
286 NULL, NULL, NULL, 0, NULL, lockh);
287 if (rc != ELDLM_OK) {
289 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
292 ldlm_lock_decref(lockh + 1, *mode);
299 #ifndef DCACHE_DISCONNECTED
300 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
303 /* Look up an entry by inode number. This function ONLY returns valid dget'd
304 * dentries with an initialized inode or errors */
305 struct dentry *mds_id2dentry(struct obd_device *obd, struct lustre_id *id,
306 struct vfsmount **mnt)
308 unsigned long ino = (unsigned long)id_ino(id);
309 __u32 generation = (__u32)id_gen(id);
310 struct mds_obd *mds = &obd->u.mds;
311 struct dentry *result;
316 RETURN(ERR_PTR(-ESTALE));
318 snprintf(idname, sizeof(idname), "0x%lx", ino);
320 CDEBUG(D_DENTRY, "--> mds_id2dentry: ino/gen %lu/%u, sb %p\n",
321 ino, generation, mds->mds_sb);
323 /* under ext3 this is neither supposed to return bad inodes nor NULL
325 result = ll_lookup_one_len(idname, mds->mds_id_de,
330 inode = result->d_inode;
332 RETURN(ERR_PTR(-ENOENT));
334 if (is_bad_inode(inode)) {
335 CERROR("bad inode returned %lu/%u\n",
336 inode->i_ino, inode->i_generation);
338 RETURN(ERR_PTR(-ENOENT));
341 /* here we disabled generation check, as root inode i_generation
342 * of cache mds and real mds are different. */
343 if (inode->i_ino != id_ino(&mds->mds_rootid) && generation &&
344 inode->i_generation != generation) {
345 /* we didn't find the right inode.. */
346 CERROR("bad inode %lu, link: %lu, ct: %d, generation %u/%u\n",
347 inode->i_ino, (unsigned long)inode->i_nlink,
348 atomic_read(&inode->i_count), inode->i_generation,
351 RETURN(ERR_PTR(-ENOENT));
355 *mnt = mds->mds_vfsmnt;
363 int mds_req_add_idmapping(struct ptlrpc_request *req,
364 struct mds_export_data *med)
366 struct mds_req_sec_desc *rsd;
367 struct lustre_sec_desc *lsd;
370 if (!med->med_remote)
373 /* maybe we should do it more completely: invalidate the gss ctxt? */
374 if (req->rq_mapped_uid == MDS_IDMAP_NOTFOUND) {
375 CWARN("didn't find mapped uid\n");
379 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
381 CERROR("Can't unpack security desc\n");
385 lsd = mds_get_lsd(req->rq_mapped_uid);
387 CERROR("can't get LSD(%u), no mapping added\n",
392 rc = mds_idmap_add(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
393 rsd->rsd_gid, lsd->lsd_gid);
399 int mds_req_del_idmapping(struct ptlrpc_request *req,
400 struct mds_export_data *med)
402 struct mds_req_sec_desc *rsd;
403 struct lustre_sec_desc *lsd;
406 if (!med->med_remote)
409 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
411 CERROR("Can't unpack security desc\n");
415 LASSERT(req->rq_mapped_uid != -1);
416 lsd = mds_get_lsd(req->rq_mapped_uid);
418 CERROR("can't get LSD(%u), no idmapping deleted\n",
423 rc = mds_idmap_del(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
424 rsd->rsd_gid, lsd->lsd_gid);
429 static int mds_init_export_data(struct ptlrpc_request *req,
430 struct mds_export_data *med)
432 struct obd_connect_data *data, *reply;
433 int ask_remote, ask_local;
436 data = lustre_msg_buf(req->rq_reqmsg, 5, sizeof(*data));
437 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*data));
438 LASSERT(data && reply);
440 if (med->med_initialized) {
441 CWARN("med already initialized, reconnect?\n");
445 ask_remote = data->ocd_connect_flags & OBD_CONNECT_REMOTE;
446 ask_local = data->ocd_connect_flags & OBD_CONNECT_LOCAL;
448 /* currently the policy is simple: satisfy client as possible
451 if (req->rq_auth_uid == -1) {
453 CWARN("null sec is used, force to be local\n");
457 if (!req->rq_remote_realm)
458 CWARN("local realm asked to be remote\n");
460 } else if (ask_local) {
461 if (req->rq_remote_realm)
462 CWARN("remote realm asked to be local\n");
465 med->med_remote = (req->rq_remote_realm != 0);
468 med->med_nllu = data->ocd_nllu[0];
469 med->med_nllg = data->ocd_nllu[1];
471 med->med_initialized = 1;
473 reply->ocd_connect_flags &= ~(OBD_CONNECT_REMOTE | OBD_CONNECT_LOCAL);
474 if (med->med_remote) {
476 med->med_idmap = mds_idmap_alloc();
479 CERROR("Failed to alloc idmap, following request from "
480 "this client will be refused\n");
482 reply->ocd_connect_flags |= OBD_CONNECT_REMOTE;
483 CDEBUG(D_SEC, "set client as remote\n");
485 reply->ocd_connect_flags |= OBD_CONNECT_LOCAL;
486 CDEBUG(D_SEC, "set client as local\n");
492 static void mds_free_export_data(struct mds_export_data *med)
497 LASSERT(med->med_remote);
498 mds_idmap_free(med->med_idmap);
499 med->med_idmap = NULL;
502 /* Establish a connection to the MDS.
504 * This will set up an export structure for the client to hold state data about
505 * that client, like open files, the last operation number it did on the server,
508 static int mds_connect(struct lustre_handle *conn, struct obd_device *obd,
509 struct obd_uuid *cluuid, struct obd_connect_data *data,
512 struct mds_export_data *med;
513 struct mds_client_data *mcd;
514 struct obd_export *exp;
518 if (!conn || !obd || !cluuid)
521 /* XXX There is a small race between checking the list and adding a new
522 * connection for the same UUID, but the real threat (list corruption
523 * when multiple different clients connect) is solved.
525 * There is a second race between adding the export to the list, and
526 * filling in the client data below. Hence skipping the case of NULL
527 * mcd above. We should already be controlling multiple connects at the
528 * client, and we can't hold the spinlock over memory allocations
529 * without risk of deadlocking.
531 rc = class_connect(conn, obd, cluuid);
534 exp = class_conn2export(conn);
536 LASSERT(exp != NULL);
537 med = &exp->exp_mds_data;
539 OBD_ALLOC(mcd, sizeof(*mcd));
541 CERROR("%s: out of memory for client data.\n",
543 GOTO(out, rc = -ENOMEM);
546 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
549 rc = mds_client_add(obd, &obd->u.mds, med, -1);
557 OBD_FREE(mcd, sizeof(*mcd));
558 class_disconnect(exp, 0);
560 class_export_put(exp);
565 static int mds_connect_post(struct obd_export *exp, unsigned long flags)
567 struct obd_device *obd = exp->exp_obd;
568 struct mds_obd *mds = &obd->u.mds;
572 if (!(flags & OBD_OPT_MDS_CONNECTION)) {
573 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
574 atomic_inc(&mds->mds_real_clients);
575 CDEBUG(D_OTHER,"%s: peer from %s is real client (%d)\n",
576 obd->obd_name, exp->exp_client_uuid.uuid,
577 atomic_read(&mds->mds_real_clients));
578 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
580 if (mds->mds_md_name)
581 rc = mds_md_connect(obd, mds->mds_md_name);
586 static int mds_init_export(struct obd_export *exp)
588 struct mds_export_data *med = &exp->exp_mds_data;
590 INIT_LIST_HEAD(&med->med_open_head);
591 spin_lock_init(&med->med_open_lock);
595 static int mds_destroy_export(struct obd_export *export)
597 struct obd_device *obd = export->exp_obd;
598 struct mds_export_data *med = &export->exp_mds_data;
599 struct lvfs_run_ctxt saved;
603 mds_free_export_data(med);
604 target_destroy_export(export);
606 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
609 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
611 /* Close any open files (which may also cause orphan unlinking). */
612 spin_lock(&med->med_open_lock);
613 while (!list_empty(&med->med_open_head)) {
614 struct list_head *tmp = med->med_open_head.next;
615 struct mds_file_data *mfd =
616 list_entry(tmp, struct mds_file_data, mfd_list);
617 struct lustre_id sid;
619 BDEVNAME_DECLARE_STORAGE(btmp);
621 /* bug 1579: fix force-closing for 2.5 */
622 struct dentry *dentry = mfd->mfd_dentry;
624 list_del(&mfd->mfd_list);
625 spin_unlock(&med->med_open_lock);
627 down(&dentry->d_inode->i_sem);
628 rc = mds_read_inode_sid(obd, dentry->d_inode, &sid);
629 up(&dentry->d_inode->i_sem);
631 CERROR("Can't read inode self id, inode %lu, "
632 "rc %d\n", dentry->d_inode->i_ino, rc);
633 memset(&sid, 0, sizeof(sid));
636 /* If you change this message, be sure to update
637 * replay_single:test_46 */
638 CERROR("force closing client file handle for %.*s (%s:"
639 DLID4")\n", dentry->d_name.len, dentry->d_name.name,
640 ll_bdevname(dentry->d_inode->i_sb, btmp),
643 /* child inode->i_alloc_sem protects orphan_dec_test and
644 * is_orphan race, mds_mfd_close drops it */
645 DOWN_WRITE_I_ALLOC_SEM(dentry->d_inode);
646 rc = mds_mfd_close(NULL, 0, obd, mfd,
647 !(export->exp_flags & OBD_OPT_FAILOVER));
649 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
650 spin_lock(&med->med_open_lock);
652 spin_unlock(&med->med_open_lock);
653 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
657 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
661 static int mds_disconnect(struct obd_export *exp, unsigned long flags)
663 unsigned long irqflags;
664 struct obd_device *obd;
669 LASSERT(exp != NULL);
670 obd = class_exp2obd(exp);
672 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
673 exp->exp_handle.h_cookie);
679 * suppress any inter-mds requests durring disconnecting lmv if this is
680 * detected --force mode. This is needed to avoid endless recovery.
682 if (atomic_read(&mds->mds_real_clients) > 0 &&
683 !(exp->exp_flags & OBD_OPT_REAL_CLIENT))
684 flags |= OBD_OPT_FORCE;
686 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
687 && !atomic_read(&mds->mds_real_clients)) {
688 /* there was no client at all */
689 mds_md_disconnect(obd, flags);
692 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
693 && atomic_dec_and_test(&mds->mds_real_clients)) {
694 /* time to drop LMV connections */
695 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
696 "Disconnnect from LMV now\n",
697 obd->obd_name, exp->exp_client_uuid.uuid);
698 mds_md_disconnect(obd, flags);
701 spin_lock_irqsave(&exp->exp_lock, irqflags);
702 exp->exp_flags = flags;
703 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
705 /* disconnect early so that clients can't keep using export */
706 rc = class_disconnect(exp, flags);
707 ldlm_cancel_locks_for_export(exp);
709 /* complete all outstanding replies */
710 spin_lock_irqsave(&exp->exp_lock, irqflags);
711 while (!list_empty(&exp->exp_outstanding_replies)) {
712 struct ptlrpc_reply_state *rs =
713 list_entry(exp->exp_outstanding_replies.next,
714 struct ptlrpc_reply_state, rs_exp_list);
715 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
717 spin_lock(&svc->srv_lock);
718 list_del_init(&rs->rs_exp_list);
719 ptlrpc_schedule_difficult_reply(rs);
720 spin_unlock(&svc->srv_lock);
722 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
726 static int mds_getstatus(struct ptlrpc_request *req)
728 struct mds_obd *mds = mds_req2mds(req);
729 struct mds_body *body;
733 size = sizeof(*body);
735 rc = lustre_pack_reply(req, 1, &size, NULL);
736 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
737 CERROR("mds: out of memory for message: size=%d\n", size);
738 req->rq_status = -ENOMEM; /* superfluous? */
742 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
743 body->valid |= OBD_MD_FID;
745 memcpy(&body->id1, &mds->mds_rootid, sizeof(body->id1));
748 * the last_committed and last_xid fields are filled in for all replies
749 * already - no need to do so here also.
754 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
755 void *data, int flag)
760 if (flag == LDLM_CB_CANCELING) {
761 /* Don't need to do anything here. */
765 /* XXX layering violation! -phil */
766 l_lock(&lock->l_resource->lr_namespace->ns_lock);
769 * get this: if mds_blocking_ast is racing with mds_intent_policy, such
770 * that mds_blocking_ast is called just before l_i_p takes the ns_lock,
771 * then by the time we get the lock, we might not be the correct
772 * blocking function anymore. So check, and return early, if so.
774 if (lock->l_blocking_ast != mds_blocking_ast) {
775 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
779 lock->l_flags |= LDLM_FL_CBPENDING;
780 do_ast = (!lock->l_readers && !lock->l_writers);
781 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
784 struct lustre_handle lockh;
787 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
788 ldlm_lock2handle(lock, &lockh);
789 rc = ldlm_cli_cancel(&lockh);
791 CERROR("ldlm_cli_cancel: %d\n", rc);
793 LDLM_DEBUG(lock, "Lock still has references, will be "
799 static int mds_convert_md(struct obd_device *obd, struct inode *inode,
800 void *md, int size, int mea)
804 if (S_ISREG(inode->i_mode)) {
805 rc = mds_convert_lov_ea(obd, inode, md, size);
806 } else if (S_ISDIR(inode->i_mode)) {
808 rc = mds_convert_mea_ea(obd, inode, md, size);
810 rc = mds_convert_lov_ea(obd, inode, md, size);
813 CERROR("Invalid EA format (nor LOV or MEA) "
814 "is detected. Inode %lu/%u\n",
815 inode->i_ino, inode->i_generation);
821 int mds_get_md(struct obd_device *obd, struct inode *inode,
822 void *md, int *size, int lock, int mea)
831 rc = fsfilt_get_md(obd, inode, md, *size,
832 (mea ? EA_MEA : EA_LOV));
834 CERROR("Error %d reading eadata for ino %lu\n",
838 rc = mds_convert_md(obd, inode, md,
854 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
855 * Call with lock=0 if the caller has already taken the i_sem. */
856 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
857 struct mds_body *body, struct inode *inode, int lock, int mea)
859 struct mds_obd *mds = &obd->u.mds;
865 lmm = lustre_msg_buf(msg, offset, 0);
867 /* Some problem with getting eadata when I sized the reply
869 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
873 lmm_size = msg->buflens[offset];
875 /* I don't really like this, but it is a sanity check on the client
876 * MD request. However, if the client doesn't know how much space
877 * to reserve for the MD, it shouldn't be bad to have too much space.
879 if (lmm_size > mds->mds_max_mdsize) {
880 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
881 inode->i_ino, lmm_size, mds->mds_max_mdsize);
885 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, mea);
887 if (S_ISDIR(inode->i_mode))
888 body->valid |= OBD_MD_FLDIREA;
890 body->valid |= OBD_MD_FLEASIZE;
893 body->valid |= OBD_MD_MEA;
895 body->eadatasize = lmm_size;
901 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
902 struct mds_body *repbody, int reply_off)
904 struct inode *inode = dentry->d_inode;
909 symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
910 LASSERT(symname != NULL);
911 len = req->rq_repmsg->buflens[reply_off + 1];
913 rc = inode->i_op->readlink(dentry, symname, len);
915 CERROR("readlink failed: %d\n", rc);
916 } else if (rc != len - 1) {
917 CERROR ("Unexpected readlink rc %d: expecting %d\n",
921 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
922 repbody->valid |= OBD_MD_LINKNAME;
923 repbody->eadatasize = rc + 1;
924 symname[rc] = 0; /* NULL terminate */
931 int mds_pack_ea(struct dentry *dentry, struct ptlrpc_request *req,
932 struct mds_body *repbody, int req_off, int reply_off)
934 struct inode *inode = dentry->d_inode;
940 ea_name = lustre_msg_string(req->rq_reqmsg, req_off + 1, 0);
941 len = req->rq_repmsg->buflens[reply_off + 1];
943 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
946 if (inode->i_op && inode->i_op->getxattr)
947 rc = inode->i_op->getxattr(dentry, ea_name, value, len);
950 if (rc != -ENODATA && rc != -EOPNOTSUPP)
951 CERROR("getxattr failed: %d", rc);
953 repbody->valid |= OBD_MD_FLEA;
954 repbody->eadatasize = rc;
961 int mds_pack_ealist(struct dentry *dentry, struct ptlrpc_request *req,
962 struct mds_body *repbody, int reply_off)
964 struct inode *inode = dentry->d_inode;
969 len = req->rq_repmsg->buflens[reply_off + 1];
971 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
974 if (inode->i_op && inode->i_op->getxattr)
975 rc = inode->i_op->listxattr(dentry, value, len);
978 CERROR("listxattr failed: %d", rc);
980 repbody->valid |= OBD_MD_FLEALIST;
981 repbody->eadatasize = rc;
987 int mds_pack_acl(struct obd_device *obd, struct lustre_msg *repmsg, int offset,
988 struct mds_body *body, struct inode *inode)
990 struct dentry de = { .d_inode = inode };
991 __u32 buflen, *sizep;
996 if (!inode->i_op->getxattr)
999 buflen = repmsg->buflens[offset + 1];
1000 buf = lustre_msg_buf(repmsg, offset + 1, buflen);
1002 size = inode->i_op->getxattr(&de, XATTR_NAME_ACL_ACCESS, buf, buflen);
1003 if (size == -ENODATA || size == -EOPNOTSUPP)
1009 sizep = lustre_msg_buf(repmsg, offset, 4);
1011 CERROR("can't locate returned acl size buf\n");
1015 *sizep = cpu_to_le32(size);
1016 body->valid |= OBD_MD_FLACL_ACCESS;
1022 * here we take simple rule: once uid/fsuid is root, we also squash
1023 * the gid/fsgid, don't care setuid/setgid attributes.
1025 int mds_squash_root(struct mds_obd *mds, struct mds_req_sec_desc *rsd,
1028 if (!mds->mds_squash_uid || *peernid == mds->mds_nosquash_nid)
1031 if (rsd->rsd_uid && rsd->rsd_fsuid)
1034 CDEBUG(D_SEC, "squash req from "LPX64":"
1035 "(%u:%u-%u:%u/%x)=>(%u:%u-%u:%u/%x)\n", *peernid,
1036 rsd->rsd_uid, rsd->rsd_gid,
1037 rsd->rsd_fsuid, rsd->rsd_fsgid, rsd->rsd_cap,
1038 rsd->rsd_uid ? rsd->rsd_uid : mds->mds_squash_uid,
1039 rsd->rsd_uid ? rsd->rsd_gid : mds->mds_squash_gid,
1040 rsd->rsd_fsuid ? rsd->rsd_fsuid : mds->mds_squash_uid,
1041 rsd->rsd_fsuid ? rsd->rsd_fsgid : mds->mds_squash_gid,
1042 rsd->rsd_cap & ~CAP_FS_MASK);
1044 if (rsd->rsd_uid == 0) {
1045 rsd->rsd_uid = mds->mds_squash_uid;
1046 rsd->rsd_gid = mds->mds_squash_gid;
1048 if (rsd->rsd_fsuid == 0) {
1049 rsd->rsd_fsuid = mds->mds_squash_uid;
1050 rsd->rsd_fsgid = mds->mds_squash_gid;
1052 rsd->rsd_cap &= ~CAP_FS_MASK;
1057 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
1058 struct ptlrpc_request *req, int req_off,
1059 struct mds_body *reqbody, int reply_off)
1061 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
1062 struct inode *inode = dentry->d_inode;
1063 struct mds_body *body;
1067 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
1070 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
1071 LASSERT(body != NULL); /* caller prepped reply */
1073 if (dentry->d_flags & DCACHE_CROSS_REF) {
1074 mds_pack_dentry2body(obd, body, dentry,
1075 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1076 CDEBUG(D_OTHER, "cross reference: "DLID4"\n",
1081 mds_pack_inode2body(obd, body, inode,
1082 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1084 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
1085 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
1086 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1, body,
1087 inode, 1, (reqbody->valid & OBD_MD_MEA) ? 1 : 0);
1089 /* if we have LOV EA data, the OST holds size, atime, mtime. */
1090 if (!(body->valid & OBD_MD_FLEASIZE) &&
1091 !(body->valid & OBD_MD_FLDIREA))
1092 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
1093 OBD_MD_FLATIME | OBD_MD_FLMTIME);
1094 } else if (S_ISLNK(inode->i_mode) &&
1095 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
1096 rc = mds_pack_link(dentry, req, body, reply_off);
1097 } else if (reqbody->valid & OBD_MD_FLEA) {
1098 rc = mds_pack_ea(dentry, req, body, req_off, reply_off);
1099 } else if (reqbody->valid & OBD_MD_FLEALIST) {
1100 rc = mds_pack_ealist(dentry, req, body, reply_off);
1103 if (reqbody->valid & OBD_MD_FLACL_ACCESS) {
1104 int inc = (reqbody->valid & OBD_MD_FLEASIZE) ? 2 : 1;
1105 rc = mds_pack_acl(obd, req->rq_repmsg, reply_off + inc,
1110 mds_body_do_reverse_map(med, body);
1115 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
1116 struct dentry *dentry,
1119 int rc = 0, size[1] = {sizeof(struct mds_body)};
1122 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1123 CERROR("failed MDS_GETATTR_PACK test\n");
1124 req->rq_status = -ENOMEM;
1128 rc = lustre_pack_reply(req, 1, size, NULL);
1130 CERROR("lustre_pack_reply failed: rc %d\n", rc);
1131 GOTO(out, req->rq_status = rc);
1139 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct dentry *de,
1142 struct inode *inode = de->d_inode;
1143 struct mds_obd *mds = mds_req2mds(req);
1144 struct mds_body *body;
1145 int rc = 0, size[4] = {sizeof(*body)}, bufcount = 1;
1148 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
1149 LASSERT(body != NULL); /* checked by caller */
1150 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
1152 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
1153 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
1156 down(&inode->i_sem);
1157 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
1158 ((body->valid & OBD_MD_MEA) ? EA_MEA : EA_LOV));
1161 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1162 CERROR("error getting inode %lu MD: rc = %d\n",
1165 } else if (rc > mds->mds_max_mdsize) {
1167 CERROR("MD size %d larger than maximum possible %u\n",
1168 rc, mds->mds_max_mdsize);
1170 size[bufcount] = rc;
1173 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
1174 if (inode->i_size + 1 != body->eadatasize)
1175 CERROR("symlink size: %Lu, reply space: %d\n",
1176 inode->i_size + 1, body->eadatasize);
1177 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
1179 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
1180 inode->i_size + 1, body->eadatasize);
1181 } else if ((body->valid & OBD_MD_FLEA)) {
1182 char *ea_name = lustre_msg_string(req->rq_reqmsg,
1185 if (inode->i_op && inode->i_op->getxattr)
1186 rc = inode->i_op->getxattr(de, ea_name, NULL, 0);
1189 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1190 CERROR("error getting inode %lu EA: rc = %d\n",
1194 size[bufcount] = min_t(int, body->eadatasize, rc);
1197 } else if (body->valid & OBD_MD_FLEALIST) {
1199 if (inode->i_op && inode->i_op->getxattr)
1200 rc = inode->i_op->listxattr(de, NULL, 0);
1203 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1204 CERROR("error getting inode %lu EA: rc = %d\n",
1208 size[bufcount] = min_t(int, body->eadatasize, rc);
1213 /* may co-exist with OBD_MD_FLEASIZE */
1214 if (body->valid & OBD_MD_FLACL_ACCESS) {
1215 size[bufcount++] = 4;
1216 size[bufcount++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
1219 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1220 CERROR("failed MDS_GETATTR_PACK test\n");
1221 req->rq_status = -ENOMEM;
1222 GOTO(out, rc = -ENOMEM);
1225 rc = lustre_pack_reply(req, bufcount, size, NULL);
1227 CERROR("out of memory\n");
1228 GOTO(out, req->rq_status = rc);
1236 int mds_check_mds_num(struct obd_device *obd, struct inode *inode,
1237 char *name, int namelen)
1239 struct mea *mea = NULL;
1240 int mea_size, rc = 0;
1243 rc = mds_md_get_attr(obd, inode, &mea, &mea_size);
1248 * dir is already splitted, check if requested filename should
1249 * live at this MDS or at another one.
1251 int i = mea_name2idx(mea, name, namelen - 1);
1252 if (mea->mea_master != id_group(&mea->mea_ids[i])) {
1254 "inapropriate MDS(%d) for %s. should be "
1255 "%lu(%d)\n", mea->mea_master, name,
1256 (unsigned long)id_group(&mea->mea_ids[i]), i);
1262 OBD_FREE(mea, mea_size);
1266 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
1267 struct lustre_handle *child_lockh, int child_part)
1269 struct obd_device *obd = req->rq_export->exp_obd;
1270 struct mds_obd *mds = &obd->u.mds;
1271 struct ldlm_reply *rep = NULL;
1272 struct lvfs_run_ctxt saved;
1273 struct mds_req_sec_desc *rsd;
1274 struct mds_body *body;
1275 struct dentry *dparent = NULL, *dchild = NULL;
1276 struct lvfs_ucred uc = {NULL, NULL,};
1277 struct lustre_handle parent_lockh[2] = {{0}, {0}};
1278 unsigned int namesize;
1279 int rc = 0, cleanup_phase = 0, resent_req = 0, update_mode, reply_offset;
1283 LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME));
1284 MD_COUNTER_INCREMENT(obd, getattr_lock);
1286 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1288 CERROR("Can't unpack security desc\n");
1292 /* swab now, before anyone looks inside the request. */
1293 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1294 lustre_swab_mds_body);
1296 CERROR("Can't swab mds_body\n");
1297 GOTO(cleanup, rc = -EFAULT);
1300 LASSERT_REQSWAB(req, offset + 1);
1301 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
1303 CERROR("Can't unpack name\n");
1304 GOTO(cleanup, rc = -EFAULT);
1306 namesize = req->rq_reqmsg->buflens[offset + 1];
1308 /* namesize less than 2 means we have empty name, probably came from
1309 revalidate by cfid, so no point in having name to be set */
1313 LASSERT (offset == 1 || offset == 3);
1315 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
1321 rc = mds_init_ucred(&uc, req, rsd);
1326 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1327 cleanup_phase = 1; /* kernel context */
1328 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
1330 LASSERT(namesize > 0);
1331 if (child_lockh->cookie != 0) {
1332 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1337 if (body->valid == OBD_MD_FLID) {
1338 struct mds_body *mds_reply;
1339 int size = sizeof(*mds_reply);
1343 dparent = mds_id2dentry(obd, &body->id1, NULL);
1344 if (IS_ERR(dparent)) {
1345 rc = PTR_ERR(dparent);
1350 * the user requested ONLY the inode number, so do a raw lookup.
1352 rc = lustre_pack_reply(req, 1, &size, NULL);
1354 CERROR("out of memory\n");
1358 dir = dparent->d_inode;
1359 LASSERT(dir->i_op->lookup_raw != NULL);
1360 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
1362 mds_reply = lustre_msg_buf(req->rq_repmsg, 0,
1363 sizeof(*mds_reply));
1365 id_ino(&mds_reply->id1) = inum;
1366 mds_reply->valid = OBD_MD_FLID;
1371 if (resent_req == 0) {
1372 LASSERT(id_fid(&body->id1) != 0);
1374 rc = mds_get_parent_child_locked(obd, mds, &body->id1,
1375 parent_lockh, &dparent,
1377 MDS_INODELOCK_UPDATE,
1380 child_lockh, &dchild,
1381 LCK_PR, child_part);
1385 cleanup_phase = 2; /* dchild, dparent, locks */
1388 * let's make sure this name should leave on this mds
1391 rc = mds_check_mds_num(obd, dparent->d_inode, name, namesize);
1395 /* we have no dentry here, drop LOOKUP bit */
1396 /* FIXME: we need MDS_INODELOCK_LOOKUP or not. */
1397 child_part &= ~MDS_INODELOCK_LOOKUP;
1398 CDEBUG(D_OTHER, "%s: retrieve attrs for "DLID4"\n",
1399 obd->obd_name, OLID4(&body->id1));
1401 dchild = mds_id2locked_dentry(obd, &body->id1, NULL,
1402 LCK_PR, parent_lockh,
1405 MDS_INODELOCK_UPDATE);
1406 if (IS_ERR(dchild)) {
1407 CERROR("can't find inode with id "DLID4", err = %d\n",
1408 OLID4(&body->id1), (int)PTR_ERR(dchild));
1409 GOTO(cleanup, rc = PTR_ERR(dchild));
1411 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
1414 struct ldlm_lock *granted_lock;
1416 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
1417 granted_lock = ldlm_handle2lock(child_lockh);
1419 LASSERTF(granted_lock != NULL, LPU64"/%lu lockh "LPX64"\n",
1420 id_fid(&body->id1), (unsigned long)id_group(&body->id1),
1421 child_lockh->cookie);
1424 /* usual named request */
1425 dparent = mds_id2dentry(obd, &body->id1, NULL);
1426 LASSERT(!IS_ERR(dparent));
1427 dchild = ll_lookup_one_len(name, dparent, namesize - 1);
1428 if (IS_ERR(dchild)) {
1429 DEBUG_REQ(D_ERROR, req, "resent, not enqueuing new locks");
1430 CDEBUG(D_ERROR, "lock against [%lu:%lu]/%*s\n",
1431 (unsigned long) id_ino(&body->id1),
1432 (unsigned long) id_gen(&body->id1),
1433 namesize - 1, name);
1435 LASSERT(!IS_ERR(dchild));
1437 /* client wants to get attr. by id */
1438 dchild = mds_id2dentry(obd, &body->id1, NULL);
1439 if (IS_ERR(dchild)) {
1440 DEBUG_REQ(D_ERROR, req, "resent, not enqueuing new locks");
1441 CDEBUG(D_ERROR, "lock against [%lu:%lu]\n",
1442 (unsigned long) id_ino(&body->id1),
1443 (unsigned long) id_gen(&body->id1));
1445 LASSERT(!IS_ERR(dchild));
1447 LDLM_LOCK_PUT(granted_lock);
1450 cleanup_phase = 2; /* dchild, dparent, locks */
1452 if (!DENTRY_VALID(dchild)) {
1453 intent_set_disposition(rep, DISP_LOOKUP_NEG);
1455 * in the intent case, the policy clears this error: the
1456 * disposition is enough.
1461 intent_set_disposition(rep, DISP_LOOKUP_POS);
1464 if (req->rq_repmsg == NULL) {
1465 if (dchild->d_flags & DCACHE_CROSS_REF)
1466 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
1468 rc = mds_getattr_pack_msg(req, dchild, offset);
1470 CERROR ("mds_getattr_pack_msg: %d\n", rc);
1475 rc = mds_getattr_internal(obd, dchild, req, offset, body, reply_offset);
1476 GOTO(cleanup, rc); /* returns the lock to the client */
1479 switch (cleanup_phase) {
1481 if (resent_req == 0) {
1482 if (rc && DENTRY_VALID(dchild))
1483 ldlm_lock_decref(child_lockh, LCK_PR);
1485 ldlm_lock_decref(parent_lockh, LCK_PR);
1487 if (parent_lockh[1].cookie != 0)
1488 ldlm_lock_decref(parent_lockh + 1, update_mode);
1495 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1497 mds_exit_ucred(&uc);
1502 static int mds_getattr(struct ptlrpc_request *req, int offset)
1504 struct obd_device *obd = req->rq_export->exp_obd;
1505 struct lvfs_run_ctxt saved;
1507 struct mds_req_sec_desc *rsd;
1508 struct mds_body *body;
1509 struct lvfs_ucred uc = {NULL, NULL,};
1513 MD_COUNTER_INCREMENT(obd, getattr);
1515 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1517 CERROR("Can't unpack security desc\n");
1521 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1522 lustre_swab_mds_body);
1524 CERROR ("Can't unpack body\n");
1528 rc = mds_init_ucred(&uc, req, rsd);
1530 mds_exit_ucred(&uc);
1534 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1535 de = mds_id2dentry(obd, &body->id1, NULL);
1537 rc = req->rq_status = PTR_ERR(de);
1541 rc = mds_getattr_pack_msg(req, de, offset);
1543 CERROR("mds_getattr_pack_msg: %d\n", rc);
1547 req->rq_status = mds_getattr_internal(obd, de, req, offset, body, 0);
1552 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1553 mds_exit_ucred(&uc);
1557 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1558 unsigned long max_age)
1563 spin_lock(&obd->obd_osfs_lock);
1564 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
1566 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1567 spin_unlock(&obd->obd_osfs_lock);
1572 static int mds_statfs(struct ptlrpc_request *req)
1574 struct obd_device *obd = req->rq_export->exp_obd;
1575 int rc, size = sizeof(struct obd_statfs);
1578 /* This will trigger a watchdog timeout */
1579 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1580 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1582 rc = lustre_pack_reply(req, 1, &size, NULL);
1583 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1584 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1588 OBD_COUNTER_INCREMENT(obd, statfs);
1590 /* We call this so that we can cache a bit - 1 jiffie worth */
1591 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
1594 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1600 req->rq_status = rc;
1604 static int mds_sync(struct ptlrpc_request *req, int offset)
1606 struct obd_device *obd = req->rq_export->exp_obd;
1607 struct mds_obd *mds = &obd->u.mds;
1608 struct mds_body *body;
1609 int rc, size = sizeof(*body);
1612 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1613 lustre_swab_mds_body);
1615 GOTO(out, rc = -EPROTO);
1617 rc = lustre_pack_reply(req, 1, &size, NULL);
1618 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1619 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1623 if (id_ino(&body->id1) == 0) {
1624 /* an id of zero is taken to mean "sync whole filesystem" */
1625 rc = fsfilt_sync(obd, mds->mds_sb);
1629 /* just any file to grab fsync method - "file" arg unused */
1630 struct file *file = mds->mds_rcvd_filp;
1631 struct mds_body *rep_body;
1634 de = mds_id2dentry(obd, &body->id1, NULL);
1636 GOTO(out, rc = PTR_ERR(de));
1638 rc = file->f_op->fsync(NULL, de, 1);
1642 rep_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_body));
1643 mds_pack_inode2body(obd, rep_body, de->d_inode,
1644 (body->valid & OBD_MD_FID) ? 1 : 0);
1650 req->rq_status = rc;
1654 /* mds_readpage does not take a DLM lock on the inode, because the client must
1655 * already have a PR lock.
1657 * If we were to take another one here, a deadlock will result, if another
1658 * thread is already waiting for a PW lock. */
1659 static int mds_readpage(struct ptlrpc_request *req, int offset)
1661 struct obd_device *obd = req->rq_export->exp_obd;
1662 struct vfsmount *mnt;
1665 struct mds_req_sec_desc *rsd;
1666 struct mds_body *body, *repbody;
1667 struct lvfs_run_ctxt saved;
1668 int rc, size = sizeof(*repbody);
1669 struct lvfs_ucred uc = {NULL, NULL,};
1672 rc = lustre_pack_reply(req, 1, &size, NULL);
1673 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1674 CERROR("mds: out of memory\n");
1675 GOTO(out, rc = -ENOMEM);
1678 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1680 CERROR("Can't unpack security desc\n");
1681 GOTO (out, rc = -EFAULT);
1684 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1685 lustre_swab_mds_body);
1687 CERROR("Can't unpack body\n");
1688 GOTO (out, rc = -EFAULT);
1691 rc = mds_init_ucred(&uc, req, rsd);
1696 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1697 de = mds_id2dentry(obd, &body->id1, &mnt);
1699 GOTO(out_pop, rc = PTR_ERR(de));
1701 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1703 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1704 /* note: in case of an error, dentry_open puts dentry */
1706 GOTO(out_pop, rc = PTR_ERR(file));
1708 /* body->size is actually the offset -eeb */
1709 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1710 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1711 body->size, de->d_inode->i_blksize);
1712 GOTO(out_file, rc = -EFAULT);
1715 /* body->nlink is actually the #bytes to read -eeb */
1716 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1717 CERROR("size %u is not multiple of blocksize %lu\n",
1718 body->nlink, de->d_inode->i_blksize);
1719 GOTO(out_file, rc = -EFAULT);
1722 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
1723 repbody->size = file->f_dentry->d_inode->i_size;
1724 repbody->valid = OBD_MD_FLSIZE;
1726 /* to make this asynchronous make sure that the handling function
1727 doesn't send a reply when this function completes. Instead a
1728 callback function would send the reply */
1729 /* body->size is actually the offset -eeb */
1730 rc = mds_sendpage(req, file, body->size, body->nlink);
1734 filp_close(file, 0);
1736 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1738 mds_exit_ucred(&uc);
1739 req->rq_status = rc;
1743 /* update master MDS ID, which is stored in local inode EA. */
1744 int mds_update_mid(struct obd_device *obd, struct lustre_id *id,
1745 void *data, int data_len)
1747 struct mds_obd *mds = &obd->u.mds;
1748 struct dentry *dentry;
1756 dentry = mds_id2dentry(obd, id, NULL);
1758 GOTO(out, rc = PTR_ERR(dentry));
1760 if (!dentry->d_inode) {
1761 CERROR("Can't find object "DLID4".\n",
1763 GOTO(out_dentry, rc = -EINVAL);
1766 handle = fsfilt_start(obd, dentry->d_inode,
1767 FSFILT_OP_SETATTR, NULL);
1769 GOTO(out_dentry, rc = PTR_ERR(handle));
1771 rc = mds_update_inode_mid(obd, dentry->d_inode, handle,
1772 (struct lustre_id *)data);
1774 CERROR("Can't update inode "DLID4" master id, "
1775 "error = %d.\n", OLID4(id), rc);
1776 GOTO(out_commit, rc);
1781 fsfilt_commit(obd, mds->mds_sb, dentry->d_inode,
1788 EXPORT_SYMBOL(mds_update_mid);
1790 /* read master MDS ID, which is stored in local inode EA. */
1791 int mds_read_mid(struct obd_device *obd, struct lustre_id *id,
1792 void *data, int data_len)
1794 struct dentry *dentry;
1801 dentry = mds_id2dentry(obd, id, NULL);
1803 GOTO(out, rc = PTR_ERR(dentry));
1805 if (!dentry->d_inode) {
1806 CERROR("Can't find object "DLID4".\n",
1808 GOTO(out_dentry, rc = -EINVAL);
1811 down(&dentry->d_inode->i_sem);
1812 rc = mds_read_inode_mid(obd, dentry->d_inode,
1813 (struct lustre_id *)data);
1814 up(&dentry->d_inode->i_sem);
1816 CERROR("Can't read inode "DLID4" master id, "
1817 "error = %d.\n", OLID4(id), rc);
1818 GOTO(out_dentry, rc);
1827 EXPORT_SYMBOL(mds_read_mid);
1829 int mds_reint(struct ptlrpc_request *req, int offset,
1830 struct lustre_handle *lockh)
1832 struct mds_update_record *rec;
1833 struct mds_req_sec_desc *rsd;
1837 OBD_ALLOC(rec, sizeof(*rec));
1841 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1843 CERROR("Can't unpack security desc\n");
1844 GOTO(out, rc = -EFAULT);
1847 rc = mds_update_unpack(req, offset, rec);
1848 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1849 CERROR("invalid record\n");
1850 GOTO(out, req->rq_status = -EINVAL);
1853 rc = mds_init_ucred(&rec->ur_uc, req, rsd);
1858 /* rc will be used to interrupt a for loop over multiple records */
1859 rc = mds_reint_rec(rec, offset, req, lockh);
1862 mds_exit_ucred(&rec->ur_uc);
1863 OBD_FREE(rec, sizeof(*rec));
1867 static int mds_filter_recovery_request(struct ptlrpc_request *req,
1868 struct obd_device *obd, int *process)
1870 switch (req->rq_reqmsg->opc) {
1871 case MDS_CONNECT: /* This will never get here, but for completeness. */
1872 case OST_CONNECT: /* This will never get here, but for completeness. */
1873 case MDS_DISCONNECT:
1874 case OST_DISCONNECT:
1879 case MDS_SYNC: /* used in unmounting */
1884 *process = target_queue_recovery_request(req, obd);
1888 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1890 /* XXX what should we set rq_status to here? */
1891 req->rq_status = -EAGAIN;
1892 RETURN(ptlrpc_error(req));
1896 static char *reint_names[] = {
1897 [REINT_SETATTR] "setattr",
1898 [REINT_CREATE] "create",
1899 [REINT_LINK] "link",
1900 [REINT_UNLINK] "unlink",
1901 [REINT_RENAME] "rename",
1902 [REINT_OPEN] "open",
1905 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER | \
1906 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ| \
1907 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME| \
1910 static void reconstruct_create(struct ptlrpc_request *req)
1912 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1913 struct mds_client_data *mcd = med->med_mcd;
1914 struct dentry *dentry;
1915 struct ost_body *body;
1916 struct lustre_id id;
1920 /* copy rc, transno and disp; steal locks */
1921 mds_req_from_mcd(req, mcd);
1922 if (req->rq_status) {
1930 id_ino(&id) = mcd->mcd_last_data;
1931 LASSERT(id_ino(&id) != 0);
1933 dentry = mds_id2dentry(req2obd(req), &id, NULL);
1934 if (IS_ERR(dentry)) {
1935 CERROR("can't find inode "LPU64"\n", id_ino(&id));
1936 req->rq_status = PTR_ERR(dentry);
1941 CWARN("reconstruct reply for x"LPU64" (remote ino) "LPU64" -> %lu/%u\n",
1942 req->rq_xid, id_ino(&id), dentry->d_inode->i_ino,
1943 dentry->d_inode->i_generation);
1945 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
1946 obdo_from_inode(&body->oa, dentry->d_inode, FILTER_VALID_FLAGS);
1947 body->oa.o_id = dentry->d_inode->i_ino;
1948 body->oa.o_generation = dentry->d_inode->i_generation;
1949 body->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
1951 down(&dentry->d_inode->i_sem);
1952 rc = mds_read_inode_sid(req2obd(req), dentry->d_inode, &id);
1953 up(&dentry->d_inode->i_sem);
1955 CERROR("Can't read inode self id, inode %lu, "
1956 "rc %d\n", dentry->d_inode->i_ino, rc);
1960 body->oa.o_fid = id_fid(&id);
1961 body->oa.o_mds = id_group(&id);
1967 static int mdt_obj_create(struct ptlrpc_request *req)
1969 struct obd_device *obd = req->rq_export->exp_obd;
1970 struct mds_obd *mds = &obd->u.mds;
1971 struct ost_body *body, *repbody;
1972 char idname[LL_ID_NAMELEN];
1973 int size = sizeof(*repbody);
1974 struct inode *parent_inode;
1975 struct lvfs_run_ctxt saved;
1976 int rc, cleanup_phase = 0;
1977 struct dentry *new = NULL;
1978 struct dentry_params dp;
1979 int mealen, flags = 0;
1980 struct lvfs_ucred uc;
1981 struct lustre_id id;
1983 void *handle = NULL;
1984 unsigned long cr_inum = 0;
1987 DEBUG_REQ(D_HA, req, "create remote object");
1988 parent_inode = mds->mds_unnamed_dir->d_inode;
1990 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
1991 lustre_swab_ost_body);
1995 rc = lustre_pack_reply(req, 1, &size, NULL);
1999 MDS_CHECK_RESENT(req, reconstruct_create(req));
2002 uc.luc_ginfo = NULL;
2003 uc.luc_uid = body->oa.o_uid;
2004 uc.luc_gid = body->oa.o_gid;
2005 uc.luc_fsuid = body->oa.o_uid;
2006 uc.luc_fsgid = body->oa.o_gid;
2008 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2009 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
2011 /* in REPLAY case inum should be given (client or other MDS fills it) */
2012 if (body->oa.o_id && ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2013 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY))) {
2015 * this is re-create request from MDS holding directory name.
2016 * we have to lookup given ino/gen first. if it exists (good
2017 * case) then there is nothing to do. if it does not then we
2018 * have to recreate it.
2020 id_ino(&id) = body->oa.o_id;
2021 id_gen(&id) = body->oa.o_generation;
2023 new = mds_id2dentry(obd, &id, NULL);
2024 if (!IS_ERR(new) && new->d_inode) {
2025 struct lustre_id sid;
2027 CWARN("mkdir() repairing is on its way: %lu/%lu\n",
2028 (unsigned long)id_ino(&id), (unsigned long)id_gen(&id));
2030 obdo_from_inode(&repbody->oa, new->d_inode,
2031 FILTER_VALID_FLAGS);
2033 repbody->oa.o_id = new->d_inode->i_ino;
2034 repbody->oa.o_generation = new->d_inode->i_generation;
2035 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2038 down(&new->d_inode->i_sem);
2039 rc = mds_read_inode_sid(obd, new->d_inode, &sid);
2040 up(&new->d_inode->i_sem);
2042 CERROR("Can't read inode self id "
2043 "inode %lu, rc %d.\n",
2044 new->d_inode->i_ino, rc);
2048 repbody->oa.o_fid = id_fid(&sid);
2049 repbody->oa.o_mds = id_group(&sid);
2050 LASSERT(id_fid(&sid) != 0);
2053 * here we could use fid passed in body->oa.o_fid and
2054 * thus avoid mds_read_inode_sid().
2056 cr_inum = new->d_inode->i_ino;
2057 GOTO(cleanup, rc = 0);
2061 down(&parent_inode->i_sem);
2062 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
2063 if (IS_ERR(handle)) {
2064 up(&parent_inode->i_sem);
2065 CERROR("fsfilt_start() failed, rc = %d\n",
2066 (int)PTR_ERR(handle));
2067 GOTO(cleanup, rc = PTR_ERR(handle));
2069 cleanup_phase = 1; /* transaction */
2072 rc = sprintf(idname, "%u.%u", ll_insecure_random_int(), current->pid);
2073 new = lookup_one_len(idname, mds->mds_unnamed_dir, rc);
2075 CERROR("%s: can't lookup new inode (%s) for mkdir: %d\n",
2076 obd->obd_name, idname, (int) PTR_ERR(new));
2077 fsfilt_commit(obd, mds->mds_sb, new->d_inode, handle, 0);
2078 up(&parent_inode->i_sem);
2079 RETURN(PTR_ERR(new));
2080 } else if (new->d_inode) {
2081 CERROR("%s: name exists. repeat\n", obd->obd_name);
2085 new->d_fsdata = (void *)&dp;
2089 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) ||
2090 (body->oa.o_flags & OBD_FL_RECREATE_OBJS)) {
2091 LASSERT(body->oa.o_id != 0);
2092 dp.p_inum = body->oa.o_id;
2093 DEBUG_REQ(D_HA, req, "replay create obj %lu/%lu",
2094 (unsigned long)body->oa.o_id,
2095 (unsigned long)body->oa.o_generation);
2098 rc = vfs_mkdir(parent_inode, new, body->oa.o_mode);
2100 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2101 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2102 new->d_inode->i_generation = body->oa.o_generation;
2103 mark_inode_dirty(new->d_inode);
2106 * avoiding asserts in cache flush case, as
2107 * @body->oa.o_id should be zero.
2109 if (body->oa.o_id) {
2110 LASSERTF(body->oa.o_id == new->d_inode->i_ino,
2111 "BUG 3550: failed to recreate obj "
2112 LPU64" -> %lu\n", body->oa.o_id,
2113 new->d_inode->i_ino);
2115 LASSERTF(body->oa.o_generation ==
2116 new->d_inode->i_generation,
2117 "BUG 3550: failed to recreate obj/gen "
2118 LPU64"/%u -> %lu/%u\n", body->oa.o_id,
2119 body->oa.o_generation,
2120 new->d_inode->i_ino,
2121 new->d_inode->i_generation);
2125 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
2126 repbody->oa.o_id = new->d_inode->i_ino;
2127 repbody->oa.o_generation = new->d_inode->i_generation;
2128 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FID;
2130 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2131 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2132 id_group(&id) = mds->mds_num;
2134 LASSERT(body->oa.o_fid != 0);
2135 id_fid(&id) = body->oa.o_fid;
2137 LASSERT(body->oa.o_id != 0);
2138 id_ino(&id) = repbody->oa.o_id;
2139 id_gen(&id) = repbody->oa.o_generation;
2141 down(&new->d_inode->i_sem);
2142 rc = mds_update_inode_sid(obd, new->d_inode, handle, &id);
2143 up(&new->d_inode->i_sem);
2146 * make sure, that fid is up-to-date.
2148 mds_set_last_fid(obd, id_fid(&id));
2151 * allocate new sid, as object is created from scratch
2152 * and this is not replay.
2154 down(&new->d_inode->i_sem);
2155 rc = mds_alloc_inode_sid(obd, new->d_inode, handle, &id);
2156 up(&new->d_inode->i_sem);
2159 CERROR("Can't update lustre ID for inode %lu, "
2160 "error = %d\n", new->d_inode->i_ino, rc);
2164 /* initializing o_fid after it is allocated. */
2165 repbody->oa.o_fid = id_fid(&id);
2166 repbody->oa.o_mds = id_group(&id);
2168 rc = fsfilt_del_dir_entry(obd, new);
2169 up(&parent_inode->i_sem);
2171 CERROR("can't remove name for object: %d\n", rc);
2175 cleanup_phase = 2; /* created directory object */
2177 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
2178 (unsigned long)new->d_inode->i_ino,
2179 (unsigned long)new->d_inode->i_generation,
2180 (unsigned)new->d_inode->i_mode);
2181 cr_inum = new->d_inode->i_ino;
2183 up(&parent_inode->i_sem);
2184 CERROR("%s: can't create dirobj: %d\n", obd->obd_name, rc);
2188 if (body->oa.o_valid & OBD_MD_FLID) {
2189 /* this is new object for splitted dir. We have to prevent
2190 * recursive splitting on it -bzzz */
2191 mealen = obd_size_diskmd(mds->mds_md_exp, NULL);
2193 OBD_ALLOC(mea, mealen);
2195 GOTO(cleanup, rc = -ENOMEM);
2197 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2198 mea->mea_master = 0;
2201 down(&new->d_inode->i_sem);
2202 rc = fsfilt_set_md(obd, new->d_inode, handle,
2203 mea, mealen, EA_MEA);
2204 up(&new->d_inode->i_sem);
2206 CERROR("fsfilt_set_md() failed, "
2209 OBD_FREE(mea, mealen);
2211 CDEBUG(D_OTHER, "%s: mark non-splittable %lu/%u - %d\n",
2212 obd->obd_name, new->d_inode->i_ino,
2213 new->d_inode->i_generation, flags);
2214 } else if (body->oa.o_easize) {
2215 /* we pass LCK_EX to split routine to signal that we have
2216 * exclusive access to the directory. simple because nobody
2217 * knows it already exists -bzzz */
2218 rc = mds_try_to_split_dir(obd, new, NULL,
2219 body->oa.o_easize, LCK_EX);
2221 CERROR("Can't split directory %lu, error = %d.\n",
2222 new->d_inode->i_ino, rc);
2230 switch (cleanup_phase) {
2231 case 2: /* object has been created, but we'll may want to replay it later */
2233 ptlrpc_require_repack(req);
2234 case 1: /* transaction */
2235 rc = mds_finish_transno(mds, parent_inode, handle,
2240 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2244 static int mdt_get_info(struct ptlrpc_request *req)
2246 struct obd_export *exp = req->rq_export;
2251 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2253 DEBUG_REQ(D_HA, req, "no get_info key");
2256 keylen = req->rq_reqmsg->buflens[0];
2258 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
2259 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
2260 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0))
2263 if (keylen >= strlen("rootid") && !strcmp(key, "rootid")) {
2264 struct lustre_id *reply;
2265 int size = sizeof(*reply);
2267 rc = lustre_pack_reply(req, 1, &size, NULL);
2271 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2272 rc = obd_get_info(exp, keylen, key, &size, reply);
2275 int size = sizeof(*reply);
2277 rc = lustre_pack_reply(req, 1, &size, NULL);
2281 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2282 rc = obd_get_info(exp, keylen, key, &size, reply);
2285 req->rq_repmsg->status = 0;
2289 static int mds_set_info(struct obd_export *exp, __u32 keylen,
2290 void *key, __u32 vallen, void *val)
2292 struct obd_device *obd;
2293 struct mds_obd *mds;
2297 obd = class_exp2obd(exp);
2299 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2300 exp->exp_handle.h_cookie);
2305 if (keylen >= strlen("mds_type") &&
2306 memcmp(key, "mds_type", keylen) == 0) {
2310 CDEBUG(D_IOCTL, "set mds type to %x\n", *(int*)val);
2312 mds->mds_obd_type = *(int*)val;
2313 group = FILTER_GROUP_FIRST_MDS + mds->mds_obd_type;
2314 valsize = sizeof(group);
2316 /* mds number has been changed, so the corresponding obdfilter
2317 * exp need to be changed too. */
2318 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
2319 "mds_conn", valsize, &group);
2322 CDEBUG(D_IOCTL, "invalid key\n");
2326 static int mdt_set_info(struct ptlrpc_request *req)
2329 struct obd_export *exp = req->rq_export;
2330 int keylen, rc = 0, vallen;
2333 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2335 DEBUG_REQ(D_HA, req, "no set_info key");
2338 keylen = req->rq_reqmsg->buflens[0];
2340 if (keylen == strlen("mds_type") &&
2341 memcmp(key, "mds_type", keylen) == 0) {
2342 rc = lustre_pack_reply(req, 0, NULL, NULL);
2346 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2347 vallen = req->rq_reqmsg->buflens[1];
2349 rc = obd_set_info(exp, keylen, key, vallen, val);
2350 req->rq_repmsg->status = 0;
2353 CDEBUG(D_IOCTL, "invalid key\n");
2357 static void mds_revoke_export_locks(struct obd_export *exp)
2359 struct ldlm_namespace *ns = exp->exp_obd->obd_namespace;
2360 struct list_head *locklist = &exp->exp_ldlm_data.led_held_locks;
2361 struct ldlm_lock *lock, *next;
2362 struct ldlm_lock_desc desc;
2364 if (!exp->u.eu_mds_data.med_remote)
2368 l_lock(&ns->ns_lock);
2369 list_for_each_entry_safe(lock, next, locklist, l_export_chain) {
2370 if (lock->l_req_mode != lock->l_granted_mode)
2373 LASSERT(lock->l_resource);
2374 if (lock->l_resource->lr_type != LDLM_IBITS &&
2375 lock->l_resource->lr_type != LDLM_PLAIN)
2378 if (lock->l_flags & LDLM_FL_AST_SENT)
2381 lock->l_flags |= LDLM_FL_AST_SENT;
2383 /* the desc just pretend to exclusive */
2384 ldlm_lock2desc(lock, &desc);
2385 desc.l_req_mode = LCK_EX;
2386 desc.l_granted_mode = 0;
2388 lock->l_blocking_ast(lock, &desc, NULL, LDLM_CB_BLOCKING);
2390 l_unlock(&ns->ns_lock);
2394 static int mds_msg_check_version(struct lustre_msg *msg)
2400 case MDS_DISCONNECT:
2402 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2404 CERROR("bad opc %u version %08x, expecting %08x\n",
2405 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2410 case MDS_GETATTR_LOCK:
2414 case MDS_DONE_WRITING:
2417 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2419 CERROR("bad opc %u version %08x, expecting %08x\n",
2420 msg->opc, msg->version, LUSTRE_MDS_VERSION);
2424 case LDLM_BL_CALLBACK:
2425 case LDLM_CP_CALLBACK:
2426 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2428 CERROR("bad opc %u version %08x, expecting %08x\n",
2429 msg->opc, msg->version, LUSTRE_DLM_VERSION);
2431 case OBD_LOG_CANCEL:
2432 case LLOG_ORIGIN_HANDLE_OPEN:
2433 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2434 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2435 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2436 case LLOG_ORIGIN_HANDLE_CLOSE:
2438 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2440 CERROR("bad opc %u version %08x, expecting %08x\n",
2441 msg->opc, msg->version, LUSTRE_LOG_VERSION);
2447 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2449 CERROR("bad opc %u version %08x, expecting %08x\n",
2450 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2453 case SEC_INIT_CONTINUE:
2458 CERROR("MDS unknown opcode %d\n", msg->opc);
2466 int mds_handle(struct ptlrpc_request *req)
2468 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
2469 struct obd_device *obd = NULL;
2470 struct mds_obd *mds = NULL; /* quell gcc overwarning */
2474 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2476 rc = mds_msg_check_version(req->rq_reqmsg);
2478 CERROR("MDS drop mal-formed request\n");
2482 /* Security opc should NOT trigger any recovery events */
2483 if (req->rq_reqmsg->opc == SEC_INIT ||
2484 req->rq_reqmsg->opc == SEC_INIT_CONTINUE) {
2485 if (!req->rq_export)
2488 mds_req_add_idmapping(req, &req->rq_export->exp_mds_data);
2489 mds_revoke_export_locks(req->rq_export);
2491 } else if (req->rq_reqmsg->opc == SEC_FINI) {
2492 if (!req->rq_export)
2495 mds_req_del_idmapping(req, &req->rq_export->exp_mds_data);
2496 mds_revoke_export_locks(req->rq_export);
2500 LASSERT(current->journal_info == NULL);
2501 /* XXX identical to OST */
2502 if (req->rq_reqmsg->opc != MDS_CONNECT) {
2503 struct mds_export_data *med;
2506 if (req->rq_export == NULL) {
2507 CERROR("operation %d on unconnected MDS from %s\n",
2508 req->rq_reqmsg->opc,
2510 req->rq_status = -ENOTCONN;
2511 GOTO(out, rc = -ENOTCONN);
2514 med = &req->rq_export->exp_mds_data;
2515 obd = req->rq_export->exp_obd;
2518 /* sanity check: if the xid matches, the request must
2519 * be marked as a resent or replayed */
2520 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
2521 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid)) {
2522 LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
2523 (MSG_RESENT | MSG_REPLAY),
2524 "rq_xid "LPU64" matches last_xid, "
2525 "expected RESENT flag\n",
2528 /* else: note the opposite is not always true; a
2529 * RESENT req after a failover will usually not match
2530 * the last_xid, since it was likely never
2531 * committed. A REPLAYed request will almost never
2532 * match the last xid, however it could for a
2533 * committed, but still retained, open. */
2535 spin_lock_bh(&obd->obd_processing_task_lock);
2536 recovering = obd->obd_recovering;
2537 spin_unlock_bh(&obd->obd_processing_task_lock);
2539 rc = mds_filter_recovery_request(req, obd,
2541 if (rc || should_process == 0) {
2543 } else if (should_process < 0) {
2544 req->rq_status = should_process;
2545 rc = ptlrpc_error(req);
2551 switch (req->rq_reqmsg->opc) {
2553 DEBUG_REQ(D_INODE, req, "connect");
2554 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
2555 rc = target_handle_connect(req);
2557 struct mds_export_data *med;
2559 LASSERT(req->rq_export);
2560 med = &req->rq_export->u.eu_mds_data;
2561 mds_init_export_data(req, med);
2562 mds_req_add_idmapping(req, med);
2564 /* Now that we have an export, set mds. */
2565 obd = req->rq_export->exp_obd;
2566 mds = mds_req2mds(req);
2570 case MDS_DISCONNECT:
2571 DEBUG_REQ(D_INODE, req, "disconnect");
2572 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
2573 rc = target_handle_disconnect(req);
2574 req->rq_status = rc; /* superfluous? */
2578 DEBUG_REQ(D_INODE, req, "getstatus");
2579 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
2580 rc = mds_getstatus(req);
2584 DEBUG_REQ(D_INODE, req, "getattr");
2585 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
2586 rc = mds_getattr(req, MDS_REQ_REC_OFF);
2589 case MDS_GETATTR_LOCK: {
2590 struct lustre_handle lockh;
2591 DEBUG_REQ(D_INODE, req, "getattr_lock");
2592 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_LOCK_NET, 0);
2594 /* If this request gets a reconstructed reply, we won't be
2595 * acquiring any new locks in mds_getattr_lock, so we don't
2599 rc = mds_getattr_lock(req, MDS_REQ_REC_OFF, &lockh,
2600 MDS_INODELOCK_UPDATE);
2601 /* this non-intent call (from an ioctl) is special */
2602 req->rq_status = rc;
2603 if (rc == 0 && lockh.cookie)
2604 ldlm_lock_decref(&lockh, LCK_PR);
2608 DEBUG_REQ(D_INODE, req, "statfs");
2609 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
2610 rc = mds_statfs(req);
2614 DEBUG_REQ(D_INODE, req, "readpage");
2615 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
2616 rc = mds_readpage(req, MDS_REQ_REC_OFF);
2618 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
2619 if (req->rq_reply_state) {
2620 lustre_free_reply_state (req->rq_reply_state);
2621 req->rq_reply_state = NULL;
2628 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
2631 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
2632 mds->mds_max_cookiesize};
2635 /* NB only peek inside req now; mds_reint() will swab it */
2637 CERROR ("Can't inspect opcode\n");
2642 if (lustre_msg_swabbed (req->rq_reqmsg))
2645 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
2646 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
2647 reint_names[opc] == NULL) ? reint_names[opc] :
2650 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
2652 if (opc == REINT_UNLINK || opc == REINT_RENAME)
2654 else if (opc == REINT_OPEN)
2659 rc = lustre_pack_reply(req, bufcount, size, NULL);
2663 rc = mds_reint(req, MDS_REQ_REC_OFF, NULL);
2664 fail = OBD_FAIL_MDS_REINT_NET_REP;
2669 DEBUG_REQ(D_INODE, req, "close");
2670 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
2671 rc = mds_close(req, MDS_REQ_REC_OFF);
2674 case MDS_DONE_WRITING:
2675 DEBUG_REQ(D_INODE, req, "done_writing");
2676 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
2677 rc = mds_done_writing(req, MDS_REQ_REC_OFF);
2681 DEBUG_REQ(D_INODE, req, "pin");
2682 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
2683 rc = mds_pin(req, MDS_REQ_REC_OFF);
2687 DEBUG_REQ(D_INODE, req, "sync");
2688 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
2689 rc = mds_sync(req, MDS_REQ_REC_OFF);
2693 DEBUG_REQ(D_INODE, req, "ping");
2694 rc = target_handle_ping(req);
2697 case OBD_LOG_CANCEL:
2698 CDEBUG(D_INODE, "log cancel\n");
2699 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
2700 rc = -ENOTSUPP; /* la la la */
2704 DEBUG_REQ(D_INODE, req, "enqueue");
2705 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
2706 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2707 ldlm_server_blocking_ast, NULL);
2708 fail = OBD_FAIL_LDLM_REPLY;
2711 DEBUG_REQ(D_INODE, req, "convert");
2712 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
2713 rc = ldlm_handle_convert(req);
2715 case LDLM_BL_CALLBACK:
2716 case LDLM_CP_CALLBACK:
2717 DEBUG_REQ(D_INODE, req, "callback");
2718 CERROR("callbacks should not happen on MDS\n");
2720 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
2722 case LLOG_ORIGIN_HANDLE_OPEN:
2723 DEBUG_REQ(D_INODE, req, "llog_init");
2724 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2725 rc = llog_origin_handle_open(req);
2727 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2728 DEBUG_REQ(D_INODE, req, "llog next block");
2729 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2730 rc = llog_origin_handle_next_block(req);
2732 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2733 DEBUG_REQ(D_INODE, req, "llog prev block");
2734 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2735 rc = llog_origin_handle_prev_block(req);
2737 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2738 DEBUG_REQ(D_INODE, req, "llog read header");
2739 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2740 rc = llog_origin_handle_read_header(req);
2742 case LLOG_ORIGIN_HANDLE_CLOSE:
2743 DEBUG_REQ(D_INODE, req, "llog close");
2744 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2745 rc = llog_origin_handle_close(req);
2748 DEBUG_REQ(D_INODE, req, "ost_create");
2749 rc = mdt_obj_create(req);
2752 DEBUG_REQ(D_INODE, req, "get_info");
2753 rc = mdt_get_info(req);
2756 DEBUG_REQ(D_INODE, req, "set_info");
2757 rc = mdt_set_info(req);
2760 CDEBUG(D_INODE, "write\n");
2761 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
2762 rc = ost_brw_write(req, NULL);
2763 LASSERT(current->journal_info == NULL);
2764 /* mdt_brw sends its own replies */
2768 DEBUG_REQ(D_INODE, req, "llog catinfo");
2769 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2770 rc = llog_catinfo(req);
2773 req->rq_status = -ENOTSUPP;
2774 rc = ptlrpc_error(req);
2778 LASSERT(current->journal_info == NULL);
2782 /* If we're DISCONNECTing, the mds_export_data is already freed */
2783 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
2784 struct mds_export_data *med = &req->rq_export->exp_mds_data;
2785 struct obd_device *obd = list_entry(mds, struct obd_device,
2787 req->rq_repmsg->last_xid =
2788 le64_to_cpu(med->med_mcd->mcd_last_xid);
2790 if (!obd->obd_no_transno) {
2791 req->rq_repmsg->last_committed =
2792 obd->obd_last_committed;
2794 DEBUG_REQ(D_IOCTL, req,
2795 "not sending last_committed update");
2797 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
2799 mds->mds_last_transno, obd->obd_last_committed,
2804 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
2805 if (obd && obd->obd_recovering) {
2806 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
2807 return target_queue_final_reply(req, rc);
2809 /* Lost a race with recovery; let the error path DTRT. */
2810 rc = req->rq_status = -ENOTCONN;
2813 target_send_reply(req, rc, fail);
2817 /* Update the server data on disk. This stores the new mount_count and also the
2818 * last_rcvd value to disk. If we don't have a clean shutdown, then the server
2819 * last_rcvd value may be less than that of the clients. This will alert us
2820 * that we may need to do client recovery.
2822 * Also assumes for mds_last_transno that we are not modifying it (no locking).
2824 int mds_update_server_data(struct obd_device *obd, int force_sync)
2826 struct mds_obd *mds = &obd->u.mds;
2827 struct mds_server_data *msd = mds->mds_server_data;
2828 struct file *filp = mds->mds_rcvd_filp;
2829 struct lvfs_run_ctxt saved;
2834 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2835 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
2837 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
2838 mds->mds_mount_count, mds->mds_last_transno);
2839 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off, force_sync);
2841 CERROR("error writing MDS server data: rc = %d\n", rc);
2842 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2847 /* saves last allocated fid counter to file. */
2848 int mds_update_last_fid(struct obd_device *obd, void *handle,
2851 struct mds_obd *mds = &obd->u.mds;
2852 struct file *filp = mds->mds_fid_filp;
2853 struct lvfs_run_ctxt saved;
2859 spin_lock(&mds->mds_last_fid_lock);
2860 last_fid = mds->mds_last_fid;
2861 spin_unlock(&mds->mds_last_fid_lock);
2863 CDEBUG(D_SUPER, "MDS last_fid is #"LPU64"\n",
2867 fsfilt_add_journal_cb(obd, mds->mds_sb, last_fid,
2868 handle, mds_commit_last_fid_cb,
2872 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2873 rc = fsfilt_write_record(obd, filp, &last_fid, sizeof(last_fid),
2875 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2878 CERROR("error writing MDS last_fid #"LPU64
2879 ", err = %d\n", last_fid, rc);
2883 CDEBUG(D_SUPER, "wrote fid #"LPU64" at idx "
2884 "%llu: err = %d\n", last_fid, off, rc);
2889 void mds_set_last_fid(struct obd_device *obd, __u64 fid)
2891 struct mds_obd *mds = &obd->u.mds;
2893 spin_lock(&mds->mds_last_fid_lock);
2894 if (fid > mds->mds_last_fid)
2895 mds->mds_last_fid = fid;
2896 spin_unlock(&mds->mds_last_fid_lock);
2899 void mds_commit_last_transno_cb(struct obd_device *obd,
2900 __u64 transno, void *data,
2903 obd_transno_commit_cb(obd, transno, error);
2906 void mds_commit_last_fid_cb(struct obd_device *obd,
2907 __u64 fid, void *data,
2911 CERROR("%s: fid "LPD64" commit error: %d\n",
2912 obd->obd_name, fid, error);
2916 CDEBUG(D_HA, "%s: fid "LPD64" committed\n",
2917 obd->obd_name, fid);
2920 __u64 mds_alloc_fid(struct obd_device *obd)
2922 struct mds_obd *mds = &obd->u.mds;
2925 spin_lock(&mds->mds_last_fid_lock);
2926 fid = ++mds->mds_last_fid;
2927 spin_unlock(&mds->mds_last_fid_lock);
2933 * allocates new lustre_id on passed @inode and saves it to inode EA.
2935 int mds_alloc_inode_sid(struct obd_device *obd, struct inode *inode,
2936 void *handle, struct lustre_id *id)
2938 struct mds_obd *mds = &obd->u.mds;
2939 int alloc = 0, rc = 0;
2942 LASSERT(obd != NULL);
2943 LASSERT(inode != NULL);
2946 OBD_ALLOC(id, sizeof(*id));
2952 id_group(id) = mds->mds_num;
2953 id_fid(id) = mds_alloc_fid(obd);
2954 id_ino(id) = inode->i_ino;
2955 id_gen(id) = inode->i_generation;
2956 id_type(id) = (S_IFMT & inode->i_mode);
2958 rc = mds_update_inode_sid(obd, inode, handle, id);
2960 CERROR("Can't update inode FID EA, "
2965 OBD_FREE(id, sizeof(*id));
2970 * reads inode self id from inode EA. Probably later this should be replaced by
2971 * caching inode self id to avoid raeding it every time it is needed.
2973 int mds_read_inode_sid(struct obd_device *obd, struct inode *inode,
2974 struct lustre_id *id)
2979 LASSERT(id != NULL);
2980 LASSERT(obd != NULL);
2981 LASSERT(inode != NULL);
2983 rc = fsfilt_get_md(obd, inode, &id->li_fid,
2984 sizeof(id->li_fid), EA_SID);
2986 CERROR("fsfilt_get_md() failed, "
2999 /* updates inode self id in EA. */
3000 int mds_update_inode_sid(struct obd_device *obd, struct inode *inode,
3001 void *handle, struct lustre_id *id)
3006 LASSERT(id != NULL);
3007 LASSERT(obd != NULL);
3008 LASSERT(inode != NULL);
3010 rc = fsfilt_set_md(obd, inode, handle, &id->li_fid,
3011 sizeof(id->li_fid), EA_SID);
3013 CERROR("fsfilt_set_md() failed, rc = %d\n", rc);
3021 * reads inode id on master MDS. This is usualy done by CMOBD to update requests
3022 * to master MDS by correct store cookie, needed to find inode on master MDS
3025 int mds_read_inode_mid(struct obd_device *obd, struct inode *inode,
3026 struct lustre_id *id)
3031 LASSERT(id != NULL);
3032 LASSERT(obd != NULL);
3033 LASSERT(inode != NULL);
3035 rc = fsfilt_get_md(obd, inode, id, sizeof(*id), EA_MID);
3037 CERROR("fsfilt_get_md() failed, rc = %d\n", rc);
3050 * updates master inode id. Usualy this is done by CMOBD after an inode is
3051 * created and relationship between cache MDS and master one should be
3054 int mds_update_inode_mid(struct obd_device *obd, struct inode *inode,
3055 void *handle, struct lustre_id *id)
3060 LASSERT(id != NULL);
3061 LASSERT(obd != NULL);
3062 LASSERT(inode != NULL);
3064 rc = fsfilt_set_md(obd, inode, handle, id,
3065 sizeof(*id), EA_MID);
3067 CERROR("fsfilt_set_md() failed, "
3075 /* mount the file system (secretly) */
3076 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
3078 struct lustre_cfg* lcfg = buf;
3079 struct mds_obd *mds = &obd->u.mds;
3080 struct lvfs_obd_ctxt *lvfs_ctxt = NULL;
3081 char *options = NULL;
3082 struct vfsmount *mnt;
3089 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
3090 RETURN(rc = -EINVAL);
3092 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
3093 if (IS_ERR(obd->obd_fsops))
3094 RETURN(rc = PTR_ERR(obd->obd_fsops));
3096 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
3098 page = __get_free_page(GFP_KERNEL);
3102 options = (char *)page;
3103 memset(options, 0, PAGE_SIZE);
3106 * here we use "iopen_nopriv" hardcoded, because it affects MDS utility
3107 * and the rest of options are passed by mount options. Probably this
3108 * should be moved to somewhere else like startup scripts or lconf. */
3109 sprintf(options, "iopen_nopriv");
3110 if (lcfg->lcfg_inllen4 > 0 && lcfg->lcfg_inlbuf4)
3111 sprintf(options + strlen(options), ",%s",
3112 lcfg->lcfg_inlbuf4);
3114 /* we have to know mdsnum before touching underlying fs -bzzz */
3115 atomic_set(&mds->mds_open_count, 0);
3116 sema_init(&mds->mds_md_sem, 1);
3117 mds->mds_md_connected = 0;
3118 mds->mds_md_name = NULL;
3120 if (lcfg->lcfg_inllen5 > 0 && lcfg->lcfg_inlbuf5 &&
3121 strncmp(lcfg->lcfg_inlbuf5, "dumb", lcfg->lcfg_inllen5)) {
3124 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
3125 obd->obd_name, lcfg->lcfg_inlbuf5);
3127 generate_random_uuid(uuid);
3128 class_uuid_unparse(uuid, &mds->mds_md_uuid);
3130 OBD_ALLOC(mds->mds_md_name, lcfg->lcfg_inllen5);
3131 if (mds->mds_md_name == NULL)
3132 RETURN(rc = -ENOMEM);
3134 memcpy(mds->mds_md_name, lcfg->lcfg_inlbuf5,
3135 lcfg->lcfg_inllen5);
3137 rc = mds_md_connect(obd, mds->mds_md_name);
3139 OBD_FREE(mds->mds_md_name, lcfg->lcfg_inllen5);
3144 mds->mds_obd_type = MDS_MASTER_OBD;
3146 if (lcfg->lcfg_inllen6 > 0 && lcfg->lcfg_inlbuf6 &&
3147 strncmp(lcfg->lcfg_inlbuf6, "dumb", lcfg->lcfg_inllen6)) {
3148 if (!memcmp(lcfg->lcfg_inlbuf6, "master", strlen("master"))) {
3149 mds->mds_obd_type = MDS_MASTER_OBD;
3150 } else if (!memcmp(lcfg->lcfg_inlbuf6, "cache", strlen("cache"))) {
3151 mds->mds_obd_type = MDS_CACHE_OBD;
3155 rc = lvfs_mount_fs(lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2,
3156 options, 0, &lvfs_ctxt);
3160 if (rc || !lvfs_ctxt) {
3161 CERROR("lvfs_mount_fs failed: rc = %d\n", rc);
3165 mnt = lvfs_ctxt->loc_mnt;
3166 mds->mds_lvfs_ctxt = lvfs_ctxt;
3167 ll_clear_rdonly(ll_sbdev(mnt->mnt_sb));
3169 CDEBUG(D_SUPER, "%s: mnt = %p\n", lcfg->lcfg_inlbuf1, mnt);
3171 sema_init(&mds->mds_epoch_sem, 1);
3172 atomic_set(&mds->mds_real_clients, 0);
3173 spin_lock_init(&mds->mds_transno_lock);
3174 spin_lock_init(&mds->mds_last_fid_lock);
3175 sema_init(&mds->mds_orphan_recovery_sem, 1);
3176 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
3178 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
3179 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
3181 if (obd->obd_namespace == NULL) {
3182 mds_cleanup(obd, 0);
3183 GOTO(err_put, rc = -ENOMEM);
3185 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
3187 rc = mds_fs_setup(obd, mnt);
3189 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
3194 rc = llog_start_commit_thread();
3198 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3199 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)) {
3202 generate_random_uuid(uuid);
3203 class_uuid_unparse(uuid, &mds->mds_dt_uuid);
3205 OBD_ALLOC(mds->mds_profile, lcfg->lcfg_inllen3);
3206 if (mds->mds_profile == NULL)
3207 GOTO(err_fs, rc = -ENOMEM);
3209 memcpy(mds->mds_profile, lcfg->lcfg_inlbuf3,
3210 lcfg->lcfg_inllen3);
3214 * setup root dir and files ID dir if lmv already connected, or there is
3217 if (mds->mds_md_exp || (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3218 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)))
3220 rc = mds_fs_setup_rootid(obd);
3224 rc = mds_fs_setup_virtid(obd);
3229 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3230 "mds_ldlm_client", &obd->obd_ldlm_client);
3231 obd->obd_replayable = 1;
3233 rc = mds_postsetup(obd);
3240 /* No extra cleanup needed for llog_init_commit_thread() */
3241 mds_fs_cleanup(obd, 0);
3243 ldlm_namespace_free(obd->obd_namespace, 0);
3244 obd->obd_namespace = NULL;
3247 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3251 fsfilt_put_ops(obd->obd_fsops);
3255 static int mds_postsetup(struct obd_device *obd)
3257 struct mds_obd *mds = &obd->u.mds;
3261 rc = obd_llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
3262 obd, 0, NULL, &llog_lvfs_ops);
3266 if (mds->mds_profile) {
3267 struct llog_ctxt *lgctxt;
3268 struct lvfs_run_ctxt saved;
3269 struct lustre_profile *lprof;
3270 struct config_llog_instance cfg;
3272 cfg.cfg_instance = NULL;
3273 cfg.cfg_uuid = mds->mds_dt_uuid;
3274 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3276 lgctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
3278 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3279 GOTO(err_llog, rc = -EINVAL);
3282 rc = class_config_process_llog(lgctxt, mds->mds_profile, &cfg);
3283 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3288 lprof = class_get_profile(mds->mds_profile);
3289 if (lprof == NULL) {
3290 CERROR("No profile found: %s\n", mds->mds_profile);
3291 GOTO(err_cleanup, rc = -ENOENT);
3293 rc = mds_dt_connect(obd, lprof->lp_lov);
3295 GOTO(err_cleanup, rc);
3297 rc = mds_md_postsetup(obd);
3299 GOTO(err_cleanup, rc);
3306 obd_llog_cleanup(llog_get_context(&obd->obd_llogs,
3307 LLOG_CONFIG_ORIG_CTXT));
3311 int mds_postrecov(struct obd_device *obd)
3313 struct mds_obd *mds = &obd->u.mds;
3314 struct llog_ctxt *ctxt;
3315 int rc, item = 0, valsize;
3319 LASSERT(!obd->obd_recovering);
3320 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
3321 LASSERT(ctxt != NULL);
3323 /* set nextid first, so we are sure it happens */
3324 rc = mds_dt_set_nextid(obd);
3326 CERROR("%s: mds_dt_set_nextid() failed\n", obd->obd_name);
3330 /* clean PENDING dir */
3331 rc = mds_cleanup_orphans(obd);
3336 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
3337 valsize = sizeof(group);
3338 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"), "mds_conn",
3343 rc = llog_connect(ctxt, obd->u.mds.mds_dt_desc.ld_tgt_count,
3346 CERROR("%s: failed at llog_origin_connect: %d\n",
3351 /* remove the orphaned precreated objects */
3352 rc = mds_dt_clearorphans(mds, NULL /* all OSTs */);
3357 RETURN(rc < 0 ? rc : item);
3360 /* cleanup all llogging subsystems */
3361 rc = obd_llog_finish(obd, &obd->obd_llogs,
3362 mds->mds_dt_desc.ld_tgt_count);
3364 CERROR("%s: failed to cleanup llogging subsystems\n",
3369 int mds_dt_clean(struct obd_device *obd)
3371 struct mds_obd *mds = &obd->u.mds;
3374 if (mds->mds_profile) {
3376 struct llog_ctxt *llctx;
3377 struct lvfs_run_ctxt saved;
3378 struct config_llog_instance cfg;
3379 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
3381 OBD_ALLOC(cln_prof, len);
3382 sprintf(cln_prof, "%s-clean", mds->mds_profile);
3384 cfg.cfg_instance = NULL;
3385 cfg.cfg_uuid = mds->mds_dt_uuid;
3387 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3388 llctx = llog_get_context(&obd->obd_llogs,
3389 LLOG_CONFIG_ORIG_CTXT);
3390 class_config_process_llog(llctx, cln_prof, &cfg);
3391 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3393 OBD_FREE(cln_prof, len);
3394 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
3395 mds->mds_profile = NULL;
3400 int mds_md_clean(struct obd_device *obd)
3402 struct mds_obd *mds = &obd->u.mds;
3405 if (mds->mds_md_name) {
3406 OBD_FREE(mds->mds_md_name, strlen(mds->mds_md_name) + 1);
3407 mds->mds_md_name = NULL;
3412 static int mds_precleanup(struct obd_device *obd, int flags)
3418 mds_dt_disconnect(obd, flags);
3420 obd_llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
3424 extern void lgss_svc_cache_purge_all(void);
3425 static int mds_cleanup(struct obd_device *obd, int flags)
3427 struct mds_obd *mds = &obd->u.mds;
3430 if (mds->mds_sb == NULL)
3433 mds_update_server_data(obd, 1);
3434 mds_update_last_fid(obd, NULL, 1);
3436 if (mds->mds_dt_objids != NULL) {
3437 int size = mds->mds_dt_desc.ld_tgt_count *
3439 OBD_FREE(mds->mds_dt_objids, size);
3441 mds_fs_cleanup(obd, flags);
3445 /* 2 seems normal on mds, (may_umount() also expects 2
3446 fwiw), but we only see 1 at this point in obdfilter. */
3447 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3451 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
3453 spin_lock_bh(&obd->obd_processing_task_lock);
3454 if (obd->obd_recovering) {
3455 target_cancel_recovery_timer(obd);
3456 obd->obd_recovering = 0;
3458 spin_unlock_bh(&obd->obd_processing_task_lock);
3461 fsfilt_put_ops(obd->obd_fsops);
3465 lgss_svc_cache_purge_all();
3470 static int set_security(const char *value, char **sec)
3474 if (!strcmp(value, "null"))
3476 else if (!strcmp(value, "krb5i"))
3478 else if (!strcmp(value, "krb5p"))
3481 CERROR("Unrecognized value, force use NULL\n");
3488 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
3490 struct lustre_cfg *lcfg = buf;
3491 struct mds_obd *mds = &obd->u.mds;
3495 switch(lcfg->lcfg_command) {
3496 case LCFG_SET_SECURITY: {
3497 if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inllen2)
3498 GOTO(out, rc = -EINVAL);
3500 if (!strcmp(lcfg->lcfg_inlbuf1, "mds_mds_sec"))
3501 rc = set_security(lcfg->lcfg_inlbuf2,
3503 else if (!strcmp(lcfg->lcfg_inlbuf1, "mds_ost_sec"))
3504 rc = set_security(lcfg->lcfg_inlbuf2,
3507 CERROR("Unrecognized key\n");
3513 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
3514 GOTO(out, rc = -EINVAL);
3522 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
3524 struct ldlm_lock *new_lock,
3525 struct ldlm_lock **old_lock,
3526 struct lustre_handle *lockh)
3528 struct obd_export *exp = req->rq_export;
3529 struct obd_device *obd = exp->exp_obd;
3530 struct ldlm_request *dlmreq =
3531 lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq));
3532 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
3533 struct list_head *iter;
3535 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3538 l_lock(&obd->obd_namespace->ns_lock);
3539 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
3540 struct ldlm_lock *lock;
3541 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
3542 if (lock == new_lock)
3544 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
3545 lockh->cookie = lock->l_handle.h_cookie;
3546 LDLM_DEBUG(lock, "restoring lock cookie");
3547 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
3550 *old_lock = LDLM_LOCK_GET(lock);
3551 l_unlock(&obd->obd_namespace->ns_lock);
3555 l_unlock(&obd->obd_namespace->ns_lock);
3557 /* If the xid matches, then we know this is a resent request,
3558 * and allow it. (It's probably an OPEN, for which we don't
3561 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
3565 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
3568 /* This remote handle isn't enqueued, so we never received or
3569 * processed this request. Clear MSG_RESENT, because it can
3570 * be handled like any normal request now. */
3572 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3574 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
3578 int intent_disposition(struct ldlm_reply *rep, int flag)
3582 return (rep->lock_policy_res1 & flag);
3585 void intent_set_disposition(struct ldlm_reply *rep, int flag)
3589 rep->lock_policy_res1 |= flag;
3592 static int mds_intent_policy(struct ldlm_namespace *ns,
3593 struct ldlm_lock **lockp, void *req_cookie,
3594 ldlm_mode_t mode, int flags, void *data)
3596 struct ptlrpc_request *req = req_cookie;
3597 struct ldlm_lock *lock = *lockp;
3598 struct ldlm_intent *it;
3599 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
3600 struct ldlm_reply *rep;
3601 struct lustre_handle lockh[2] = {{0}, {0}};
3602 struct ldlm_lock *new_lock = NULL;
3603 int getattr_part = MDS_INODELOCK_UPDATE;
3604 int rc, reply_buffers;
3605 int repsize[5] = {sizeof(struct ldlm_reply),
3606 sizeof(struct mds_body),
3607 mds->mds_max_mdsize};
3609 int offset = MDS_REQ_INTENT_REC_OFF;
3612 LASSERT(req != NULL);
3613 MD_COUNTER_INCREMENT(req->rq_export->exp_obd, intent_lock);
3615 if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) {
3616 /* No intent was provided */
3617 int size = sizeof(struct ldlm_reply);
3618 rc = lustre_pack_reply(req, 1, &size, NULL);
3623 it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it),
3624 lustre_swab_ldlm_intent);
3626 CERROR("Intent missing\n");
3627 RETURN(req->rq_status = -EFAULT);
3630 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
3633 if (it->opc & ( IT_OPEN | IT_GETATTR | IT_LOOKUP | IT_CHDIR )) {
3636 repsize[4] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
3639 rc = lustre_pack_reply(req, reply_buffers, repsize, NULL);
3641 RETURN(req->rq_status = rc);
3643 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
3644 LASSERT(rep != NULL);
3646 intent_set_disposition(rep, DISP_IT_EXECD);
3648 /* execute policy */
3649 switch ((long)it->opc) {
3651 case IT_CREAT|IT_OPEN:
3652 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3654 /* XXX swab here to assert that an mds_open reint
3655 * packet is following */
3656 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3658 rep->lock_policy_res2 = mds_reint(req, offset, lockh);
3660 if (rep->lock_policy_res2) {
3662 * mds_open() returns ENOLCK where it should return
3663 * zero, but it has no lock to return.
3665 if (rep->lock_policy_res2 == ENOLCK)
3666 rep->lock_policy_res2 = 0;
3668 RETURN(ELDLM_LOCK_ABORTED);
3672 * IT_OPEN may return lock on cross-node dentry that we want to
3673 * hold during attr retrival -bzzz
3675 if (lockh[0].cookie == 0)
3676 RETURN(ELDLM_LOCK_ABORTED);
3680 getattr_part = MDS_INODELOCK_LOOKUP;
3683 getattr_part |= MDS_INODELOCK_LOOKUP;
3685 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3686 lock, &new_lock, lockh);
3687 rep->lock_policy_res2 = mds_getattr_lock(req, offset, lockh,
3689 /* FIXME: LDLM can set req->rq_status. MDS sets
3690 policy_res{1,2} with disposition and status.
3691 - replay: returns 0 & req->status is old status
3692 - otherwise: returns req->status */
3693 if (intent_disposition(rep, DISP_LOOKUP_NEG))
3694 rep->lock_policy_res2 = 0;
3695 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
3696 rep->lock_policy_res2)
3697 RETURN(ELDLM_LOCK_ABORTED);
3698 if (req->rq_status != 0) {
3700 rep->lock_policy_res2 = req->rq_status;
3701 RETURN(ELDLM_LOCK_ABORTED);
3705 rc = mds_lock_and_check_slave(offset, req, lockh);
3706 if ((rep->lock_policy_res2 = rc)) {
3708 rep->lock_policy_res2 = 0;
3709 RETURN(ELDLM_LOCK_ABORTED);
3713 CERROR("Unhandled intent "LPD64"\n", it->opc);
3717 /* By this point, whatever function we called above must have either
3718 * filled in 'lockh', been an intent replay, or returned an error. We
3719 * want to allow replayed RPCs to not get a lock, since we would just
3720 * drop it below anyways because lock replay is done separately by the
3721 * client afterwards. For regular RPCs we want to give the new lock to
3722 * the client instead of whatever lock it was about to get. */
3723 if (new_lock == NULL)
3724 new_lock = ldlm_handle2lock(&lockh[0]);
3725 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
3728 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
3729 it->opc, lockh[0].cookie);
3731 /* If we've already given this lock to a client once, then we should
3732 * have no readers or writers. Otherwise, we should have one reader
3733 * _or_ writer ref (which will be zeroed below) before returning the
3734 * lock to a client. */
3735 if (new_lock->l_export == req->rq_export) {
3736 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3738 LASSERT(new_lock->l_export == NULL);
3739 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3744 if (new_lock->l_export == req->rq_export) {
3745 /* Already gave this to the client, which means that we
3746 * reconstructed a reply. */
3747 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3749 RETURN(ELDLM_LOCK_REPLACED);
3752 /* Fixup the lock to be given to the client */
3753 l_lock(&new_lock->l_resource->lr_namespace->ns_lock);
3754 new_lock->l_readers = 0;
3755 new_lock->l_writers = 0;
3757 new_lock->l_export = class_export_get(req->rq_export);
3758 list_add(&new_lock->l_export_chain,
3759 &new_lock->l_export->exp_ldlm_data.led_held_locks);
3761 new_lock->l_blocking_ast = lock->l_blocking_ast;
3762 new_lock->l_completion_ast = lock->l_completion_ast;
3764 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
3765 sizeof(lock->l_remote_handle));
3767 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3769 LDLM_LOCK_PUT(new_lock);
3770 l_unlock(&new_lock->l_resource->lr_namespace->ns_lock);
3772 RETURN(ELDLM_LOCK_REPLACED);
3775 int mds_attach(struct obd_device *dev, obd_count len, void *data)
3777 struct lprocfs_static_vars lvars;
3780 lprocfs_init_multi_vars(0, &lvars);
3782 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
3786 return lprocfs_alloc_md_stats(dev, 0);
3789 int mds_detach(struct obd_device *dev)
3791 lprocfs_free_md_stats(dev);
3792 return lprocfs_obd_detach(dev);
3795 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
3797 struct lprocfs_static_vars lvars;
3799 lprocfs_init_multi_vars(1, &lvars);
3800 return lprocfs_obd_attach(dev, lvars.obd_vars);
3803 int mdt_detach(struct obd_device *dev)
3805 return lprocfs_obd_detach(dev);
3808 static int mdt_setup(struct obd_device *obd, obd_count len, void *buf)
3810 struct mds_obd *mds = &obd->u.mds;
3815 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3816 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
3817 MDS_SERVICE_WATCHDOG_TIMEOUT,
3818 mds_handle, "mds", obd->obd_proc_entry);
3820 if (!mds->mds_service) {
3821 CERROR("failed to start service\n");
3825 rc = ptlrpc_start_n_threads(obd, mds->mds_service, MDT_NUM_THREADS,
3828 GOTO(err_thread, rc);
3830 mds->mds_setattr_service =
3831 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3832 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
3833 MDS_SERVICE_WATCHDOG_TIMEOUT,
3834 mds_handle, "mds_setattr",
3835 obd->obd_proc_entry);
3836 if (!mds->mds_setattr_service) {
3837 CERROR("failed to start getattr service\n");
3838 GOTO(err_thread, rc = -ENOMEM);
3841 rc = ptlrpc_start_n_threads(obd, mds->mds_setattr_service,
3842 MDT_NUM_THREADS, "ll_mdt_attr");
3844 GOTO(err_thread2, rc);
3846 mds->mds_readpage_service =
3847 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3848 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
3849 MDS_SERVICE_WATCHDOG_TIMEOUT,
3850 mds_handle, "mds_readpage",
3851 obd->obd_proc_entry);
3852 if (!mds->mds_readpage_service) {
3853 CERROR("failed to start readpage service\n");
3854 GOTO(err_thread2, rc = -ENOMEM);
3857 rc = ptlrpc_start_n_threads(obd, mds->mds_readpage_service,
3858 MDT_NUM_THREADS, "ll_mdt_rdpg");
3861 GOTO(err_thread3, rc);
3866 ptlrpc_unregister_service(mds->mds_readpage_service);
3868 ptlrpc_unregister_service(mds->mds_setattr_service);
3870 ptlrpc_unregister_service(mds->mds_service);
3874 static int mdt_cleanup(struct obd_device *obd, int flags)
3876 struct mds_obd *mds = &obd->u.mds;
3879 ptlrpc_stop_all_threads(mds->mds_readpage_service);
3880 ptlrpc_unregister_service(mds->mds_readpage_service);
3882 ptlrpc_stop_all_threads(mds->mds_setattr_service);
3883 ptlrpc_unregister_service(mds->mds_setattr_service);
3885 ptlrpc_stop_all_threads(mds->mds_service);
3886 ptlrpc_unregister_service(mds->mds_service);
3891 static struct dentry *mds_lvfs_id2dentry(__u64 ino, __u32 gen,
3892 __u64 gr, void *data)
3894 struct lustre_id id;
3895 struct obd_device *obd = data;
3899 return mds_id2dentry(obd, &id, NULL);
3902 static int mds_get_info(struct obd_export *exp, __u32 keylen,
3903 void *key, __u32 *valsize, void *val)
3905 struct obd_device *obd;
3906 struct mds_obd *mds;
3909 obd = class_exp2obd(exp);
3913 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
3914 exp->exp_handle.h_cookie);
3918 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
3919 /* get log_context handle. */
3920 unsigned long *llh_handle = val;
3921 *valsize = sizeof(unsigned long);
3922 *llh_handle = (unsigned long)obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT];
3925 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
3926 /* get log_context handle. */
3927 unsigned long *sb = val;
3928 *valsize = sizeof(unsigned long);
3929 *sb = (unsigned long)obd->u.mds.mds_sb;
3933 if (keylen >= strlen("mdsize") && memcmp(key, "mdsize", keylen) == 0) {
3934 __u32 *mdsize = val;
3935 *valsize = sizeof(*mdsize);
3936 *mdsize = mds->mds_max_mdsize;
3940 if (keylen >= strlen("mdsnum") && strcmp(key, "mdsnum") == 0) {
3941 __u32 *mdsnum = val;
3942 *valsize = sizeof(*mdsnum);
3943 *mdsnum = mds->mds_num;
3947 if (keylen >= strlen("rootid") && strcmp(key, "rootid") == 0) {
3948 struct lustre_id *rootid = val;
3949 *valsize = sizeof(struct lustre_id);
3950 *rootid = mds->mds_rootid;
3954 CDEBUG(D_IOCTL, "invalid key\n");
3958 struct lvfs_callback_ops mds_lvfs_ops = {
3959 l_id2dentry: mds_lvfs_id2dentry,
3962 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
3963 int objcount, struct obd_ioobj *obj,
3964 int niocount, struct niobuf_remote *nb,
3965 struct niobuf_local *res,
3966 struct obd_trans_info *oti);
3968 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
3969 int objcount, struct obd_ioobj *obj, int niocount,
3970 struct niobuf_local *res, struct obd_trans_info *oti,
3973 /* use obd ops to offer management infrastructure */
3974 static struct obd_ops mds_obd_ops = {
3975 .o_owner = THIS_MODULE,
3976 .o_attach = mds_attach,
3977 .o_detach = mds_detach,
3978 .o_connect = mds_connect,
3979 .o_connect_post = mds_connect_post,
3980 .o_init_export = mds_init_export,
3981 .o_destroy_export = mds_destroy_export,
3982 .o_disconnect = mds_disconnect,
3983 .o_setup = mds_setup,
3984 .o_precleanup = mds_precleanup,
3985 .o_cleanup = mds_cleanup,
3986 .o_process_config = mds_process_config,
3987 .o_postrecov = mds_postrecov,
3988 .o_statfs = mds_obd_statfs,
3989 .o_iocontrol = mds_iocontrol,
3990 .o_create = mds_obd_create,
3991 .o_destroy = mds_obd_destroy,
3992 .o_llog_init = mds_llog_init,
3993 .o_llog_finish = mds_llog_finish,
3994 .o_notify = mds_notify,
3995 .o_get_info = mds_get_info,
3996 .o_set_info = mds_set_info,
3997 .o_preprw = mds_preprw,
3998 .o_commitrw = mds_commitrw,
4001 static struct obd_ops mdt_obd_ops = {
4002 .o_owner = THIS_MODULE,
4003 .o_attach = mdt_attach,
4004 .o_detach = mdt_detach,
4005 .o_setup = mdt_setup,
4006 .o_cleanup = mdt_cleanup,
4009 static int __init mds_init(void)
4011 struct lprocfs_static_vars lvars;
4013 mds_init_lsd_cache();
4015 lprocfs_init_multi_vars(0, &lvars);
4016 class_register_type(&mds_obd_ops, NULL, lvars.module_vars,
4018 lprocfs_init_multi_vars(1, &lvars);
4019 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars,
4025 static void /*__exit*/ mds_exit(void)
4027 mds_cleanup_lsd_cache();
4029 class_unregister_type(LUSTRE_MDS_NAME);
4030 class_unregister_type(LUSTRE_MDT_NAME);
4033 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4034 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
4035 MODULE_LICENSE("GPL");
4037 module_init(mds_init);
4038 module_exit(mds_exit);