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 initial,
568 struct obd_device *obd = exp->exp_obd;
569 struct mds_obd *mds = &obd->u.mds;
570 struct mds_export_data *med;
571 struct mds_client_data *mcd;
575 med = &exp->exp_mds_data;
579 /* some one reconnect initially, we have to reset
580 * data existing export can have. bug 6102 */
581 if (mcd->mcd_last_xid != 0)
582 CDEBUG(D_HA, "initial reconnect to existing export\n");
583 mcd->mcd_last_transno = 0;
584 mcd->mcd_last_xid = 0;
585 mcd->mcd_last_result = 0;
586 mcd->mcd_last_data = 0;
589 if (!(flags & OBD_OPT_MDS_CONNECTION)) {
590 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
591 atomic_inc(&mds->mds_real_clients);
592 CDEBUG(D_OTHER,"%s: peer from %s is real client (%d)\n",
593 obd->obd_name, exp->exp_client_uuid.uuid,
594 atomic_read(&mds->mds_real_clients));
595 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
597 if (mds->mds_md_name)
598 rc = mds_md_connect(obd, mds->mds_md_name);
603 static int mds_init_export(struct obd_export *exp)
605 struct mds_export_data *med = &exp->exp_mds_data;
607 INIT_LIST_HEAD(&med->med_open_head);
608 spin_lock_init(&med->med_open_lock);
612 static int mds_destroy_export(struct obd_export *export)
614 struct obd_device *obd = export->exp_obd;
615 struct mds_export_data *med = &export->exp_mds_data;
616 struct lvfs_run_ctxt saved;
620 mds_free_export_data(med);
621 target_destroy_export(export);
623 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
626 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
628 /* Close any open files (which may also cause orphan unlinking). */
629 spin_lock(&med->med_open_lock);
630 while (!list_empty(&med->med_open_head)) {
631 struct list_head *tmp = med->med_open_head.next;
632 struct mds_file_data *mfd =
633 list_entry(tmp, struct mds_file_data, mfd_list);
634 struct lustre_id sid;
636 BDEVNAME_DECLARE_STORAGE(btmp);
638 /* bug 1579: fix force-closing for 2.5 */
639 struct dentry *dentry = mfd->mfd_dentry;
641 list_del(&mfd->mfd_list);
642 spin_unlock(&med->med_open_lock);
644 down(&dentry->d_inode->i_sem);
645 rc = mds_read_inode_sid(obd, dentry->d_inode, &sid);
646 up(&dentry->d_inode->i_sem);
648 CERROR("Can't read inode self id, inode %lu, "
649 "rc %d\n", dentry->d_inode->i_ino, rc);
650 memset(&sid, 0, sizeof(sid));
653 /* If you change this message, be sure to update
654 * replay_single:test_46 */
655 CERROR("force closing client file handle for %.*s (%s:"
656 DLID4")\n", dentry->d_name.len, dentry->d_name.name,
657 ll_bdevname(dentry->d_inode->i_sb, btmp),
660 /* child inode->i_alloc_sem protects orphan_dec_test and
661 * is_orphan race, mds_mfd_close drops it */
662 DOWN_WRITE_I_ALLOC_SEM(dentry->d_inode);
663 rc = mds_mfd_close(NULL, 0, obd, mfd,
664 !(export->exp_flags & OBD_OPT_FAILOVER));
666 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
667 spin_lock(&med->med_open_lock);
669 spin_unlock(&med->med_open_lock);
670 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
674 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
678 static int mds_disconnect(struct obd_export *exp, unsigned long flags)
680 unsigned long irqflags;
681 struct obd_device *obd;
686 LASSERT(exp != NULL);
687 obd = class_exp2obd(exp);
689 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
690 exp->exp_handle.h_cookie);
696 * suppress any inter-mds requests durring disconnecting lmv if this is
697 * detected --force mode. This is needed to avoid endless recovery.
699 if (atomic_read(&mds->mds_real_clients) > 0 &&
700 !(exp->exp_flags & OBD_OPT_REAL_CLIENT))
701 flags |= OBD_OPT_FORCE;
703 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
704 && !atomic_read(&mds->mds_real_clients)) {
705 /* there was no client at all */
706 mds_md_disconnect(obd, flags);
709 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
710 && atomic_dec_and_test(&mds->mds_real_clients)) {
711 /* time to drop LMV connections */
712 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
713 "Disconnnect from LMV now\n",
714 obd->obd_name, exp->exp_client_uuid.uuid);
715 mds_md_disconnect(obd, flags);
718 spin_lock_irqsave(&exp->exp_lock, irqflags);
719 exp->exp_flags = flags;
720 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
722 /* disconnect early so that clients can't keep using export */
723 rc = class_disconnect(exp, flags);
724 ldlm_cancel_locks_for_export(exp);
726 /* complete all outstanding replies */
727 spin_lock_irqsave(&exp->exp_lock, irqflags);
728 while (!list_empty(&exp->exp_outstanding_replies)) {
729 struct ptlrpc_reply_state *rs =
730 list_entry(exp->exp_outstanding_replies.next,
731 struct ptlrpc_reply_state, rs_exp_list);
732 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
734 spin_lock(&svc->srv_lock);
735 list_del_init(&rs->rs_exp_list);
736 ptlrpc_schedule_difficult_reply(rs);
737 spin_unlock(&svc->srv_lock);
739 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
743 static int mds_getstatus(struct ptlrpc_request *req)
745 struct mds_obd *mds = mds_req2mds(req);
746 struct mds_body *body;
750 size = sizeof(*body);
752 rc = lustre_pack_reply(req, 1, &size, NULL);
753 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
754 CERROR("mds: out of memory for message: size=%d\n", size);
755 req->rq_status = -ENOMEM; /* superfluous? */
759 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
760 body->valid |= OBD_MD_FID;
762 memcpy(&body->id1, &mds->mds_rootid, sizeof(body->id1));
765 * the last_committed and last_xid fields are filled in for all replies
766 * already - no need to do so here also.
771 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
772 void *data, int flag)
777 if (flag == LDLM_CB_CANCELING) {
778 /* Don't need to do anything here. */
782 /* XXX layering violation! -phil */
783 l_lock(&lock->l_resource->lr_namespace->ns_lock);
786 * get this: if mds_blocking_ast is racing with mds_intent_policy, such
787 * that mds_blocking_ast is called just before l_i_p takes the ns_lock,
788 * then by the time we get the lock, we might not be the correct
789 * blocking function anymore. So check, and return early, if so.
791 if (lock->l_blocking_ast != mds_blocking_ast) {
792 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
796 lock->l_flags |= LDLM_FL_CBPENDING;
797 do_ast = (!lock->l_readers && !lock->l_writers);
798 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
801 struct lustre_handle lockh;
804 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
805 ldlm_lock2handle(lock, &lockh);
806 rc = ldlm_cli_cancel(&lockh);
808 CERROR("ldlm_cli_cancel: %d\n", rc);
810 LDLM_DEBUG(lock, "Lock still has references, will be "
816 static int mds_convert_md(struct obd_device *obd, struct inode *inode,
817 void *md, int size, int mea)
821 if (S_ISREG(inode->i_mode)) {
822 rc = mds_convert_lov_ea(obd, inode, md, size);
823 } else if (S_ISDIR(inode->i_mode)) {
825 rc = mds_convert_mea_ea(obd, inode, md, size);
827 rc = mds_convert_lov_ea(obd, inode, md, size);
830 CERROR("Invalid EA format (nor LOV or MEA) "
831 "is detected. Inode %lu/%u\n",
832 inode->i_ino, inode->i_generation);
838 int mds_get_md(struct obd_device *obd, struct inode *inode,
839 void *md, int *size, int lock, int mea)
848 rc = fsfilt_get_md(obd, inode, md, *size,
849 (mea ? EA_MEA : EA_LOV));
851 CERROR("Error %d reading eadata for ino %lu\n",
855 rc = mds_convert_md(obd, inode, md,
871 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
872 * Call with lock=0 if the caller has already taken the i_sem. */
873 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
874 struct mds_body *body, struct inode *inode, int lock, int mea)
876 struct mds_obd *mds = &obd->u.mds;
882 lmm = lustre_msg_buf(msg, offset, 0);
884 /* Some problem with getting eadata when I sized the reply
886 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
890 lmm_size = msg->buflens[offset];
892 /* I don't really like this, but it is a sanity check on the client
893 * MD request. However, if the client doesn't know how much space
894 * to reserve for the MD, it shouldn't be bad to have too much space.
896 if (lmm_size > mds->mds_max_mdsize) {
897 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
898 inode->i_ino, lmm_size, mds->mds_max_mdsize);
902 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, mea);
904 if (S_ISDIR(inode->i_mode))
905 body->valid |= OBD_MD_FLDIREA;
907 body->valid |= OBD_MD_FLEASIZE;
910 body->valid |= OBD_MD_MEA;
912 body->eadatasize = lmm_size;
918 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
919 struct mds_body *repbody, int reply_off)
921 struct inode *inode = dentry->d_inode;
926 symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
927 LASSERT(symname != NULL);
928 len = req->rq_repmsg->buflens[reply_off + 1];
930 rc = inode->i_op->readlink(dentry, symname, len);
932 CERROR("readlink failed: %d\n", rc);
933 } else if (rc != len - 1) {
934 CERROR ("Unexpected readlink rc %d: expecting %d\n",
938 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
939 repbody->valid |= OBD_MD_LINKNAME;
940 repbody->eadatasize = rc + 1;
941 symname[rc] = 0; /* NULL terminate */
948 int mds_pack_ea(struct dentry *dentry, struct ptlrpc_request *req,
949 struct mds_body *repbody, int req_off, int reply_off)
951 struct inode *inode = dentry->d_inode;
957 ea_name = lustre_msg_string(req->rq_reqmsg, req_off + 1, 0);
958 len = req->rq_repmsg->buflens[reply_off + 1];
960 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
963 if (inode->i_op && inode->i_op->getxattr)
964 rc = inode->i_op->getxattr(dentry, ea_name, value, len);
967 if (rc != -ENODATA && rc != -EOPNOTSUPP)
968 CERROR("getxattr failed: %d", rc);
970 repbody->valid |= OBD_MD_FLEA;
971 repbody->eadatasize = rc;
978 int mds_pack_ealist(struct dentry *dentry, struct ptlrpc_request *req,
979 struct mds_body *repbody, int reply_off)
981 struct inode *inode = dentry->d_inode;
986 len = req->rq_repmsg->buflens[reply_off + 1];
988 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
991 if (inode->i_op && inode->i_op->getxattr)
992 rc = inode->i_op->listxattr(dentry, value, len);
995 CERROR("listxattr failed: %d", rc);
997 repbody->valid |= OBD_MD_FLEALIST;
998 repbody->eadatasize = rc;
1004 int mds_pack_acl(struct obd_device *obd, struct lustre_msg *repmsg, int offset,
1005 struct mds_body *body, struct inode *inode)
1007 struct dentry de = { .d_inode = inode };
1008 __u32 buflen, *sizep;
1013 if (!inode->i_op->getxattr)
1016 buflen = repmsg->buflens[offset + 1];
1017 buf = lustre_msg_buf(repmsg, offset + 1, buflen);
1019 size = inode->i_op->getxattr(&de, XATTR_NAME_ACL_ACCESS, buf, buflen);
1020 if (size == -ENODATA || size == -EOPNOTSUPP)
1026 sizep = lustre_msg_buf(repmsg, offset, 4);
1028 CERROR("can't locate returned acl size buf\n");
1032 *sizep = cpu_to_le32(size);
1033 body->valid |= OBD_MD_FLACL_ACCESS;
1039 * here we take simple rule: once uid/fsuid is root, we also squash
1040 * the gid/fsgid, don't care setuid/setgid attributes.
1042 int mds_squash_root(struct mds_obd *mds, struct mds_req_sec_desc *rsd,
1045 if (!mds->mds_squash_uid || *peernid == mds->mds_nosquash_nid)
1048 if (rsd->rsd_uid && rsd->rsd_fsuid)
1051 CDEBUG(D_SEC, "squash req from "LPX64":"
1052 "(%u:%u-%u:%u/%x)=>(%u:%u-%u:%u/%x)\n", *peernid,
1053 rsd->rsd_uid, rsd->rsd_gid,
1054 rsd->rsd_fsuid, rsd->rsd_fsgid, rsd->rsd_cap,
1055 rsd->rsd_uid ? rsd->rsd_uid : mds->mds_squash_uid,
1056 rsd->rsd_uid ? rsd->rsd_gid : mds->mds_squash_gid,
1057 rsd->rsd_fsuid ? rsd->rsd_fsuid : mds->mds_squash_uid,
1058 rsd->rsd_fsuid ? rsd->rsd_fsgid : mds->mds_squash_gid,
1059 rsd->rsd_cap & ~CAP_FS_MASK);
1061 if (rsd->rsd_uid == 0) {
1062 rsd->rsd_uid = mds->mds_squash_uid;
1063 rsd->rsd_gid = mds->mds_squash_gid;
1065 if (rsd->rsd_fsuid == 0) {
1066 rsd->rsd_fsuid = mds->mds_squash_uid;
1067 rsd->rsd_fsgid = mds->mds_squash_gid;
1069 rsd->rsd_cap &= ~CAP_FS_MASK;
1074 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
1075 struct ptlrpc_request *req, int req_off,
1076 struct mds_body *reqbody, int reply_off)
1078 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
1079 struct inode *inode = dentry->d_inode;
1080 struct mds_body *body;
1084 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
1087 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
1088 LASSERT(body != NULL); /* caller prepped reply */
1090 if (dentry->d_flags & DCACHE_CROSS_REF) {
1091 mds_pack_dentry2body(obd, body, dentry,
1092 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1093 CDEBUG(D_OTHER, "cross reference: "DLID4"\n",
1098 mds_pack_inode2body(obd, body, inode,
1099 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1101 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
1102 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
1104 /* guessing what kind og attribute do we need. */
1105 int is_mea = (S_ISDIR(inode->i_mode) &&
1106 (reqbody->valid & OBD_MD_MEA) != 0);
1108 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1,
1109 body, inode, 1, is_mea);
1111 /* if we have LOV EA data, the OST holds size, atime, mtime. */
1112 if (!(body->valid & OBD_MD_FLEASIZE) &&
1113 !(body->valid & OBD_MD_FLDIREA))
1114 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
1115 OBD_MD_FLATIME | OBD_MD_FLMTIME);
1116 } else if (S_ISLNK(inode->i_mode) &&
1117 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
1118 rc = mds_pack_link(dentry, req, body, reply_off);
1119 } else if (reqbody->valid & OBD_MD_FLEA) {
1120 rc = mds_pack_ea(dentry, req, body, req_off, reply_off);
1121 } else if (reqbody->valid & OBD_MD_FLEALIST) {
1122 rc = mds_pack_ealist(dentry, req, body, reply_off);
1125 if (reqbody->valid & OBD_MD_FLACL_ACCESS) {
1126 int inc = (reqbody->valid & OBD_MD_FLEASIZE) ? 2 : 1;
1127 rc = mds_pack_acl(obd, req->rq_repmsg, reply_off + inc,
1132 mds_body_do_reverse_map(med, body);
1137 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
1138 struct dentry *dentry,
1141 int rc = 0, size[1] = {sizeof(struct mds_body)};
1144 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1145 CERROR("failed MDS_GETATTR_PACK test\n");
1146 req->rq_status = -ENOMEM;
1150 rc = lustre_pack_reply(req, 1, size, NULL);
1152 CERROR("lustre_pack_reply failed: rc %d\n", rc);
1153 GOTO(out, req->rq_status = rc);
1161 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct dentry *de,
1164 struct inode *inode = de->d_inode;
1165 struct mds_obd *mds = mds_req2mds(req);
1166 struct mds_body *body;
1167 int rc = 0, size[4] = {sizeof(*body)}, bufcount = 1;
1170 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
1171 LASSERT(body != NULL); /* checked by caller */
1172 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
1174 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
1175 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
1178 down(&inode->i_sem);
1179 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
1180 ((body->valid & OBD_MD_MEA) ? EA_MEA : EA_LOV));
1183 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1184 CERROR("error getting inode %lu MD: rc = %d\n",
1187 } else if (rc > mds->mds_max_mdsize) {
1189 CERROR("MD size %d larger than maximum possible %u\n",
1190 rc, mds->mds_max_mdsize);
1192 size[bufcount] = rc;
1195 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
1196 if (inode->i_size + 1 != body->eadatasize)
1197 CERROR("symlink size: %Lu, reply space: %d\n",
1198 inode->i_size + 1, body->eadatasize);
1199 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
1201 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
1202 inode->i_size + 1, body->eadatasize);
1203 } else if ((body->valid & OBD_MD_FLEA)) {
1204 char *ea_name = lustre_msg_string(req->rq_reqmsg,
1207 if (inode->i_op && inode->i_op->getxattr)
1208 rc = inode->i_op->getxattr(de, ea_name, NULL, 0);
1211 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1212 CERROR("error getting inode %lu EA: rc = %d\n",
1216 size[bufcount] = min_t(int, body->eadatasize, rc);
1219 } else if (body->valid & OBD_MD_FLEALIST) {
1221 if (inode->i_op && inode->i_op->getxattr)
1222 rc = inode->i_op->listxattr(de, NULL, 0);
1225 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1226 CERROR("error getting inode %lu EA: rc = %d\n",
1230 size[bufcount] = min_t(int, body->eadatasize, rc);
1235 /* may co-exist with OBD_MD_FLEASIZE */
1236 if (body->valid & OBD_MD_FLACL_ACCESS) {
1237 size[bufcount++] = 4;
1238 size[bufcount++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
1241 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1242 CERROR("failed MDS_GETATTR_PACK test\n");
1243 req->rq_status = -ENOMEM;
1244 GOTO(out, rc = -ENOMEM);
1247 rc = lustre_pack_reply(req, bufcount, size, NULL);
1249 CERROR("out of memory\n");
1250 GOTO(out, req->rq_status = rc);
1258 int mds_check_mds_num(struct obd_device *obd, struct inode *inode,
1259 char *name, int namelen)
1261 struct mea *mea = NULL;
1262 int mea_size, rc = 0;
1265 rc = mds_md_get_attr(obd, inode, &mea, &mea_size);
1270 * dir is already splitted, check if requested filename should
1271 * live at this MDS or at another one.
1273 int i = mea_name2idx(mea, name, namelen - 1);
1274 if (mea->mea_master != id_group(&mea->mea_ids[i])) {
1276 "inapropriate MDS(%d) for %s. should be "
1277 "%lu(%d)\n", mea->mea_master, name,
1278 (unsigned long)id_group(&mea->mea_ids[i]), i);
1284 OBD_FREE(mea, mea_size);
1288 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
1289 struct lustre_handle *child_lockh, int child_part)
1291 struct obd_device *obd = req->rq_export->exp_obd;
1292 struct mds_obd *mds = &obd->u.mds;
1293 struct ldlm_reply *rep = NULL;
1294 struct lvfs_run_ctxt saved;
1295 struct mds_req_sec_desc *rsd;
1296 struct mds_body *body;
1297 struct dentry *dparent = NULL, *dchild = NULL;
1298 struct lvfs_ucred uc = {NULL, NULL,};
1299 struct lustre_handle parent_lockh[2] = {{0}, {0}};
1300 unsigned int namesize;
1301 int rc = 0, cleanup_phase = 0, resent_req = 0, update_mode, reply_offset;
1305 LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME));
1306 MD_COUNTER_INCREMENT(obd, getattr_lock);
1308 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1310 CERROR("Can't unpack security desc\n");
1314 /* swab now, before anyone looks inside the request. */
1315 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1316 lustre_swab_mds_body);
1318 CERROR("Can't swab mds_body\n");
1319 GOTO(cleanup, rc = -EFAULT);
1322 LASSERT_REQSWAB(req, offset + 1);
1323 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
1325 CERROR("Can't unpack name\n");
1326 GOTO(cleanup, rc = -EFAULT);
1328 namesize = req->rq_reqmsg->buflens[offset + 1];
1330 /* namesize less than 2 means we have empty name, probably came from
1331 revalidate by cfid, so no point in having name to be set */
1335 LASSERT (offset == 1 || offset == 3);
1337 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
1343 rc = mds_init_ucred(&uc, req, rsd);
1348 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1349 cleanup_phase = 1; /* kernel context */
1350 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
1352 LASSERT(namesize > 0);
1353 if (child_lockh->cookie != 0) {
1354 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1359 if (body->valid == OBD_MD_FLID) {
1360 struct mds_body *mds_reply;
1361 int size = sizeof(*mds_reply);
1365 dparent = mds_id2dentry(obd, &body->id1, NULL);
1366 if (IS_ERR(dparent)) {
1367 rc = PTR_ERR(dparent);
1372 * the user requested ONLY the inode number, so do a raw lookup.
1374 rc = lustre_pack_reply(req, 1, &size, NULL);
1376 CERROR("out of memory\n");
1380 dir = dparent->d_inode;
1381 LASSERT(dir->i_op->lookup_raw != NULL);
1382 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
1384 mds_reply = lustre_msg_buf(req->rq_repmsg, 0,
1385 sizeof(*mds_reply));
1387 id_ino(&mds_reply->id1) = inum;
1388 mds_reply->valid = OBD_MD_FLID;
1393 if (resent_req == 0) {
1394 LASSERT(id_fid(&body->id1) != 0);
1396 rc = mds_get_parent_child_locked(obd, mds, &body->id1,
1397 parent_lockh, &dparent,
1399 MDS_INODELOCK_UPDATE,
1402 child_lockh, &dchild,
1403 LCK_PR, child_part);
1407 cleanup_phase = 2; /* dchild, dparent, locks */
1410 * let's make sure this name should leave on this mds
1413 rc = mds_check_mds_num(obd, dparent->d_inode, name, namesize);
1417 /* we have no dentry here, drop LOOKUP bit */
1418 /* FIXME: we need MDS_INODELOCK_LOOKUP or not. */
1419 child_part &= ~MDS_INODELOCK_LOOKUP;
1420 CDEBUG(D_OTHER, "%s: retrieve attrs for "DLID4"\n",
1421 obd->obd_name, OLID4(&body->id1));
1423 dchild = mds_id2locked_dentry(obd, &body->id1, NULL,
1424 LCK_PR, parent_lockh,
1427 MDS_INODELOCK_UPDATE);
1428 if (IS_ERR(dchild)) {
1429 CERROR("can't find inode with id "DLID4", err = %d\n",
1430 OLID4(&body->id1), (int)PTR_ERR(dchild));
1431 GOTO(cleanup, rc = PTR_ERR(dchild));
1433 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
1436 struct ldlm_lock *granted_lock;
1438 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
1439 granted_lock = ldlm_handle2lock(child_lockh);
1441 LASSERTF(granted_lock != NULL, LPU64"/%lu lockh "LPX64"\n",
1442 id_fid(&body->id1), (unsigned long)id_group(&body->id1),
1443 child_lockh->cookie);
1446 /* usual named request */
1447 dparent = mds_id2dentry(obd, &body->id1, NULL);
1448 LASSERT(!IS_ERR(dparent));
1449 dchild = ll_lookup_one_len(name, dparent, namesize - 1);
1450 LASSERT(!IS_ERR(dchild));
1452 /* client wants to get attr. by id */
1453 dchild = mds_id2dentry(obd, &body->id1, NULL);
1454 LASSERT(!IS_ERR(dchild));
1456 LDLM_LOCK_PUT(granted_lock);
1459 cleanup_phase = 2; /* dchild, dparent, locks */
1461 if (!DENTRY_VALID(dchild)) {
1462 intent_set_disposition(rep, DISP_LOOKUP_NEG);
1464 * in the intent case, the policy clears this error: the
1465 * disposition is enough.
1470 intent_set_disposition(rep, DISP_LOOKUP_POS);
1473 if (req->rq_repmsg == NULL) {
1474 if (dchild->d_flags & DCACHE_CROSS_REF)
1475 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
1477 rc = mds_getattr_pack_msg(req, dchild, offset);
1479 CERROR ("mds_getattr_pack_msg: %d\n", rc);
1484 rc = mds_getattr_internal(obd, dchild, req, offset, body, reply_offset);
1485 GOTO(cleanup, rc); /* returns the lock to the client */
1488 switch (cleanup_phase) {
1490 if (resent_req == 0) {
1491 if (rc && DENTRY_VALID(dchild))
1492 ldlm_lock_decref(child_lockh, LCK_PR);
1494 ldlm_lock_decref(parent_lockh, LCK_PR);
1496 if (parent_lockh[1].cookie != 0)
1497 ldlm_lock_decref(parent_lockh + 1, update_mode);
1504 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1506 mds_exit_ucred(&uc);
1511 static int mds_getattr(struct ptlrpc_request *req, int offset)
1513 struct obd_device *obd = req->rq_export->exp_obd;
1514 struct lvfs_run_ctxt saved;
1516 struct mds_req_sec_desc *rsd;
1517 struct mds_body *body;
1518 struct lvfs_ucred uc = {NULL, NULL,};
1522 MD_COUNTER_INCREMENT(obd, getattr);
1524 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1526 CERROR("Can't unpack security desc\n");
1530 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1531 lustre_swab_mds_body);
1533 CERROR ("Can't unpack body\n");
1537 rc = mds_init_ucred(&uc, req, rsd);
1539 mds_exit_ucred(&uc);
1543 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1544 de = mds_id2dentry(obd, &body->id1, NULL);
1546 rc = req->rq_status = PTR_ERR(de);
1550 rc = mds_getattr_pack_msg(req, de, offset);
1552 CERROR("mds_getattr_pack_msg: %d\n", rc);
1556 req->rq_status = mds_getattr_internal(obd, de, req, offset, body, 0);
1561 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1562 mds_exit_ucred(&uc);
1566 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1567 unsigned long max_age)
1572 spin_lock(&obd->obd_osfs_lock);
1573 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
1575 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1576 spin_unlock(&obd->obd_osfs_lock);
1581 static int mds_statfs(struct ptlrpc_request *req)
1583 struct obd_device *obd = req->rq_export->exp_obd;
1584 int rc, size = sizeof(struct obd_statfs);
1587 /* This will trigger a watchdog timeout */
1588 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1589 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1591 rc = lustre_pack_reply(req, 1, &size, NULL);
1592 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1593 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1597 OBD_COUNTER_INCREMENT(obd, statfs);
1599 /* We call this so that we can cache a bit - 1 jiffie worth */
1600 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
1603 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1609 req->rq_status = rc;
1613 static int mds_sync(struct ptlrpc_request *req, int offset)
1615 struct obd_device *obd = req->rq_export->exp_obd;
1616 struct mds_obd *mds = &obd->u.mds;
1617 struct mds_body *body;
1618 int rc, size = sizeof(*body);
1621 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1622 lustre_swab_mds_body);
1624 GOTO(out, rc = -EPROTO);
1626 rc = lustre_pack_reply(req, 1, &size, NULL);
1627 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1628 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1632 if (id_ino(&body->id1) == 0) {
1633 /* an id of zero is taken to mean "sync whole filesystem" */
1634 rc = fsfilt_sync(obd, mds->mds_sb);
1638 /* just any file to grab fsync method - "file" arg unused */
1639 struct file *file = mds->mds_rcvd_filp;
1640 struct mds_body *rep_body;
1643 de = mds_id2dentry(obd, &body->id1, NULL);
1645 GOTO(out, rc = PTR_ERR(de));
1647 rc = file->f_op->fsync(NULL, de, 1);
1651 rep_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_body));
1652 mds_pack_inode2body(obd, rep_body, de->d_inode,
1653 (body->valid & OBD_MD_FID) ? 1 : 0);
1659 req->rq_status = rc;
1663 /* mds_readpage does not take a DLM lock on the inode, because the client must
1664 * already have a PR lock.
1666 * If we were to take another one here, a deadlock will result, if another
1667 * thread is already waiting for a PW lock. */
1668 static int mds_readpage(struct ptlrpc_request *req, int offset)
1670 struct obd_device *obd = req->rq_export->exp_obd;
1671 struct vfsmount *mnt;
1674 struct mds_req_sec_desc *rsd;
1675 struct mds_body *body, *repbody;
1676 struct lvfs_run_ctxt saved;
1677 int rc, size = sizeof(*repbody);
1678 struct lvfs_ucred uc = {NULL, NULL,};
1681 rc = lustre_pack_reply(req, 1, &size, NULL);
1682 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1683 CERROR("mds: out of memory\n");
1684 GOTO(out, rc = -ENOMEM);
1687 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1689 CERROR("Can't unpack security desc\n");
1690 GOTO (out, rc = -EFAULT);
1693 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1694 lustre_swab_mds_body);
1696 CERROR("Can't unpack body\n");
1697 GOTO (out, rc = -EFAULT);
1700 rc = mds_init_ucred(&uc, req, rsd);
1705 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1706 de = mds_id2dentry(obd, &body->id1, &mnt);
1708 GOTO(out_pop, rc = PTR_ERR(de));
1710 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1712 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1713 /* note: in case of an error, dentry_open puts dentry */
1715 GOTO(out_pop, rc = PTR_ERR(file));
1717 /* body->size is actually the offset -eeb */
1718 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1719 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1720 body->size, de->d_inode->i_blksize);
1721 GOTO(out_file, rc = -EFAULT);
1724 /* body->nlink is actually the #bytes to read -eeb */
1725 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1726 CERROR("size %u is not multiple of blocksize %lu\n",
1727 body->nlink, de->d_inode->i_blksize);
1728 GOTO(out_file, rc = -EFAULT);
1731 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
1732 repbody->size = file->f_dentry->d_inode->i_size;
1733 repbody->valid = OBD_MD_FLSIZE;
1735 /* to make this asynchronous make sure that the handling function
1736 doesn't send a reply when this function completes. Instead a
1737 callback function would send the reply */
1738 /* body->size is actually the offset -eeb */
1739 rc = mds_sendpage(req, file, body->size, body->nlink);
1743 filp_close(file, 0);
1745 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1747 mds_exit_ucred(&uc);
1748 req->rq_status = rc;
1752 /* update master MDS ID, which is stored in local inode EA. */
1753 int mds_update_mid(struct obd_device *obd, struct lustre_id *id,
1754 void *data, int data_len)
1756 struct mds_obd *mds = &obd->u.mds;
1757 struct dentry *dentry;
1765 dentry = mds_id2dentry(obd, id, NULL);
1767 GOTO(out, rc = PTR_ERR(dentry));
1769 if (!dentry->d_inode) {
1770 CERROR("Can't find object "DLID4".\n",
1772 GOTO(out_dentry, rc = -EINVAL);
1775 handle = fsfilt_start(obd, dentry->d_inode,
1776 FSFILT_OP_SETATTR, NULL);
1778 GOTO(out_dentry, rc = PTR_ERR(handle));
1780 rc = mds_update_inode_mid(obd, dentry->d_inode, handle,
1781 (struct lustre_id *)data);
1783 CERROR("Can't update inode "DLID4" master id, "
1784 "error = %d.\n", OLID4(id), rc);
1785 GOTO(out_commit, rc);
1790 fsfilt_commit(obd, mds->mds_sb, dentry->d_inode,
1797 EXPORT_SYMBOL(mds_update_mid);
1799 /* read master MDS ID, which is stored in local inode EA. */
1800 int mds_read_mid(struct obd_device *obd, struct lustre_id *id,
1801 void *data, int data_len)
1803 struct dentry *dentry;
1810 dentry = mds_id2dentry(obd, id, NULL);
1812 GOTO(out, rc = PTR_ERR(dentry));
1814 if (!dentry->d_inode) {
1815 CERROR("Can't find object "DLID4".\n",
1817 GOTO(out_dentry, rc = -EINVAL);
1820 down(&dentry->d_inode->i_sem);
1821 rc = mds_read_inode_mid(obd, dentry->d_inode,
1822 (struct lustre_id *)data);
1823 up(&dentry->d_inode->i_sem);
1825 CERROR("Can't read inode "DLID4" master id, "
1826 "error = %d.\n", OLID4(id), rc);
1827 GOTO(out_dentry, rc);
1836 EXPORT_SYMBOL(mds_read_mid);
1838 int mds_reint(struct ptlrpc_request *req, int offset,
1839 struct lustre_handle *lockh)
1841 struct mds_update_record *rec;
1842 struct mds_req_sec_desc *rsd;
1846 OBD_ALLOC(rec, sizeof(*rec));
1850 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1852 CERROR("Can't unpack security desc\n");
1853 GOTO(out, rc = -EFAULT);
1856 rc = mds_update_unpack(req, offset, rec);
1857 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1858 CERROR("invalid record\n");
1859 GOTO(out, req->rq_status = -EINVAL);
1862 rc = mds_init_ucred(&rec->ur_uc, req, rsd);
1867 /* rc will be used to interrupt a for loop over multiple records */
1868 rc = mds_reint_rec(rec, offset, req, lockh);
1871 mds_exit_ucred(&rec->ur_uc);
1872 OBD_FREE(rec, sizeof(*rec));
1876 static int mds_filter_recovery_request(struct ptlrpc_request *req,
1877 struct obd_device *obd, int *process)
1879 switch (req->rq_reqmsg->opc) {
1880 case MDS_CONNECT: /* This will never get here, but for completeness. */
1881 case OST_CONNECT: /* This will never get here, but for completeness. */
1882 case MDS_DISCONNECT:
1883 case OST_DISCONNECT:
1888 case MDS_SYNC: /* used in unmounting */
1893 *process = target_queue_recovery_request(req, obd);
1897 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1899 /* XXX what should we set rq_status to here? */
1900 req->rq_status = -EAGAIN;
1901 RETURN(ptlrpc_error(req));
1905 static char *reint_names[] = {
1906 [REINT_SETATTR] "setattr",
1907 [REINT_CREATE] "create",
1908 [REINT_LINK] "link",
1909 [REINT_UNLINK] "unlink",
1910 [REINT_RENAME] "rename",
1911 [REINT_OPEN] "open",
1914 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER | \
1915 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ| \
1916 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME| \
1919 static void reconstruct_create(struct ptlrpc_request *req)
1921 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1922 struct mds_client_data *mcd = med->med_mcd;
1923 struct dentry *dentry;
1924 struct ost_body *body;
1925 struct lustre_id id;
1929 /* copy rc, transno and disp; steal locks */
1930 mds_req_from_mcd(req, mcd);
1931 if (req->rq_status) {
1939 id_ino(&id) = mcd->mcd_last_data;
1940 LASSERT(id_ino(&id) != 0);
1942 dentry = mds_id2dentry(req2obd(req), &id, NULL);
1943 if (IS_ERR(dentry)) {
1944 CERROR("can't find inode "LPU64"\n", id_ino(&id));
1945 req->rq_status = PTR_ERR(dentry);
1950 CWARN("reconstruct reply for x"LPU64" (remote ino) "LPU64" -> %lu/%u\n",
1951 req->rq_xid, id_ino(&id), dentry->d_inode->i_ino,
1952 dentry->d_inode->i_generation);
1954 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
1955 obdo_from_inode(&body->oa, dentry->d_inode, FILTER_VALID_FLAGS);
1956 body->oa.o_id = dentry->d_inode->i_ino;
1957 body->oa.o_generation = dentry->d_inode->i_generation;
1958 body->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
1960 down(&dentry->d_inode->i_sem);
1961 rc = mds_read_inode_sid(req2obd(req), dentry->d_inode, &id);
1962 up(&dentry->d_inode->i_sem);
1964 CERROR("Can't read inode self id, inode %lu, "
1965 "rc %d\n", dentry->d_inode->i_ino, rc);
1969 body->oa.o_fid = id_fid(&id);
1970 body->oa.o_mds = id_group(&id);
1976 static int mdt_obj_create(struct ptlrpc_request *req)
1978 struct obd_device *obd = req->rq_export->exp_obd;
1979 struct mds_obd *mds = &obd->u.mds;
1980 struct ost_body *body, *repbody;
1981 char idname[LL_ID_NAMELEN];
1982 int size = sizeof(*repbody);
1983 struct inode *parent_inode;
1984 struct lvfs_run_ctxt saved;
1985 int rc, cleanup_phase = 0;
1986 struct dentry *new = NULL;
1987 struct dentry_params dp;
1988 int mealen, flags = 0;
1989 struct lvfs_ucred uc;
1990 struct lustre_id id;
1992 void *handle = NULL;
1993 unsigned long cr_inum = 0;
1996 DEBUG_REQ(D_HA, req, "create remote object");
1997 parent_inode = mds->mds_unnamed_dir->d_inode;
1999 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
2000 lustre_swab_ost_body);
2004 rc = lustre_pack_reply(req, 1, &size, NULL);
2008 MDS_CHECK_RESENT(req, reconstruct_create(req));
2011 uc.luc_ginfo = NULL;
2012 uc.luc_uid = body->oa.o_uid;
2013 uc.luc_gid = body->oa.o_gid;
2014 uc.luc_fsuid = body->oa.o_uid;
2015 uc.luc_fsgid = body->oa.o_gid;
2017 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2018 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
2020 /* in REPLAY case inum should be given (client or other MDS fills it) */
2021 if (body->oa.o_id && ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2022 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY))) {
2024 * this is re-create request from MDS holding directory name.
2025 * we have to lookup given ino/gen first. if it exists (good
2026 * case) then there is nothing to do. if it does not then we
2027 * have to recreate it.
2029 id_ino(&id) = body->oa.o_id;
2030 id_gen(&id) = body->oa.o_generation;
2032 new = mds_id2dentry(obd, &id, NULL);
2033 if (!IS_ERR(new) && new->d_inode) {
2034 struct lustre_id sid;
2036 CWARN("mkdir() repairing is on its way: %lu/%lu\n",
2037 (unsigned long)id_ino(&id), (unsigned long)id_gen(&id));
2039 obdo_from_inode(&repbody->oa, new->d_inode,
2040 FILTER_VALID_FLAGS);
2042 repbody->oa.o_id = new->d_inode->i_ino;
2043 repbody->oa.o_generation = new->d_inode->i_generation;
2044 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2047 down(&new->d_inode->i_sem);
2048 rc = mds_read_inode_sid(obd, new->d_inode, &sid);
2049 up(&new->d_inode->i_sem);
2051 CERROR("Can't read inode self id "
2052 "inode %lu, rc %d.\n",
2053 new->d_inode->i_ino, rc);
2057 repbody->oa.o_fid = id_fid(&sid);
2058 repbody->oa.o_mds = id_group(&sid);
2059 LASSERT(id_fid(&sid) != 0);
2062 * here we could use fid passed in body->oa.o_fid and
2063 * thus avoid mds_read_inode_sid().
2065 cr_inum = new->d_inode->i_ino;
2066 GOTO(cleanup, rc = 0);
2070 down(&parent_inode->i_sem);
2071 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
2072 if (IS_ERR(handle)) {
2073 up(&parent_inode->i_sem);
2074 CERROR("fsfilt_start() failed, rc = %d\n",
2075 (int)PTR_ERR(handle));
2076 GOTO(cleanup, rc = PTR_ERR(handle));
2078 cleanup_phase = 1; /* transaction */
2081 rc = sprintf(idname, "%u.%u", ll_insecure_random_int(), current->pid);
2082 new = lookup_one_len(idname, mds->mds_unnamed_dir, rc);
2084 CERROR("%s: can't lookup new inode (%s) for mkdir: %d\n",
2085 obd->obd_name, idname, (int) PTR_ERR(new));
2086 fsfilt_commit(obd, mds->mds_sb, new->d_inode, handle, 0);
2087 up(&parent_inode->i_sem);
2088 RETURN(PTR_ERR(new));
2089 } else if (new->d_inode) {
2090 CERROR("%s: name exists. repeat\n", obd->obd_name);
2094 new->d_fsdata = (void *)&dp;
2098 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) ||
2099 (body->oa.o_flags & OBD_FL_RECREATE_OBJS)) {
2100 LASSERT(body->oa.o_id != 0);
2101 dp.p_inum = body->oa.o_id;
2102 DEBUG_REQ(D_HA, req, "replay create obj %lu/%lu",
2103 (unsigned long)body->oa.o_id,
2104 (unsigned long)body->oa.o_generation);
2107 rc = vfs_mkdir(parent_inode, new, body->oa.o_mode);
2109 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2110 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2111 new->d_inode->i_generation = body->oa.o_generation;
2112 mark_inode_dirty(new->d_inode);
2115 * avoiding asserts in cache flush case, as
2116 * @body->oa.o_id should be zero.
2118 if (body->oa.o_id) {
2119 LASSERTF(body->oa.o_id == new->d_inode->i_ino,
2120 "BUG 3550: failed to recreate obj "
2121 LPU64" -> %lu\n", body->oa.o_id,
2122 new->d_inode->i_ino);
2124 LASSERTF(body->oa.o_generation ==
2125 new->d_inode->i_generation,
2126 "BUG 3550: failed to recreate obj/gen "
2127 LPU64"/%u -> %lu/%u\n", body->oa.o_id,
2128 body->oa.o_generation,
2129 new->d_inode->i_ino,
2130 new->d_inode->i_generation);
2134 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
2135 repbody->oa.o_id = new->d_inode->i_ino;
2136 repbody->oa.o_generation = new->d_inode->i_generation;
2137 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FID;
2139 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2140 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2141 id_group(&id) = mds->mds_num;
2143 LASSERT(body->oa.o_fid != 0);
2144 id_fid(&id) = body->oa.o_fid;
2146 LASSERT(body->oa.o_id != 0);
2147 id_ino(&id) = repbody->oa.o_id;
2148 id_gen(&id) = repbody->oa.o_generation;
2150 down(&new->d_inode->i_sem);
2151 rc = mds_update_inode_sid(obd, new->d_inode, handle, &id);
2152 up(&new->d_inode->i_sem);
2155 * make sure, that fid is up-to-date.
2157 mds_set_last_fid(obd, id_fid(&id));
2160 * allocate new sid, as object is created from scratch
2161 * and this is not replay.
2163 down(&new->d_inode->i_sem);
2164 rc = mds_alloc_inode_sid(obd, new->d_inode, handle, &id);
2165 up(&new->d_inode->i_sem);
2168 CERROR("Can't update lustre ID for inode %lu, "
2169 "error = %d\n", new->d_inode->i_ino, rc);
2173 /* initializing o_fid after it is allocated. */
2174 repbody->oa.o_fid = id_fid(&id);
2175 repbody->oa.o_mds = id_group(&id);
2177 rc = fsfilt_del_dir_entry(obd, new);
2178 up(&parent_inode->i_sem);
2180 CERROR("can't remove name for object: %d\n", rc);
2184 cleanup_phase = 2; /* created directory object */
2186 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
2187 (unsigned long)new->d_inode->i_ino,
2188 (unsigned long)new->d_inode->i_generation,
2189 (unsigned)new->d_inode->i_mode);
2190 cr_inum = new->d_inode->i_ino;
2192 up(&parent_inode->i_sem);
2193 CERROR("%s: can't create dirobj: %d\n", obd->obd_name, rc);
2197 if (body->oa.o_valid & OBD_MD_FLID) {
2198 /* this is new object for splitted dir. We have to prevent
2199 * recursive splitting on it -bzzz */
2200 mealen = obd_size_diskmd(mds->mds_md_exp, NULL);
2202 OBD_ALLOC(mea, mealen);
2204 GOTO(cleanup, rc = -ENOMEM);
2206 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2207 mea->mea_master = 0;
2210 down(&new->d_inode->i_sem);
2211 rc = fsfilt_set_md(obd, new->d_inode, handle,
2212 mea, mealen, EA_MEA);
2213 up(&new->d_inode->i_sem);
2215 CERROR("fsfilt_set_md() failed, "
2218 OBD_FREE(mea, mealen);
2220 CDEBUG(D_OTHER, "%s: mark non-splittable %lu/%u - %d\n",
2221 obd->obd_name, new->d_inode->i_ino,
2222 new->d_inode->i_generation, flags);
2223 } else if (body->oa.o_easize) {
2224 /* we pass LCK_EX to split routine to signal that we have
2225 * exclusive access to the directory. simple because nobody
2226 * knows it already exists -bzzz */
2227 rc = mds_try_to_split_dir(obd, new, NULL,
2228 body->oa.o_easize, LCK_EX);
2230 CERROR("Can't split directory %lu, error = %d.\n",
2231 new->d_inode->i_ino, rc);
2239 switch (cleanup_phase) {
2240 case 2: /* object has been created, but we'll may want to replay it later */
2242 ptlrpc_require_repack(req);
2243 case 1: /* transaction */
2244 rc = mds_finish_transno(mds, parent_inode, handle,
2249 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2253 static int mdt_get_info(struct ptlrpc_request *req)
2255 struct obd_export *exp = req->rq_export;
2260 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2262 DEBUG_REQ(D_HA, req, "no get_info key");
2265 keylen = req->rq_reqmsg->buflens[0];
2267 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
2268 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
2269 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0))
2272 if (keylen >= strlen("rootid") && !strcmp(key, "rootid")) {
2273 struct lustre_id *reply;
2274 int size = sizeof(*reply);
2276 rc = lustre_pack_reply(req, 1, &size, NULL);
2280 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2281 rc = obd_get_info(exp, keylen, key, &size, reply);
2284 int size = sizeof(*reply);
2286 rc = lustre_pack_reply(req, 1, &size, NULL);
2290 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2291 rc = obd_get_info(exp, keylen, key, &size, reply);
2294 req->rq_repmsg->status = 0;
2298 static int mds_set_info(struct obd_export *exp, __u32 keylen,
2299 void *key, __u32 vallen, void *val)
2301 struct obd_device *obd;
2302 struct mds_obd *mds;
2306 obd = class_exp2obd(exp);
2308 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2309 exp->exp_handle.h_cookie);
2314 if (keylen >= strlen("mds_type") &&
2315 memcmp(key, "mds_type", keylen) == 0) {
2319 CDEBUG(D_IOCTL, "set mds type to %x\n", *(int*)val);
2321 mds->mds_obd_type = *(int*)val;
2322 group = FILTER_GROUP_FIRST_MDS + mds->mds_obd_type;
2323 valsize = sizeof(group);
2325 /* mds number has been changed, so the corresponding obdfilter
2326 * exp need to be changed too. */
2327 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
2328 "mds_conn", valsize, &group);
2331 CDEBUG(D_IOCTL, "invalid key\n");
2335 static int mdt_set_info(struct ptlrpc_request *req)
2338 struct obd_export *exp = req->rq_export;
2339 int keylen, rc = 0, vallen;
2342 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2344 DEBUG_REQ(D_HA, req, "no set_info key");
2347 keylen = req->rq_reqmsg->buflens[0];
2349 if (keylen == strlen("mds_type") &&
2350 memcmp(key, "mds_type", keylen) == 0) {
2351 rc = lustre_pack_reply(req, 0, NULL, NULL);
2355 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2356 vallen = req->rq_reqmsg->buflens[1];
2358 rc = obd_set_info(exp, keylen, key, vallen, val);
2359 req->rq_repmsg->status = 0;
2362 CDEBUG(D_IOCTL, "invalid key\n");
2366 static void mds_revoke_export_locks(struct obd_export *exp)
2368 struct ldlm_namespace *ns = exp->exp_obd->obd_namespace;
2369 struct list_head *locklist = &exp->exp_ldlm_data.led_held_locks;
2370 struct ldlm_lock *lock, *next;
2371 struct ldlm_lock_desc desc;
2373 if (!exp->u.eu_mds_data.med_remote)
2377 l_lock(&ns->ns_lock);
2378 list_for_each_entry_safe(lock, next, locklist, l_export_chain) {
2379 if (lock->l_req_mode != lock->l_granted_mode)
2382 LASSERT(lock->l_resource);
2383 if (lock->l_resource->lr_type != LDLM_IBITS &&
2384 lock->l_resource->lr_type != LDLM_PLAIN)
2387 if (lock->l_flags & LDLM_FL_AST_SENT)
2390 lock->l_flags |= LDLM_FL_AST_SENT;
2392 /* the desc just pretend to exclusive */
2393 ldlm_lock2desc(lock, &desc);
2394 desc.l_req_mode = LCK_EX;
2395 desc.l_granted_mode = 0;
2397 lock->l_blocking_ast(lock, &desc, NULL, LDLM_CB_BLOCKING);
2399 l_unlock(&ns->ns_lock);
2403 static int mds_msg_check_version(struct lustre_msg *msg)
2409 case MDS_DISCONNECT:
2411 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2413 CERROR("bad opc %u version %08x, expecting %08x\n",
2414 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2419 case MDS_GETATTR_LOCK:
2423 case MDS_DONE_WRITING:
2426 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2428 CERROR("bad opc %u version %08x, expecting %08x\n",
2429 msg->opc, msg->version, LUSTRE_MDS_VERSION);
2433 case LDLM_BL_CALLBACK:
2434 case LDLM_CP_CALLBACK:
2435 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2437 CERROR("bad opc %u version %08x, expecting %08x\n",
2438 msg->opc, msg->version, LUSTRE_DLM_VERSION);
2440 case OBD_LOG_CANCEL:
2441 case LLOG_ORIGIN_HANDLE_OPEN:
2442 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2443 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2444 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2445 case LLOG_ORIGIN_HANDLE_CLOSE:
2447 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2449 CERROR("bad opc %u version %08x, expecting %08x\n",
2450 msg->opc, msg->version, LUSTRE_LOG_VERSION);
2456 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2458 CERROR("bad opc %u version %08x, expecting %08x\n",
2459 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2462 case SEC_INIT_CONTINUE:
2467 CERROR("MDS unknown opcode %d\n", msg->opc);
2475 int mds_handle(struct ptlrpc_request *req)
2477 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
2478 struct obd_device *obd = NULL;
2479 struct mds_obd *mds = NULL; /* quell gcc overwarning */
2483 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2485 rc = mds_msg_check_version(req->rq_reqmsg);
2487 CERROR("MDS drop mal-formed request\n");
2491 /* Security opc should NOT trigger any recovery events */
2492 if (req->rq_reqmsg->opc == SEC_INIT ||
2493 req->rq_reqmsg->opc == SEC_INIT_CONTINUE) {
2494 if (!req->rq_export)
2497 mds_req_add_idmapping(req, &req->rq_export->exp_mds_data);
2498 mds_revoke_export_locks(req->rq_export);
2500 } else if (req->rq_reqmsg->opc == SEC_FINI) {
2501 if (!req->rq_export)
2504 mds_req_del_idmapping(req, &req->rq_export->exp_mds_data);
2505 mds_revoke_export_locks(req->rq_export);
2509 LASSERT(current->journal_info == NULL);
2510 /* XXX identical to OST */
2511 if (req->rq_reqmsg->opc != MDS_CONNECT) {
2512 struct mds_export_data *med;
2515 if (req->rq_export == NULL) {
2516 CERROR("operation %d on unconnected MDS from %s\n",
2517 req->rq_reqmsg->opc,
2519 req->rq_status = -ENOTCONN;
2520 GOTO(out, rc = -ENOTCONN);
2523 med = &req->rq_export->exp_mds_data;
2524 obd = req->rq_export->exp_obd;
2527 /* sanity check: if the xid matches, the request must
2528 * be marked as a resent or replayed */
2529 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
2530 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid)) {
2531 LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
2532 (MSG_RESENT | MSG_REPLAY),
2533 "rq_xid "LPU64" matches last_xid, "
2534 "expected RESENT flag\n",
2537 /* else: note the opposite is not always true; a
2538 * RESENT req after a failover will usually not match
2539 * the last_xid, since it was likely never
2540 * committed. A REPLAYed request will almost never
2541 * match the last xid, however it could for a
2542 * committed, but still retained, open. */
2544 spin_lock_bh(&obd->obd_processing_task_lock);
2545 recovering = obd->obd_recovering;
2546 spin_unlock_bh(&obd->obd_processing_task_lock);
2548 rc = mds_filter_recovery_request(req, obd,
2550 if (rc || should_process == 0) {
2552 } else if (should_process < 0) {
2553 req->rq_status = should_process;
2554 rc = ptlrpc_error(req);
2560 switch (req->rq_reqmsg->opc) {
2562 DEBUG_REQ(D_INODE, req, "connect");
2563 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
2564 rc = target_handle_connect(req);
2566 struct mds_export_data *med;
2568 LASSERT(req->rq_export);
2569 med = &req->rq_export->u.eu_mds_data;
2570 mds_init_export_data(req, med);
2571 mds_req_add_idmapping(req, med);
2573 /* Now that we have an export, set mds. */
2574 obd = req->rq_export->exp_obd;
2575 mds = mds_req2mds(req);
2579 case MDS_DISCONNECT:
2580 DEBUG_REQ(D_INODE, req, "disconnect");
2581 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
2582 rc = target_handle_disconnect(req);
2583 req->rq_status = rc; /* superfluous? */
2587 DEBUG_REQ(D_INODE, req, "getstatus");
2588 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
2589 rc = mds_getstatus(req);
2593 DEBUG_REQ(D_INODE, req, "getattr");
2594 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
2595 rc = mds_getattr(req, MDS_REQ_REC_OFF);
2598 case MDS_GETATTR_LOCK: {
2599 struct lustre_handle lockh;
2600 DEBUG_REQ(D_INODE, req, "getattr_lock");
2601 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_LOCK_NET, 0);
2603 /* If this request gets a reconstructed reply, we won't be
2604 * acquiring any new locks in mds_getattr_lock, so we don't
2608 rc = mds_getattr_lock(req, MDS_REQ_REC_OFF, &lockh,
2609 MDS_INODELOCK_UPDATE);
2610 /* this non-intent call (from an ioctl) is special */
2611 req->rq_status = rc;
2612 if (rc == 0 && lockh.cookie)
2613 ldlm_lock_decref(&lockh, LCK_PR);
2617 DEBUG_REQ(D_INODE, req, "statfs");
2618 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
2619 rc = mds_statfs(req);
2623 DEBUG_REQ(D_INODE, req, "readpage");
2624 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
2625 rc = mds_readpage(req, MDS_REQ_REC_OFF);
2627 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
2628 if (req->rq_reply_state) {
2629 lustre_free_reply_state (req->rq_reply_state);
2630 req->rq_reply_state = NULL;
2637 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
2640 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
2641 mds->mds_max_cookiesize};
2644 /* NB only peek inside req now; mds_reint() will swab it */
2646 CERROR ("Can't inspect opcode\n");
2651 if (lustre_msg_swabbed (req->rq_reqmsg))
2654 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
2655 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
2656 reint_names[opc] == NULL) ? reint_names[opc] :
2659 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
2661 if (opc == REINT_UNLINK || opc == REINT_RENAME)
2663 else if (opc == REINT_OPEN)
2668 rc = lustre_pack_reply(req, bufcount, size, NULL);
2672 rc = mds_reint(req, MDS_REQ_REC_OFF, NULL);
2673 fail = OBD_FAIL_MDS_REINT_NET_REP;
2678 DEBUG_REQ(D_INODE, req, "close");
2679 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
2680 rc = mds_close(req, MDS_REQ_REC_OFF);
2683 case MDS_DONE_WRITING:
2684 DEBUG_REQ(D_INODE, req, "done_writing");
2685 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
2686 rc = mds_done_writing(req, MDS_REQ_REC_OFF);
2690 DEBUG_REQ(D_INODE, req, "pin");
2691 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
2692 rc = mds_pin(req, MDS_REQ_REC_OFF);
2696 DEBUG_REQ(D_INODE, req, "sync");
2697 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
2698 rc = mds_sync(req, MDS_REQ_REC_OFF);
2702 DEBUG_REQ(D_INODE, req, "ping");
2703 rc = target_handle_ping(req);
2706 case OBD_LOG_CANCEL:
2707 CDEBUG(D_INODE, "log cancel\n");
2708 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
2709 rc = -ENOTSUPP; /* la la la */
2713 DEBUG_REQ(D_INODE, req, "enqueue");
2714 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
2715 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
2716 ldlm_server_blocking_ast, NULL);
2717 fail = OBD_FAIL_LDLM_REPLY;
2720 DEBUG_REQ(D_INODE, req, "convert");
2721 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
2722 rc = ldlm_handle_convert(req);
2724 case LDLM_BL_CALLBACK:
2725 case LDLM_CP_CALLBACK:
2726 DEBUG_REQ(D_INODE, req, "callback");
2727 CERROR("callbacks should not happen on MDS\n");
2729 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
2731 case LLOG_ORIGIN_HANDLE_OPEN:
2732 DEBUG_REQ(D_INODE, req, "llog_init");
2733 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2734 rc = llog_origin_handle_open(req);
2736 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2737 DEBUG_REQ(D_INODE, req, "llog next block");
2738 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2739 rc = llog_origin_handle_next_block(req);
2741 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2742 DEBUG_REQ(D_INODE, req, "llog prev block");
2743 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2744 rc = llog_origin_handle_prev_block(req);
2746 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2747 DEBUG_REQ(D_INODE, req, "llog read header");
2748 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2749 rc = llog_origin_handle_read_header(req);
2751 case LLOG_ORIGIN_HANDLE_CLOSE:
2752 DEBUG_REQ(D_INODE, req, "llog close");
2753 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2754 rc = llog_origin_handle_close(req);
2757 DEBUG_REQ(D_INODE, req, "ost_create");
2758 rc = mdt_obj_create(req);
2761 DEBUG_REQ(D_INODE, req, "get_info");
2762 rc = mdt_get_info(req);
2765 DEBUG_REQ(D_INODE, req, "set_info");
2766 rc = mdt_set_info(req);
2769 CDEBUG(D_INODE, "write\n");
2770 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
2771 rc = ost_brw_write(req, NULL);
2772 LASSERT(current->journal_info == NULL);
2773 /* mdt_brw sends its own replies */
2777 DEBUG_REQ(D_INODE, req, "llog catinfo");
2778 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
2779 rc = llog_catinfo(req);
2782 req->rq_status = -ENOTSUPP;
2783 rc = ptlrpc_error(req);
2787 LASSERT(current->journal_info == NULL);
2791 /* If we're DISCONNECTing, the mds_export_data is already freed */
2792 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
2793 struct mds_export_data *med = &req->rq_export->exp_mds_data;
2794 struct obd_device *obd = list_entry(mds, struct obd_device,
2796 req->rq_repmsg->last_xid =
2797 le64_to_cpu(med->med_mcd->mcd_last_xid);
2799 if (!obd->obd_no_transno) {
2800 req->rq_repmsg->last_committed =
2801 obd->obd_last_committed;
2803 DEBUG_REQ(D_IOCTL, req,
2804 "not sending last_committed update");
2806 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
2808 mds->mds_last_transno, obd->obd_last_committed,
2814 target_send_reply(req, rc, fail);
2818 /* Update the server data on disk. This stores the new mount_count and also the
2819 * last_rcvd value to disk. If we don't have a clean shutdown, then the server
2820 * last_rcvd value may be less than that of the clients. This will alert us
2821 * that we may need to do client recovery.
2823 * Also assumes for mds_last_transno that we are not modifying it (no locking).
2825 int mds_update_server_data(struct obd_device *obd, int force_sync)
2827 struct mds_obd *mds = &obd->u.mds;
2828 struct mds_server_data *msd = mds->mds_server_data;
2829 struct file *filp = mds->mds_rcvd_filp;
2830 struct lvfs_run_ctxt saved;
2835 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2836 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
2838 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
2839 mds->mds_mount_count, mds->mds_last_transno);
2840 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off, force_sync);
2842 CERROR("error writing MDS server data: rc = %d\n", rc);
2843 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2848 /* saves last allocated fid counter to file. */
2849 int mds_update_last_fid(struct obd_device *obd, void *handle,
2852 struct mds_obd *mds = &obd->u.mds;
2853 struct file *filp = mds->mds_fid_filp;
2854 struct lvfs_run_ctxt saved;
2860 spin_lock(&mds->mds_last_fid_lock);
2861 last_fid = mds->mds_last_fid;
2862 spin_unlock(&mds->mds_last_fid_lock);
2864 CDEBUG(D_SUPER, "MDS last_fid is #"LPU64"\n",
2868 fsfilt_add_journal_cb(obd, mds->mds_sb, last_fid,
2869 handle, mds_commit_last_fid_cb,
2873 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2874 rc = fsfilt_write_record(obd, filp, &last_fid, sizeof(last_fid),
2876 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2879 CERROR("error writing MDS last_fid #"LPU64
2880 ", err = %d\n", last_fid, rc);
2884 CDEBUG(D_SUPER, "wrote fid #"LPU64" at idx "
2885 "%llu: err = %d\n", last_fid, off, rc);
2890 void mds_set_last_fid(struct obd_device *obd, __u64 fid)
2892 struct mds_obd *mds = &obd->u.mds;
2894 spin_lock(&mds->mds_last_fid_lock);
2895 if (fid > mds->mds_last_fid)
2896 mds->mds_last_fid = fid;
2897 spin_unlock(&mds->mds_last_fid_lock);
2900 void mds_commit_last_transno_cb(struct obd_device *obd,
2901 __u64 transno, void *data,
2904 obd_transno_commit_cb(obd, transno, error);
2907 void mds_commit_last_fid_cb(struct obd_device *obd,
2908 __u64 fid, void *data,
2912 CERROR("%s: fid "LPD64" commit error: %d\n",
2913 obd->obd_name, fid, error);
2917 CDEBUG(D_HA, "%s: fid "LPD64" committed\n",
2918 obd->obd_name, fid);
2921 __u64 mds_alloc_fid(struct obd_device *obd)
2923 struct mds_obd *mds = &obd->u.mds;
2926 spin_lock(&mds->mds_last_fid_lock);
2927 fid = ++mds->mds_last_fid;
2928 spin_unlock(&mds->mds_last_fid_lock);
2934 * allocates new lustre_id on passed @inode and saves it to inode EA.
2936 int mds_alloc_inode_sid(struct obd_device *obd, struct inode *inode,
2937 void *handle, struct lustre_id *id)
2939 struct mds_obd *mds = &obd->u.mds;
2940 int alloc = 0, rc = 0;
2943 LASSERT(obd != NULL);
2944 LASSERT(inode != NULL);
2947 OBD_ALLOC(id, sizeof(*id));
2953 id_group(id) = mds->mds_num;
2954 id_fid(id) = mds_alloc_fid(obd);
2955 id_ino(id) = inode->i_ino;
2956 id_gen(id) = inode->i_generation;
2957 id_type(id) = (S_IFMT & inode->i_mode);
2959 rc = mds_update_inode_sid(obd, inode, handle, id);
2961 CERROR("Can't update inode FID EA, "
2966 OBD_FREE(id, sizeof(*id));
2971 * reads inode self id from inode EA. Probably later this should be replaced by
2972 * caching inode self id to avoid raeding it every time it is needed.
2974 int mds_read_inode_sid(struct obd_device *obd, struct inode *inode,
2975 struct lustre_id *id)
2980 LASSERT(id != NULL);
2981 LASSERT(obd != NULL);
2982 LASSERT(inode != NULL);
2984 rc = fsfilt_get_md(obd, inode, &id->li_fid,
2985 sizeof(id->li_fid), EA_SID);
2987 CERROR("fsfilt_get_md() failed, "
3000 /* updates inode self id in EA. */
3001 int mds_update_inode_sid(struct obd_device *obd, struct inode *inode,
3002 void *handle, struct lustre_id *id)
3007 LASSERT(id != NULL);
3008 LASSERT(obd != NULL);
3009 LASSERT(inode != NULL);
3011 rc = fsfilt_set_md(obd, inode, handle, &id->li_fid,
3012 sizeof(id->li_fid), EA_SID);
3014 CERROR("fsfilt_set_md() failed, rc = %d\n", rc);
3022 * reads inode id on master MDS. This is usualy done by CMOBD to update requests
3023 * to master MDS by correct store cookie, needed to find inode on master MDS
3026 int mds_read_inode_mid(struct obd_device *obd, struct inode *inode,
3027 struct lustre_id *id)
3032 LASSERT(id != NULL);
3033 LASSERT(obd != NULL);
3034 LASSERT(inode != NULL);
3036 rc = fsfilt_get_md(obd, inode, id, sizeof(*id), EA_MID);
3038 CERROR("fsfilt_get_md() failed, rc = %d\n", rc);
3051 * updates master inode id. Usualy this is done by CMOBD after an inode is
3052 * created and relationship between cache MDS and master one should be
3055 int mds_update_inode_mid(struct obd_device *obd, struct inode *inode,
3056 void *handle, struct lustre_id *id)
3061 LASSERT(id != NULL);
3062 LASSERT(obd != NULL);
3063 LASSERT(inode != NULL);
3065 rc = fsfilt_set_md(obd, inode, handle, id,
3066 sizeof(*id), EA_MID);
3068 CERROR("fsfilt_set_md() failed, "
3076 /* mount the file system (secretly) */
3077 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
3079 struct lustre_cfg* lcfg = buf;
3080 struct mds_obd *mds = &obd->u.mds;
3081 struct lvfs_obd_ctxt *lvfs_ctxt = NULL;
3082 char *options = NULL;
3083 struct vfsmount *mnt;
3090 if (!lcfg->lcfg_inlbuf1 || !lcfg->lcfg_inlbuf2)
3091 RETURN(rc = -EINVAL);
3093 obd->obd_fsops = fsfilt_get_ops(lcfg->lcfg_inlbuf2);
3094 if (IS_ERR(obd->obd_fsops))
3095 RETURN(rc = PTR_ERR(obd->obd_fsops));
3097 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
3099 page = __get_free_page(GFP_KERNEL);
3103 options = (char *)page;
3104 memset(options, 0, PAGE_SIZE);
3107 * here we use "iopen_nopriv" hardcoded, because it affects MDS utility
3108 * and the rest of options are passed by mount options. Probably this
3109 * should be moved to somewhere else like startup scripts or lconf. */
3110 sprintf(options, "iopen_nopriv");
3111 if (lcfg->lcfg_inllen4 > 0 && lcfg->lcfg_inlbuf4)
3112 sprintf(options + strlen(options), ",%s",
3113 lcfg->lcfg_inlbuf4);
3115 /* we have to know mdsnum before touching underlying fs -bzzz */
3116 atomic_set(&mds->mds_open_count, 0);
3117 sema_init(&mds->mds_md_sem, 1);
3118 mds->mds_md_connected = 0;
3119 mds->mds_md_name = NULL;
3121 if (lcfg->lcfg_inllen5 > 0 && lcfg->lcfg_inlbuf5 &&
3122 strncmp(lcfg->lcfg_inlbuf5, "dumb", lcfg->lcfg_inllen5)) {
3125 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
3126 obd->obd_name, lcfg->lcfg_inlbuf5);
3128 generate_random_uuid(uuid);
3129 class_uuid_unparse(uuid, &mds->mds_md_uuid);
3131 OBD_ALLOC(mds->mds_md_name, lcfg->lcfg_inllen5);
3132 if (mds->mds_md_name == NULL)
3133 RETURN(rc = -ENOMEM);
3135 memcpy(mds->mds_md_name, lcfg->lcfg_inlbuf5,
3136 lcfg->lcfg_inllen5);
3138 rc = mds_md_connect(obd, mds->mds_md_name);
3140 OBD_FREE(mds->mds_md_name, lcfg->lcfg_inllen5);
3145 mds->mds_obd_type = MDS_MASTER_OBD;
3147 if (lcfg->lcfg_inllen6 > 0 && lcfg->lcfg_inlbuf6 &&
3148 strncmp(lcfg->lcfg_inlbuf6, "dumb", lcfg->lcfg_inllen6)) {
3149 if (!memcmp(lcfg->lcfg_inlbuf6, "master", strlen("master"))) {
3150 mds->mds_obd_type = MDS_MASTER_OBD;
3151 } else if (!memcmp(lcfg->lcfg_inlbuf6, "cache", strlen("cache"))) {
3152 mds->mds_obd_type = MDS_CACHE_OBD;
3156 rc = lvfs_mount_fs(lcfg->lcfg_inlbuf1, lcfg->lcfg_inlbuf2,
3157 options, 0, &lvfs_ctxt);
3161 if (rc || !lvfs_ctxt) {
3162 CERROR("lvfs_mount_fs failed: rc = %d\n", rc);
3166 mnt = lvfs_ctxt->loc_mnt;
3167 mds->mds_lvfs_ctxt = lvfs_ctxt;
3168 ll_clear_rdonly(ll_sbdev(mnt->mnt_sb));
3170 CDEBUG(D_SUPER, "%s: mnt = %p\n", lcfg->lcfg_inlbuf1, mnt);
3172 sema_init(&mds->mds_epoch_sem, 1);
3173 atomic_set(&mds->mds_real_clients, 0);
3174 spin_lock_init(&mds->mds_transno_lock);
3175 spin_lock_init(&mds->mds_last_fid_lock);
3176 sema_init(&mds->mds_orphan_recovery_sem, 1);
3177 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
3179 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
3180 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
3182 if (obd->obd_namespace == NULL) {
3183 mds_cleanup(obd, 0);
3184 GOTO(err_put, rc = -ENOMEM);
3186 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
3188 rc = mds_fs_setup(obd, mnt);
3190 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
3195 rc = llog_start_commit_thread();
3199 if (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3200 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)) {
3203 generate_random_uuid(uuid);
3204 class_uuid_unparse(uuid, &mds->mds_dt_uuid);
3206 OBD_ALLOC(mds->mds_profile, lcfg->lcfg_inllen3);
3207 if (mds->mds_profile == NULL)
3208 GOTO(err_fs, rc = -ENOMEM);
3210 memcpy(mds->mds_profile, lcfg->lcfg_inlbuf3,
3211 lcfg->lcfg_inllen3);
3215 * setup root dir and files ID dir if lmv already connected, or there is
3218 if (mds->mds_md_exp || (lcfg->lcfg_inllen3 > 0 && lcfg->lcfg_inlbuf3 &&
3219 strncmp(lcfg->lcfg_inlbuf3, "dumb", lcfg->lcfg_inllen3)))
3221 rc = mds_fs_setup_rootid(obd);
3225 rc = mds_fs_setup_virtid(obd);
3230 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3231 "mds_ldlm_client", &obd->obd_ldlm_client);
3232 obd->obd_replayable = 1;
3234 rc = mds_postsetup(obd);
3241 /* No extra cleanup needed for llog_init_commit_thread() */
3242 mds_fs_cleanup(obd, 0);
3244 ldlm_namespace_free(obd->obd_namespace, 0);
3245 obd->obd_namespace = NULL;
3248 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3252 fsfilt_put_ops(obd->obd_fsops);
3256 static int mds_postsetup(struct obd_device *obd)
3258 struct mds_obd *mds = &obd->u.mds;
3262 rc = obd_llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
3263 obd, 0, NULL, &llog_lvfs_ops);
3267 if (mds->mds_profile) {
3268 struct llog_ctxt *lgctxt;
3269 struct lvfs_run_ctxt saved;
3270 struct lustre_profile *lprof;
3271 struct config_llog_instance cfg;
3273 cfg.cfg_instance = NULL;
3274 cfg.cfg_uuid = mds->mds_dt_uuid;
3275 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3277 lgctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
3279 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3280 GOTO(err_llog, rc = -EINVAL);
3283 rc = class_config_process_llog(lgctxt, mds->mds_profile, &cfg);
3284 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3289 lprof = class_get_profile(mds->mds_profile);
3290 if (lprof == NULL) {
3291 CERROR("No profile found: %s\n", mds->mds_profile);
3292 GOTO(err_cleanup, rc = -ENOENT);
3294 rc = mds_dt_connect(obd, lprof->lp_lov);
3296 GOTO(err_cleanup, rc);
3298 rc = mds_md_postsetup(obd);
3300 GOTO(err_cleanup, rc);
3307 obd_llog_cleanup(llog_get_context(&obd->obd_llogs,
3308 LLOG_CONFIG_ORIG_CTXT));
3312 int mds_postrecov_common(struct obd_device *obd)
3314 struct mds_obd *mds = &obd->u.mds;
3315 struct llog_ctxt *ctxt;
3316 int rc, item = 0, valsize;
3320 LASSERT(!obd->obd_recovering);
3321 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
3322 LASSERT(ctxt != NULL);
3324 /* set nextid first, so we are sure it happens */
3325 rc = mds_dt_set_nextid(obd);
3327 CERROR("%s: mds_dt_set_nextid() failed\n", obd->obd_name);
3331 /* clean PENDING dir */
3332 rc = mds_cleanup_orphans(obd);
3337 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
3338 valsize = sizeof(group);
3339 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"), "mds_conn",
3344 rc = llog_connect(ctxt, obd->u.mds.mds_dt_desc.ld_tgt_count,
3347 CERROR("%s: failed at llog_origin_connect: %d\n",
3352 /* remove the orphaned precreated objects */
3353 rc = mds_dt_clearorphans(mds, NULL /* all OSTs */);
3358 RETURN(rc < 0 ? rc : item);
3361 /* cleanup all llogging subsystems */
3362 rc = obd_llog_finish(obd, &obd->obd_llogs,
3363 mds->mds_dt_desc.ld_tgt_count);
3365 CERROR("%s: failed to cleanup llogging subsystems\n",
3370 int mds_postrecov(struct obd_device *obd)
3374 rc = mds_postrecov_common(obd);
3376 rc = mds_md_reconnect(obd);
3380 int mds_dt_clean(struct obd_device *obd)
3382 struct mds_obd *mds = &obd->u.mds;
3385 if (mds->mds_profile) {
3387 struct llog_ctxt *llctx;
3388 struct lvfs_run_ctxt saved;
3389 struct config_llog_instance cfg;
3390 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
3392 OBD_ALLOC(cln_prof, len);
3393 sprintf(cln_prof, "%s-clean", mds->mds_profile);
3395 cfg.cfg_instance = NULL;
3396 cfg.cfg_uuid = mds->mds_dt_uuid;
3398 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3399 llctx = llog_get_context(&obd->obd_llogs,
3400 LLOG_CONFIG_ORIG_CTXT);
3401 class_config_process_llog(llctx, cln_prof, &cfg);
3402 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3404 OBD_FREE(cln_prof, len);
3405 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
3406 mds->mds_profile = NULL;
3411 int mds_md_clean(struct obd_device *obd)
3413 struct mds_obd *mds = &obd->u.mds;
3416 if (mds->mds_md_name) {
3417 OBD_FREE(mds->mds_md_name, strlen(mds->mds_md_name) + 1);
3418 mds->mds_md_name = NULL;
3423 static int mds_precleanup(struct obd_device *obd, int flags)
3429 mds_dt_disconnect(obd, flags);
3431 obd_llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
3435 extern void lgss_svc_cache_purge_all(void);
3436 static int mds_cleanup(struct obd_device *obd, int flags)
3438 struct mds_obd *mds = &obd->u.mds;
3441 if (mds->mds_sb == NULL)
3444 mds_update_server_data(obd, 1);
3445 mds_update_last_fid(obd, NULL, 1);
3447 if (mds->mds_dt_objids != NULL) {
3448 int size = mds->mds_dt_desc.ld_tgt_count *
3450 OBD_FREE(mds->mds_dt_objids, size);
3452 mds_fs_cleanup(obd, flags);
3456 /* 2 seems normal on mds, (may_umount() also expects 2
3457 fwiw), but we only see 1 at this point in obdfilter. */
3458 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3462 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
3464 spin_lock_bh(&obd->obd_processing_task_lock);
3465 if (obd->obd_recovering) {
3466 target_cancel_recovery_timer(obd);
3467 obd->obd_recovering = 0;
3469 spin_unlock_bh(&obd->obd_processing_task_lock);
3472 fsfilt_put_ops(obd->obd_fsops);
3476 lgss_svc_cache_purge_all();
3481 static int set_security(const char *value, char **sec)
3485 if (!strcmp(value, "null"))
3487 else if (!strcmp(value, "krb5i"))
3489 else if (!strcmp(value, "krb5p"))
3492 CERROR("Unrecognized value, force use NULL\n");
3499 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
3501 struct lustre_cfg *lcfg = buf;
3502 struct mds_obd *mds = &obd->u.mds;
3506 switch(lcfg->lcfg_command) {
3507 case LCFG_SET_SECURITY: {
3508 if (!lcfg->lcfg_inllen1 || !lcfg->lcfg_inllen2)
3509 GOTO(out, rc = -EINVAL);
3511 if (!strcmp(lcfg->lcfg_inlbuf1, "mds_mds_sec"))
3512 rc = set_security(lcfg->lcfg_inlbuf2,
3514 else if (!strcmp(lcfg->lcfg_inlbuf1, "mds_ost_sec"))
3515 rc = set_security(lcfg->lcfg_inlbuf2,
3518 CERROR("Unrecognized key\n");
3524 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
3525 GOTO(out, rc = -EINVAL);
3533 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
3535 struct ldlm_lock *new_lock,
3536 struct ldlm_lock **old_lock,
3537 struct lustre_handle *lockh)
3539 struct obd_export *exp = req->rq_export;
3540 struct obd_device *obd = exp->exp_obd;
3541 struct ldlm_request *dlmreq =
3542 lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq));
3543 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
3544 struct list_head *iter;
3546 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
3549 l_lock(&obd->obd_namespace->ns_lock);
3550 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
3551 struct ldlm_lock *lock;
3552 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
3553 if (lock == new_lock)
3555 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
3556 lockh->cookie = lock->l_handle.h_cookie;
3557 LDLM_DEBUG(lock, "restoring lock cookie");
3558 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
3561 *old_lock = LDLM_LOCK_GET(lock);
3562 l_unlock(&obd->obd_namespace->ns_lock);
3566 l_unlock(&obd->obd_namespace->ns_lock);
3568 /* If the xid matches, then we know this is a resent request,
3569 * and allow it. (It's probably an OPEN, for which we don't
3572 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
3576 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
3579 /* This remote handle isn't enqueued, so we never received or
3580 * processed this request. Clear MSG_RESENT, because it can
3581 * be handled like any normal request now. */
3583 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
3585 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
3589 int intent_disposition(struct ldlm_reply *rep, int flag)
3593 return (rep->lock_policy_res1 & flag);
3596 void intent_set_disposition(struct ldlm_reply *rep, int flag)
3600 rep->lock_policy_res1 |= flag;
3603 static int mds_intent_policy(struct ldlm_namespace *ns,
3604 struct ldlm_lock **lockp, void *req_cookie,
3605 ldlm_mode_t mode, int flags, void *data)
3607 struct ptlrpc_request *req = req_cookie;
3608 struct ldlm_lock *lock = *lockp;
3609 struct ldlm_intent *it;
3610 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
3611 struct ldlm_reply *rep;
3612 struct lustre_handle lockh[2] = {{0}, {0}};
3613 struct ldlm_lock *new_lock = NULL;
3614 int getattr_part = MDS_INODELOCK_UPDATE;
3615 int rc, reply_buffers;
3616 int repsize[5] = {sizeof(struct ldlm_reply),
3617 sizeof(struct mds_body),
3618 mds->mds_max_mdsize};
3620 int offset = MDS_REQ_INTENT_REC_OFF;
3623 LASSERT(req != NULL);
3624 MD_COUNTER_INCREMENT(req->rq_export->exp_obd, intent_lock);
3626 if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) {
3627 /* No intent was provided */
3628 int size = sizeof(struct ldlm_reply);
3629 rc = lustre_pack_reply(req, 1, &size, NULL);
3634 it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it),
3635 lustre_swab_ldlm_intent);
3637 CERROR("Intent missing\n");
3638 RETURN(req->rq_status = -EFAULT);
3641 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
3644 if (it->opc & ( IT_OPEN | IT_GETATTR | IT_LOOKUP | IT_CHDIR )) {
3647 repsize[4] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
3650 rc = lustre_pack_reply(req, reply_buffers, repsize, NULL);
3652 RETURN(req->rq_status = rc);
3654 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
3655 LASSERT(rep != NULL);
3657 intent_set_disposition(rep, DISP_IT_EXECD);
3659 /* execute policy */
3660 switch ((long)it->opc) {
3662 case IT_CREAT|IT_OPEN:
3663 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3665 /* XXX swab here to assert that an mds_open reint
3666 * packet is following */
3667 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3669 rep->lock_policy_res2 = mds_reint(req, offset, lockh);
3671 if (rep->lock_policy_res2) {
3673 * mds_open() returns ENOLCK where it should return
3674 * zero, but it has no lock to return.
3676 if (rep->lock_policy_res2 == ENOLCK)
3677 rep->lock_policy_res2 = 0;
3679 RETURN(ELDLM_LOCK_ABORTED);
3683 * IT_OPEN may return lock on cross-node dentry that we want to
3684 * hold during attr retrival -bzzz
3686 if (lockh[0].cookie == 0)
3687 RETURN(ELDLM_LOCK_ABORTED);
3691 getattr_part = MDS_INODELOCK_LOOKUP;
3694 getattr_part |= MDS_INODELOCK_LOOKUP;
3696 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
3697 lock, &new_lock, lockh);
3698 rep->lock_policy_res2 = mds_getattr_lock(req, offset, lockh,
3700 /* FIXME: LDLM can set req->rq_status. MDS sets
3701 policy_res{1,2} with disposition and status.
3702 - replay: returns 0 & req->status is old status
3703 - otherwise: returns req->status */
3704 if (intent_disposition(rep, DISP_LOOKUP_NEG))
3705 rep->lock_policy_res2 = 0;
3706 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
3707 rep->lock_policy_res2)
3708 RETURN(ELDLM_LOCK_ABORTED);
3709 if (req->rq_status != 0) {
3711 rep->lock_policy_res2 = req->rq_status;
3712 RETURN(ELDLM_LOCK_ABORTED);
3716 rc = mds_lock_and_check_slave(offset, req, lockh);
3717 if ((rep->lock_policy_res2 = rc)) {
3719 rep->lock_policy_res2 = 0;
3720 RETURN(ELDLM_LOCK_ABORTED);
3724 CERROR("Unhandled intent "LPD64"\n", it->opc);
3728 /* By this point, whatever function we called above must have either
3729 * filled in 'lockh', been an intent replay, or returned an error. We
3730 * want to allow replayed RPCs to not get a lock, since we would just
3731 * drop it below anyways because lock replay is done separately by the
3732 * client afterwards. For regular RPCs we want to give the new lock to
3733 * the client instead of whatever lock it was about to get. */
3734 if (new_lock == NULL)
3735 new_lock = ldlm_handle2lock(&lockh[0]);
3736 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
3739 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
3740 it->opc, lockh[0].cookie);
3742 /* If we've already given this lock to a client once, then we should
3743 * have no readers or writers. Otherwise, we should have one reader
3744 * _or_ writer ref (which will be zeroed below) before returning the
3745 * lock to a client. */
3746 if (new_lock->l_export == req->rq_export) {
3747 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
3749 LASSERT(new_lock->l_export == NULL);
3750 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
3755 if (new_lock->l_export == req->rq_export) {
3756 /* Already gave this to the client, which means that we
3757 * reconstructed a reply. */
3758 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
3760 RETURN(ELDLM_LOCK_REPLACED);
3763 /* Fixup the lock to be given to the client */
3764 l_lock(&new_lock->l_resource->lr_namespace->ns_lock);
3765 new_lock->l_readers = 0;
3766 new_lock->l_writers = 0;
3768 new_lock->l_export = class_export_get(req->rq_export);
3769 list_add(&new_lock->l_export_chain,
3770 &new_lock->l_export->exp_ldlm_data.led_held_locks);
3772 new_lock->l_blocking_ast = lock->l_blocking_ast;
3773 new_lock->l_completion_ast = lock->l_completion_ast;
3775 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
3776 sizeof(lock->l_remote_handle));
3778 new_lock->l_flags &= ~LDLM_FL_LOCAL;
3780 LDLM_LOCK_PUT(new_lock);
3781 l_unlock(&new_lock->l_resource->lr_namespace->ns_lock);
3783 RETURN(ELDLM_LOCK_REPLACED);
3786 int mds_attach(struct obd_device *dev, obd_count len, void *data)
3788 struct lprocfs_static_vars lvars;
3791 lprocfs_init_multi_vars(0, &lvars);
3793 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
3797 return lprocfs_alloc_md_stats(dev, 0);
3800 int mds_detach(struct obd_device *dev)
3802 lprocfs_free_md_stats(dev);
3803 return lprocfs_obd_detach(dev);
3806 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
3808 struct lprocfs_static_vars lvars;
3810 lprocfs_init_multi_vars(1, &lvars);
3811 return lprocfs_obd_attach(dev, lvars.obd_vars);
3814 int mdt_detach(struct obd_device *dev)
3816 return lprocfs_obd_detach(dev);
3819 static int mdt_setup(struct obd_device *obd, obd_count len, void *buf)
3821 struct mds_obd *mds = &obd->u.mds;
3826 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3827 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
3828 MDS_SERVICE_WATCHDOG_TIMEOUT,
3829 mds_handle, "mds", obd->obd_proc_entry);
3831 if (!mds->mds_service) {
3832 CERROR("failed to start service\n");
3836 rc = ptlrpc_start_n_threads(obd, mds->mds_service, MDT_NUM_THREADS,
3839 GOTO(err_thread, rc);
3841 mds->mds_setattr_service =
3842 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3843 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
3844 MDS_SERVICE_WATCHDOG_TIMEOUT,
3845 mds_handle, "mds_setattr",
3846 obd->obd_proc_entry);
3847 if (!mds->mds_setattr_service) {
3848 CERROR("failed to start getattr service\n");
3849 GOTO(err_thread, rc = -ENOMEM);
3852 rc = ptlrpc_start_n_threads(obd, mds->mds_setattr_service,
3853 MDT_NUM_THREADS, "ll_mdt_attr");
3855 GOTO(err_thread2, rc);
3857 mds->mds_readpage_service =
3858 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
3859 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
3860 MDS_SERVICE_WATCHDOG_TIMEOUT,
3861 mds_handle, "mds_readpage",
3862 obd->obd_proc_entry);
3863 if (!mds->mds_readpage_service) {
3864 CERROR("failed to start readpage service\n");
3865 GOTO(err_thread2, rc = -ENOMEM);
3868 rc = ptlrpc_start_n_threads(obd, mds->mds_readpage_service,
3869 MDT_NUM_THREADS, "ll_mdt_rdpg");
3872 GOTO(err_thread3, rc);
3877 ptlrpc_unregister_service(mds->mds_readpage_service);
3879 ptlrpc_unregister_service(mds->mds_setattr_service);
3881 ptlrpc_unregister_service(mds->mds_service);
3885 static int mdt_cleanup(struct obd_device *obd, int flags)
3887 struct mds_obd *mds = &obd->u.mds;
3890 ptlrpc_stop_all_threads(mds->mds_readpage_service);
3891 ptlrpc_unregister_service(mds->mds_readpage_service);
3893 ptlrpc_stop_all_threads(mds->mds_setattr_service);
3894 ptlrpc_unregister_service(mds->mds_setattr_service);
3896 ptlrpc_stop_all_threads(mds->mds_service);
3897 ptlrpc_unregister_service(mds->mds_service);
3902 static struct dentry *mds_lvfs_id2dentry(__u64 ino, __u32 gen,
3903 __u64 gr, void *data)
3905 struct lustre_id id;
3906 struct obd_device *obd = data;
3910 return mds_id2dentry(obd, &id, NULL);
3913 static int mds_get_info(struct obd_export *exp, __u32 keylen,
3914 void *key, __u32 *valsize, void *val)
3916 struct obd_device *obd;
3917 struct mds_obd *mds;
3920 obd = class_exp2obd(exp);
3924 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
3925 exp->exp_handle.h_cookie);
3929 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
3930 /* get log_context handle. */
3931 unsigned long *llh_handle = val;
3932 *valsize = sizeof(unsigned long);
3933 *llh_handle = (unsigned long)obd->obd_llog_ctxt[LLOG_REINT_ORIG_CTXT];
3936 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
3937 /* get log_context handle. */
3938 unsigned long *sb = val;
3939 *valsize = sizeof(unsigned long);
3940 *sb = (unsigned long)obd->u.mds.mds_sb;
3944 if (keylen >= strlen("mdsize") && memcmp(key, "mdsize", keylen) == 0) {
3945 __u32 *mdsize = val;
3946 *valsize = sizeof(*mdsize);
3947 *mdsize = mds->mds_max_mdsize;
3951 if (keylen >= strlen("mdsnum") && strcmp(key, "mdsnum") == 0) {
3952 __u32 *mdsnum = val;
3953 *valsize = sizeof(*mdsnum);
3954 *mdsnum = mds->mds_num;
3958 if (keylen >= strlen("rootid") && strcmp(key, "rootid") == 0) {
3959 struct lustre_id *rootid = val;
3960 *valsize = sizeof(struct lustre_id);
3961 *rootid = mds->mds_rootid;
3965 CDEBUG(D_IOCTL, "invalid key\n");
3969 struct lvfs_callback_ops mds_lvfs_ops = {
3970 l_id2dentry: mds_lvfs_id2dentry,
3973 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
3974 int objcount, struct obd_ioobj *obj,
3975 int niocount, struct niobuf_remote *nb,
3976 struct niobuf_local *res,
3977 struct obd_trans_info *oti);
3979 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
3980 int objcount, struct obd_ioobj *obj, int niocount,
3981 struct niobuf_local *res, struct obd_trans_info *oti,
3984 /* use obd ops to offer management infrastructure */
3985 static struct obd_ops mds_obd_ops = {
3986 .o_owner = THIS_MODULE,
3987 .o_attach = mds_attach,
3988 .o_detach = mds_detach,
3989 .o_connect = mds_connect,
3990 .o_connect_post = mds_connect_post,
3991 .o_init_export = mds_init_export,
3992 .o_destroy_export = mds_destroy_export,
3993 .o_disconnect = mds_disconnect,
3994 .o_setup = mds_setup,
3995 .o_precleanup = mds_precleanup,
3996 .o_cleanup = mds_cleanup,
3997 .o_process_config = mds_process_config,
3998 .o_postrecov = mds_postrecov,
3999 .o_statfs = mds_obd_statfs,
4000 .o_iocontrol = mds_iocontrol,
4001 .o_create = mds_obd_create,
4002 .o_destroy = mds_obd_destroy,
4003 .o_llog_init = mds_llog_init,
4004 .o_llog_finish = mds_llog_finish,
4005 .o_notify = mds_notify,
4006 .o_get_info = mds_get_info,
4007 .o_set_info = mds_set_info,
4008 .o_preprw = mds_preprw,
4009 .o_commitrw = mds_commitrw,
4012 static struct obd_ops mdt_obd_ops = {
4013 .o_owner = THIS_MODULE,
4014 .o_attach = mdt_attach,
4015 .o_detach = mdt_detach,
4016 .o_setup = mdt_setup,
4017 .o_cleanup = mdt_cleanup,
4020 static int __init mds_init(void)
4022 struct lprocfs_static_vars lvars;
4024 mds_init_lsd_cache();
4026 lprocfs_init_multi_vars(0, &lvars);
4027 class_register_type(&mds_obd_ops, NULL, lvars.module_vars,
4029 lprocfs_init_multi_vars(1, &lvars);
4030 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars,
4036 static void /*__exit*/ mds_exit(void)
4038 mds_cleanup_lsd_cache();
4040 class_unregister_type(LUSTRE_MDS_NAME);
4041 class_unregister_type(LUSTRE_MDT_NAME);
4044 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4045 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
4046 MODULE_LICENSE("GPL");
4048 module_init(mds_init);
4049 module_exit(mds_exit);