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 <linux/lustre_sec.h>
60 #include <linux/lustre_gs.h>
61 #include "mds_internal.h"
63 static int mds_intent_policy(struct ldlm_namespace *ns,
64 struct ldlm_lock **lockp, void *req_cookie,
65 ldlm_mode_t mode, int flags, void *data);
66 static int mds_postsetup(struct obd_device *obd);
67 static int mds_cleanup(struct obd_device *obd, int flags);
70 /* Assumes caller has already pushed into the kernel filesystem context */
71 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
72 loff_t offset, int count)
74 struct ptlrpc_bulk_desc *desc;
75 struct l_wait_info lwi;
77 int rc = 0, npages, i, tmpcount, tmpsize = 0;
80 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
82 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
83 OBD_ALLOC(pages, sizeof(*pages) * npages);
85 GOTO(out, rc = -ENOMEM);
87 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
90 GOTO(out_free, rc = -ENOMEM);
92 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
93 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
95 pages[i] = alloc_pages(GFP_KERNEL, 0);
97 GOTO(cleanup_buf, rc = -ENOMEM);
99 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
102 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
103 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
104 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
105 tmpsize, offset, file->f_dentry->d_inode->i_ino,
106 file->f_dentry->d_inode->i_size);
108 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
109 kmap(pages[i]), tmpsize, &offset);
113 GOTO(cleanup_buf, rc = -EIO);
116 LASSERT(desc->bd_nob == count);
118 rc = ptlrpc_start_bulk_transfer(desc);
120 GOTO(cleanup_buf, rc);
122 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
123 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
124 OBD_FAIL_MDS_SENDPAGE, rc = -EIO);
125 GOTO(abort_bulk, rc);
128 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
129 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
130 LASSERT (rc == 0 || rc == -ETIMEDOUT);
133 if (desc->bd_success &&
134 desc->bd_nob_transferred == count)
135 GOTO(cleanup_buf, rc);
137 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
140 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
141 (rc == -ETIMEDOUT) ? "timeout" : "network error",
142 desc->bd_nob_transferred, count,
143 req->rq_export->exp_client_uuid.uuid,
144 req->rq_export->exp_connection->c_remote_uuid.uuid);
146 ptlrpc_fail_export(req->rq_export);
150 ptlrpc_abort_bulk (desc);
152 for (i = 0; i < npages; i++)
154 __free_pages(pages[i], 0);
156 ptlrpc_free_bulk(desc);
158 OBD_FREE(pages, sizeof(*pages) * npages);
163 extern char *ldlm_lockname[];
165 int mds_lock_mode_for_dir(struct obd_device *obd,
166 struct dentry *dentry, int mode)
168 int ret_mode = 0, split;
170 /* any dir access needs couple locks:
171 * 1) on part of dir we gonna lookup/modify in
172 * 2) on a whole dir to protect it from concurrent splitting
173 * and to flush client's cache for readdir()
174 * so, for a given mode and dentry this routine decides what
175 * lock mode to use for lock #2:
176 * 1) if caller's gonna lookup in dir then we need to protect
177 * dir from being splitted only - LCK_CR
178 * 2) if caller's gonna modify dir then we need to protect
179 * dir from being splitted and to flush cache - LCK_CW
180 * 3) if caller's gonna modify dir and that dir seems ready
181 * for splitting then we need to protect it from any
182 * type of access (lookup/modify/split) - LCK_EX -bzzz */
184 split = mds_splitting_expected(obd, dentry);
187 * it is important to check here only for MDS_NO_SPLITTABLE. The reason
188 * is that MDS_NO_SPLITTABLE means dir is not splittable in principle
189 * and another thread will not split it on the quiet. But if we have
190 * MDS_NO_SPLIT_EXPECTED, this means, that dir may be splitted anytime,
191 * but not now (for current thread) and we should consider that it can
192 * happen soon and go that branch which can yield LCK_EX to protect from
193 * possible splitting.
195 if (split == MDS_NO_SPLITTABLE) {
197 * this inode won't be splitted. so we need not to protect from
198 * just flush client's cache on modification.
205 if (mode == LCK_EX) {
207 } else if (mode == LCK_PR) {
209 } else if (mode == LCK_PW) {
211 * caller gonna modify directory. We use concurrent
212 * write lock here to retract client's cache for
215 if (split == MDS_EXPECT_SPLIT) {
217 * splitting possible. serialize any access the
218 * idea is that first one seen dir is splittable
219 * is given exclusive lock and split
220 * directory. caller passes lock mode to
221 * mds_try_to_split_dir() and splitting would be
222 * done with exclusive lock only -bzzz.
224 CDEBUG(D_OTHER, "%s: gonna split %lu/%lu\n",
226 (unsigned long)dentry->d_inode->i_ino,
227 (unsigned long)dentry->d_inode->i_generation);
238 /* only valid locked dentries or errors should be returned */
239 struct dentry *mds_id2locked_dentry(struct obd_device *obd, struct lustre_id *id,
240 struct vfsmount **mnt, int lock_mode,
241 struct lustre_handle *lockh, int *mode,
242 char *name, int namelen, __u64 lockpart)
244 struct dentry *de = mds_id2dentry(obd, id, mnt), *retval = de;
245 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
246 struct ldlm_res_id res_id = { .name = {0} };
247 int flags = LDLM_FL_ATOMIC_CB, rc;
254 res_id.name[0] = id_fid(id);
255 res_id.name[1] = id_group(id);
258 if (name && IS_PDIROPS(de->d_inode)) {
259 ldlm_policy_data_t cpolicy =
260 { .l_inodebits = { MDS_INODELOCK_UPDATE } };
261 LASSERT(mode != NULL);
262 *mode = mds_lock_mode_for_dir(obd, de, lock_mode);
264 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
266 &cpolicy, *mode, &flags,
268 ldlm_completion_ast, NULL, NULL,
269 NULL, 0, NULL, lockh + 1);
270 if (rc != ELDLM_OK) {
272 RETURN(ERR_PTR(-ENOLCK));
275 flags = LDLM_FL_ATOMIC_CB;
277 res_id.name[2] = full_name_hash((unsigned char *)name, namelen);
279 CDEBUG(D_INFO, "take lock on "DLID4":"LPX64"\n",
280 OLID4(id), res_id.name[2]);
283 #warning "No PDIROPS support in the kernel"
285 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
286 LDLM_IBITS, &policy, lock_mode, &flags,
287 mds_blocking_ast, ldlm_completion_ast,
288 NULL, NULL, NULL, 0, NULL, lockh);
289 if (rc != ELDLM_OK) {
291 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
294 ldlm_lock_decref(lockh + 1, *mode);
296 } else if (de->d_inode && de->d_inode->i_nlink == 0) {
297 /* as sometimes we lookup inode by ino/generation through
298 iopen mechanism, it's possible to find already unlinked
299 inode with nlink == 0. let's interpretate the case as
301 CWARN("found already unlinked inode %lu/%u\n",
302 de->d_inode->i_ino, de->d_inode->i_generation);
304 retval = ERR_PTR(-ENOENT);
305 ldlm_lock_decref(lockh, lock_mode);
308 ldlm_lock_decref(lockh + 1, *mode);
315 #ifndef DCACHE_DISCONNECTED
316 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
319 /* Look up an entry by inode number. This function ONLY returns valid dget'd
320 * dentries with an initialized inode or errors */
321 struct dentry *mds_id2dentry(struct obd_device *obd, struct lustre_id *id,
322 struct vfsmount **mnt)
324 struct mds_obd *mds = &obd->u.mds;
325 struct dentry *result;
327 unsigned long ino = 0;
328 __u32 generation = 0;
331 if (!id_ino(id) && id_fid(id)) {
332 struct lustre_id *lid;
334 /* if this is reint case we should use fidmap for resolving
335 * correct local store cookie. */
336 lid = mds_fidmap_lookup(obd, id);
338 RETURN(ERR_PTR(-ENOENT));
340 ino = (unsigned long)id_ino(lid);
341 generation = (__u32)id_gen(lid);
343 CDEBUG(D_DENTRY, "fidmap resolved "DLID4"->"DLID4"\n",
344 OLID4(id), OLID4(lid));
346 } else if (id_ino(id)) {
347 ino = (unsigned long)id_ino(id);
348 generation = (__u32)id_gen(id);
350 CERROR("invalid id for lookup "
351 DLID4"\n", OLID4(id));
356 RETURN(ERR_PTR(-ESTALE));
358 snprintf(idname, sizeof(idname), "0x%lx", ino);
360 CDEBUG(D_DENTRY, "--> mds_id2dentry: ino/gen %lu/%u, sb %p\n",
361 ino, generation, mds->mds_sb);
363 /* under ext3 this is neither supposed to return bad inodes nor NULL
365 result = ll_lookup_one_len(idname, mds->mds_id_de,
370 inode = result->d_inode;
372 RETURN(ERR_PTR(-ENOENT));
374 if (is_bad_inode(inode)) {
375 CERROR("bad inode returned %lu/%u\n",
376 inode->i_ino, inode->i_generation);
378 RETURN(ERR_PTR(-ENOENT));
381 /* here we disabled generation check, as root inode i_generation
382 * of cache mds and real mds are different. */
383 if (id_fid(id) != id_fid(&mds->mds_rootid) && generation != 0 &&
384 inode->i_generation != generation) {
385 /* we didn't find the right inode.. */
386 if (id_group(id) != mds->mds_num) {
387 CERROR("bad inode %lu found, link: %lu, ct: %d, generation "
388 "%u != %u, mds %u != %u, request to wrong MDS?\n",
389 inode->i_ino, (unsigned long)inode->i_nlink,
390 atomic_read(&inode->i_count), inode->i_generation,
391 generation, mds->mds_num, (unsigned)id_group(id));
393 CERROR("bad inode %lu found, link: %lu, ct: %d, generation "
394 "%u != %u, inode is recreated while request handled?\n",
395 inode->i_ino, (unsigned long)inode->i_nlink,
396 atomic_read(&inode->i_count), inode->i_generation,
400 RETURN(ERR_PTR(-ENOENT));
404 *mnt = mds->mds_vfsmnt;
412 int mds_req_add_idmapping(struct ptlrpc_request *req,
413 struct mds_export_data *med)
415 struct mds_req_sec_desc *rsd;
416 struct lustre_sec_desc *lsd;
419 if (!med->med_remote)
422 /* maybe we should do it more completely: invalidate the gss ctxt? */
423 if (req->rq_mapped_uid == MDS_IDMAP_NOTFOUND) {
424 CWARN("didn't find mapped uid\n");
428 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
430 CERROR("Can't unpack security desc\n");
434 lsd = mds_get_lsd(req->rq_mapped_uid);
436 CERROR("can't get LSD(%u), no mapping added\n",
441 rc = mds_idmap_add(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
442 rsd->rsd_gid, lsd->lsd_gid);
448 int mds_req_del_idmapping(struct ptlrpc_request *req,
449 struct mds_export_data *med)
451 struct mds_req_sec_desc *rsd;
452 struct lustre_sec_desc *lsd;
455 if (!med->med_remote)
458 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
460 CERROR("Can't unpack security desc\n");
464 LASSERT(req->rq_mapped_uid != -1);
465 lsd = mds_get_lsd(req->rq_mapped_uid);
467 CERROR("can't get LSD(%u), no idmapping deleted\n",
472 rc = mds_idmap_del(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
473 rsd->rsd_gid, lsd->lsd_gid);
478 static int mds_init_export_data(struct ptlrpc_request *req,
479 struct mds_export_data *med)
481 struct obd_connect_data *data, *reply;
482 int ask_remote, ask_local;
485 data = lustre_msg_buf(req->rq_reqmsg, 5, sizeof(*data));
486 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*data));
487 LASSERT(data && reply);
489 if (med->med_initialized) {
490 CDEBUG(D_SEC, "med already initialized, reconnect?\n");
494 ask_remote = data->ocd_connect_flags & OBD_CONNECT_REMOTE;
495 ask_local = data->ocd_connect_flags & OBD_CONNECT_LOCAL;
497 /* currently the policy is simple: satisfy client as possible
500 if (req->rq_auth_uid == -1) {
502 CWARN("null sec is used, force to be local\n");
506 if (!req->rq_remote_realm)
507 CWARN("local realm asked to be remote\n");
509 } else if (ask_local) {
510 if (req->rq_remote_realm)
511 CWARN("remote realm asked to be local\n");
514 med->med_remote = (req->rq_remote_realm != 0);
517 med->med_nllu = data->ocd_nllu[0];
518 med->med_nllg = data->ocd_nllu[1];
520 med->med_initialized = 1;
522 reply->ocd_connect_flags &= ~(OBD_CONNECT_REMOTE | OBD_CONNECT_LOCAL);
523 if (med->med_remote) {
525 med->med_idmap = mds_idmap_alloc();
528 CERROR("Failed to alloc idmap, following request from "
529 "this client will be refused\n");
531 reply->ocd_connect_flags |= OBD_CONNECT_REMOTE;
532 CDEBUG(D_SEC, "set client as remote\n");
534 reply->ocd_connect_flags |= OBD_CONNECT_LOCAL;
535 CDEBUG(D_SEC, "set client as local\n");
541 static void mds_free_export_data(struct mds_export_data *med)
546 LASSERT(med->med_remote);
547 mds_idmap_free(med->med_idmap);
548 med->med_idmap = NULL;
551 /* Establish a connection to the MDS.
553 * This will set up an export structure for the client to hold state data about
554 * that client, like open files, the last operation number it did on the server,
557 static int mds_connect(struct lustre_handle *conn, struct obd_device *obd,
558 struct obd_uuid *cluuid, struct obd_connect_data *data,
561 struct mds_export_data *med;
562 struct mds_client_data *mcd;
563 struct obd_export *exp;
567 if (!conn || !obd || !cluuid)
570 /* XXX There is a small race between checking the list and adding a new
571 * connection for the same UUID, but the real threat (list corruption
572 * when multiple different clients connect) is solved.
574 * There is a second race between adding the export to the list, and
575 * filling in the client data below. Hence skipping the case of NULL
576 * mcd above. We should already be controlling multiple connects at the
577 * client, and we can't hold the spinlock over memory allocations
578 * without risk of deadlocking.
580 rc = class_connect(conn, obd, cluuid);
583 exp = class_conn2export(conn);
585 LASSERT(exp != NULL);
586 med = &exp->exp_mds_data;
588 OBD_ALLOC(mcd, sizeof(*mcd));
590 CERROR("%s: out of memory for client data.\n",
592 GOTO(out, rc = -ENOMEM);
595 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
598 rc = mds_client_add(obd, &obd->u.mds, med, -1);
606 OBD_FREE(mcd, sizeof(*mcd));
607 class_disconnect(exp, 0);
609 class_export_put(exp);
614 static int mds_connect_post(struct obd_export *exp, unsigned initial,
617 struct obd_device *obd = exp->exp_obd;
618 struct mds_obd *mds = &obd->u.mds;
619 struct mds_export_data *med;
620 struct mds_client_data *mcd;
624 med = &exp->exp_mds_data;
628 /* some one reconnect initially, we have to reset
629 * data existing export can have. bug 6102 */
630 if (mcd->mcd_last_xid != 0)
631 CDEBUG(D_HA, "initial reconnect to existing export\n");
632 mcd->mcd_last_transno = 0;
633 mcd->mcd_last_xid = 0;
634 mcd->mcd_last_close_xid = 0;
635 mcd->mcd_last_result = 0;
636 mcd->mcd_last_data = 0;
639 if (!(flags & OBD_OPT_MDS_CONNECTION)) {
640 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
641 atomic_inc(&mds->mds_real_clients);
642 CDEBUG(D_OTHER,"%s: peer from %s is real client (%d)\n",
643 obd->obd_name, exp->exp_client_uuid.uuid,
644 atomic_read(&mds->mds_real_clients));
645 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
647 if (mds->mds_md_name)
648 rc = mds_md_connect(obd, mds->mds_md_name);
653 static int mds_init_export(struct obd_export *exp)
655 struct mds_export_data *med = &exp->exp_mds_data;
657 INIT_LIST_HEAD(&med->med_open_head);
658 spin_lock_init(&med->med_open_lock);
662 static int mds_destroy_export(struct obd_export *export)
664 struct obd_device *obd = export->exp_obd;
665 struct mds_export_data *med = &export->exp_mds_data;
666 struct lvfs_run_ctxt saved;
670 mds_free_export_data(med);
671 target_destroy_export(export);
673 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
676 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
678 /* Close any open files (which may also cause orphan unlinking). */
679 spin_lock(&med->med_open_lock);
680 while (!list_empty(&med->med_open_head)) {
681 struct list_head *tmp = med->med_open_head.next;
682 struct mds_file_data *mfd =
683 list_entry(tmp, struct mds_file_data, mfd_list);
684 struct lustre_id sid;
686 BDEVNAME_DECLARE_STORAGE(btmp);
688 /* bug 1579: fix force-closing for 2.5 */
689 struct dentry *dentry = mfd->mfd_dentry;
691 list_del(&mfd->mfd_list);
692 spin_unlock(&med->med_open_lock);
694 down(&dentry->d_inode->i_sem);
695 rc = mds_read_inode_sid(obd, dentry->d_inode, &sid);
696 up(&dentry->d_inode->i_sem);
698 CERROR("Can't read inode self id, inode %lu, "
699 "rc %d\n", dentry->d_inode->i_ino, rc);
700 memset(&sid, 0, sizeof(sid));
703 /* If you change this message, be sure to update
704 * replay_single:test_46 */
705 CERROR("force closing client file handle for %.*s (%s:"
706 DLID4")\n", dentry->d_name.len, dentry->d_name.name,
707 ll_bdevname(dentry->d_inode->i_sb, btmp),
710 /* child inode->i_alloc_sem protects orphan_dec_test and
711 * is_orphan race, mds_mfd_close drops it */
712 DOWN_WRITE_I_ALLOC_SEM(dentry->d_inode);
713 rc = mds_mfd_close(NULL, 0, obd, mfd,
714 !(export->exp_flags & OBD_OPT_FAILOVER));
716 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
717 spin_lock(&med->med_open_lock);
719 spin_unlock(&med->med_open_lock);
720 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
724 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
728 static int mds_disconnect(struct obd_export *exp, unsigned long flags)
730 unsigned long irqflags;
731 struct obd_device *obd;
736 LASSERT(exp != NULL);
737 obd = class_exp2obd(exp);
739 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
740 exp->exp_handle.h_cookie);
746 * suppress any inter-mds requests durring disconnecting lmv if this is
747 * detected --force mode. This is needed to avoid endless recovery.
749 if (atomic_read(&mds->mds_real_clients) > 0 &&
750 !(exp->exp_flags & OBD_OPT_REAL_CLIENT))
751 flags |= OBD_OPT_FORCE;
753 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
754 && !atomic_read(&mds->mds_real_clients)) {
755 /* there was no client at all */
756 mds_md_disconnect(obd, flags);
759 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
760 && atomic_dec_and_test(&mds->mds_real_clients)) {
761 /* time to drop LMV connections */
762 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
763 "Disconnnect from LMV now\n",
764 obd->obd_name, exp->exp_client_uuid.uuid);
765 mds_md_disconnect(obd, flags);
768 spin_lock_irqsave(&exp->exp_lock, irqflags);
769 exp->exp_flags = flags;
770 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
772 /* disconnect early so that clients can't keep using export */
773 rc = class_disconnect(exp, flags);
774 ldlm_cancel_locks_for_export(exp);
776 /* complete all outstanding replies */
777 spin_lock_irqsave(&exp->exp_lock, irqflags);
778 while (!list_empty(&exp->exp_outstanding_replies)) {
779 struct ptlrpc_reply_state *rs =
780 list_entry(exp->exp_outstanding_replies.next,
781 struct ptlrpc_reply_state, rs_exp_list);
782 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
784 spin_lock(&svc->srv_lock);
785 list_del_init(&rs->rs_exp_list);
786 ptlrpc_schedule_difficult_reply(rs);
787 spin_unlock(&svc->srv_lock);
789 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
793 static int mds_getstatus(struct ptlrpc_request *req)
795 struct mds_obd *mds = mds_req2mds(req);
796 struct mds_body *body;
800 size = sizeof(*body);
802 rc = lustre_pack_reply(req, 1, &size, NULL);
803 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
804 CERROR("mds: out of memory for message: size=%d\n", size);
805 req->rq_status = -ENOMEM; /* superfluous? */
809 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
810 body->valid |= OBD_MD_FID;
812 memcpy(&body->id1, &mds->mds_rootid, sizeof(body->id1));
815 * the last_committed and last_xid fields are filled in for all replies
816 * already - no need to do so here also.
821 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
822 void *data, int flag)
827 if (flag == LDLM_CB_CANCELING) {
828 /* Don't need to do anything here. */
832 /* XXX layering violation! -phil */
833 lock_res_and_lock(lock);
836 * get this: if mds_blocking_ast is racing with mds_intent_policy, such
837 * that mds_blocking_ast is called just before l_i_p takes the ns_lock,
838 * then by the time we get the lock, we might not be the correct
839 * blocking function anymore. So check, and return early, if so.
841 if (lock->l_blocking_ast != mds_blocking_ast) {
842 unlock_res_and_lock(lock);
846 lock->l_flags |= LDLM_FL_CBPENDING;
847 do_ast = (!lock->l_readers && !lock->l_writers);
848 unlock_res_and_lock(lock);
851 struct lustre_handle lockh;
854 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
855 ldlm_lock2handle(lock, &lockh);
856 rc = ldlm_cli_cancel(&lockh);
858 CERROR("ldlm_cli_cancel: %d\n", rc);
860 LDLM_DEBUG(lock, "Lock still has references, will be "
866 static int mds_convert_md(struct obd_device *obd, struct inode *inode,
867 void *md, int size, int mea)
871 if (S_ISREG(inode->i_mode)) {
872 rc = mds_convert_lov_ea(obd, inode, md, size);
873 } else if (S_ISDIR(inode->i_mode)) {
875 rc = mds_convert_mea_ea(obd, inode, md, size);
877 rc = mds_convert_lov_ea(obd, inode, md, size);
880 CERROR("Invalid EA format (nor LOV or MEA) "
881 "is detected. Inode %lu/%u\n",
882 inode->i_ino, inode->i_generation);
888 int mds_get_md(struct obd_device *obd, struct inode *inode,
889 void *md, int *size, int lock, int mea)
898 rc = fsfilt_get_md(obd, inode, md, *size,
899 (mea ? EA_MEA : EA_LOV));
901 CERROR("Error %d reading eadata for ino %lu\n",
905 rc = mds_convert_md(obd, inode, md,
920 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
921 * Call with lock=0 if the caller has already taken the i_sem. */
922 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
923 struct mds_body *body, struct inode *inode, int lock, int mea)
925 struct mds_obd *mds = &obd->u.mds;
930 lmm = lustre_msg_buf(msg, offset, 0);
932 /* Some problem with getting eadata when I sized the reply
934 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
938 lmm_size = msg->buflens[offset];
940 /* I don't really like this, but it is a sanity check on the client
941 * MD request. However, if the client doesn't know how much space
942 * to reserve for the MD, it shouldn't be bad to have too much space.
944 if (lmm_size > mds->mds_max_mdsize) {
945 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
946 inode->i_ino, lmm_size, mds->mds_max_mdsize);
950 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, mea);
952 body->valid |= S_ISDIR(inode->i_mode) ?
953 OBD_MD_FLDIREA : OBD_MD_FLEASIZE;
956 body->valid |= OBD_MD_MEA;
958 body->eadatasize = lmm_size;
965 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
966 struct mds_body *repbody, int reply_off)
968 struct inode *inode = dentry->d_inode;
973 symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
974 LASSERT(symname != NULL);
975 len = req->rq_repmsg->buflens[reply_off + 1];
977 rc = inode->i_op->readlink(dentry, symname, len);
979 CERROR("readlink failed: %d\n", rc);
980 } else if (rc != len - 1) {
981 CERROR ("Unexpected readlink rc %d: expecting %d\n",
985 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
986 repbody->valid |= OBD_MD_LINKNAME;
987 repbody->eadatasize = rc + 1;
988 symname[rc] = 0; /* NULL terminate */
995 int mds_pack_xattr(struct dentry *dentry, struct ptlrpc_request *req,
996 struct mds_body *repbody, int req_off, int reply_off)
998 struct inode *inode = dentry->d_inode;
1004 ea_name = lustre_msg_string(req->rq_reqmsg, req_off + 1, 0);
1005 len = req->rq_repmsg->buflens[reply_off + 1];
1007 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
1011 if (!strcmp(ea_name, XATTR_NAME_LUSTRE_ACL)) {
1012 struct rmtacl_upcall_desc desc;
1014 if (len != LUSTRE_ACL_SIZE_MAX || !value) {
1015 CERROR("no reply buffer prepared\n");
1019 memset(&desc, 0, sizeof(desc));
1021 desc.cmd = lustre_msg_string(req->rq_reqmsg, req_off + 2, 0);
1022 desc.cmdlen = req->rq_reqmsg->buflens[req_off + 2];
1023 desc.res = (char *) value;
1024 desc.reslen = LUSTRE_ACL_SIZE_MAX;
1026 mds_do_remote_acl_upcall(&desc);
1028 if (desc.upcall_status)
1029 RETURN(desc.upcall_status);
1031 if (desc.reslen > LUSTRE_ACL_SIZE_MAX) {
1032 CERROR("downcall claim reslen %u\n", desc.reslen);
1035 /* like remote setfacl, steal "flags" in mds_body as the
1036 * exececution status
1038 repbody->flags = desc.status;
1039 repbody->valid |= OBD_MD_FLXATTR;
1040 repbody->eadatasize = desc.reslen;
1045 if (inode->i_op && inode->i_op->getxattr)
1046 rc = inode->i_op->getxattr(dentry, ea_name, value, len);
1049 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1050 CERROR("getxattr failed: %d", rc);
1052 repbody->valid |= OBD_MD_FLXATTR;
1053 repbody->eadatasize = rc;
1060 int mds_pack_xattr_list(struct dentry *dentry, struct ptlrpc_request *req,
1061 struct mds_body *repbody, int reply_off)
1063 struct inode *inode = dentry->d_inode;
1068 len = req->rq_repmsg->buflens[reply_off + 1];
1070 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
1073 if (inode->i_op && inode->i_op->getxattr)
1074 rc = inode->i_op->listxattr(dentry, value, len);
1077 CERROR("listxattr failed: %d", rc);
1079 repbody->valid |= OBD_MD_FLXATTRLIST;
1080 repbody->eadatasize = rc;
1087 int mds_pack_posix_acl(struct lustre_msg *repmsg, int offset,
1088 struct mds_body *body, struct inode *inode)
1090 struct dentry de = { .d_inode = inode };
1091 __u32 buflen, *sizep;
1096 if (!inode->i_op->getxattr)
1099 sizep = lustre_msg_buf(repmsg, offset, 4);
1101 CERROR("can't locate returned acl size buf\n");
1105 buflen = repmsg->buflens[offset + 1];
1106 buf = lustre_msg_buf(repmsg, offset + 1, buflen);
1108 size = inode->i_op->getxattr(&de, XATTR_NAME_ACL_ACCESS, buf, buflen);
1109 if (size == -ENODATA || size == -EOPNOTSUPP)
1115 *sizep = cpu_to_le32(size);
1116 body->valid |= OBD_MD_FLACL;
1121 int mds_pack_remote_perm(struct ptlrpc_request *req, int reply_off,
1122 struct mds_body *body, struct inode *inode)
1124 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
1125 struct lustre_sec_desc *lsd;
1126 struct mds_remote_perm *perm;
1129 LASSERT(inode->i_op);
1130 LASSERT(inode->i_op->permission);
1131 LASSERT(req->rq_export->exp_mds_data.med_remote);
1133 perm = (struct mds_remote_perm *)
1134 lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(perm));
1136 CERROR("no remote perm buf at offset %d\n", reply_off);
1140 memset(perm, 0, sizeof(*perm));
1142 /* obtain authenticated uid/gid and LSD permissions, which
1143 * might be different from current process context, from LSD
1145 lsd = mds_get_lsd(current->uid);
1147 CWARN("can't LSD of uid %u\n", current->uid);
1151 perm->mrp_auth_uid = lsd->lsd_uid;
1152 perm->mrp_auth_gid = lsd->lsd_gid;
1154 lsd_perms = mds_lsd_get_perms(lsd, 1, 0, req->rq_peer.peer_id.nid);
1155 if (lsd_perms & LSD_PERM_SETUID)
1156 perm->mrp_allow_setuid = 1;
1157 if (lsd_perms & LSD_PERM_SETGID)
1158 perm->mrp_allow_setgid = 1;
1162 if (mds_remote_perm_do_reverse_map(med, perm))
1165 /* permission bits of current user
1166 * XXX this is low efficient, could we do it in one blow?
1168 if (inode->i_op->permission(inode, MAY_EXEC, NULL) == 0)
1169 perm->mrp_perm |= MAY_EXEC;
1170 if (inode->i_op->permission(inode, MAY_WRITE, NULL) == 0)
1171 perm->mrp_perm |= MAY_WRITE;
1172 if (inode->i_op->permission(inode, MAY_READ, NULL) == 0)
1173 perm->mrp_perm |= MAY_READ;
1175 body->valid |= (OBD_MD_FLACL | OBD_MD_FLRMTACL);
1180 int mds_pack_acl(struct ptlrpc_request *req, int reply_off,
1181 struct mds_body *body, struct inode *inode)
1185 if (!req->rq_export->exp_mds_data.med_remote)
1186 rc = mds_pack_posix_acl(req->rq_repmsg, reply_off, body, inode);
1188 rc = mds_pack_remote_perm(req, reply_off + 1, body, inode);
1193 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
1194 struct ptlrpc_request *req, int req_off,
1195 struct mds_body *reqbody, int reply_off,
1196 struct mds_req_sec_desc *rsd)
1198 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
1199 struct inode *inode = dentry->d_inode;
1200 struct mds_body *body;
1201 int rc = 0, offset = 0;
1204 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
1207 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
1208 LASSERT(body != NULL); /* caller prepped reply */
1210 if (dentry->d_flags & DCACHE_CROSS_REF) {
1211 mds_pack_dentry2body(obd, body, dentry,
1212 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1213 CDEBUG(D_OTHER, "cross reference: "DLID4"\n",
1218 mds_pack_inode2body(obd, body, inode,
1219 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1221 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
1222 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
1224 /* guessing what kind og attribute do we need. */
1225 int is_mea = (S_ISDIR(inode->i_mode) &&
1226 (reqbody->valid & OBD_MD_MEA) != 0);
1228 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1,
1229 body, inode, 1, is_mea);
1231 /* if we have LOV EA data, the OST holds size, atime, mtime. */
1232 if (!(body->valid & OBD_MD_FLEASIZE) &&
1233 !(body->valid & OBD_MD_FLDIREA))
1234 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
1235 OBD_MD_FLATIME | OBD_MD_FLMTIME);
1237 } else if (S_ISLNK(inode->i_mode) &&
1238 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
1239 rc = mds_pack_link(dentry, req, body, reply_off);
1240 } else if (reqbody->valid & OBD_MD_FLXATTR) {
1241 rc = mds_pack_xattr(dentry, req, body, req_off, reply_off);
1242 } else if (reqbody->valid & OBD_MD_FLXATTRLIST) {
1243 rc = mds_pack_xattr_list(dentry, req, body, reply_off);
1246 offset = reply_off + ((reqbody->valid & OBD_MD_FLEASIZE) ? 2 : 1);
1247 if (reqbody->valid & OBD_MD_FLACL) {
1248 rc = mds_pack_acl(req, offset, body, inode);
1252 if (reqbody->valid & OBD_MD_FLKEY) {
1253 rc = mds_pack_gskey(obd, req->rq_repmsg, &offset,
1257 mds_pack_audit(obd, inode, body);
1259 if (reqbody->valid & OBD_MD_CAPA) {
1260 struct lustre_capa *req_capa;
1262 LASSERT(!(reqbody->valid & ~OBD_MD_CAPA));
1263 LASSERT(S_ISREG(inode->i_mode));
1265 req_capa = lustre_swab_reqbuf(req, req_off + 1,
1267 lustre_swab_lustre_capa);
1268 if (req_capa == NULL) {
1269 CERROR("Can't unpack capa\n");
1273 offset = reply_off + 1;
1274 rc = mds_pack_capa(obd, med, reqbody, req_capa, req,
1279 mds_body_do_reverse_map(med, body);
1284 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
1285 struct dentry *dentry,
1288 int rc = 0, size[1] = {sizeof(struct mds_body)};
1291 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1292 CERROR("failed MDS_GETATTR_PACK test\n");
1293 req->rq_status = -ENOMEM;
1297 rc = lustre_pack_reply(req, 1, size, NULL);
1299 CERROR("lustre_pack_reply failed: rc %d\n", rc);
1300 GOTO(out, req->rq_status = rc);
1308 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct dentry *de,
1311 struct inode *inode = de->d_inode;
1312 struct mds_obd *mds = mds_req2mds(req);
1313 struct mds_body *body;
1314 int rc = 0, size[4] = {sizeof(*body)}, bufcount = 1;
1317 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
1318 LASSERT(body != NULL); /* checked by caller */
1319 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
1321 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
1322 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
1325 down(&inode->i_sem);
1326 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
1327 ((body->valid & OBD_MD_MEA) ? EA_MEA : EA_LOV));
1330 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1331 CERROR("error getting inode %lu MD: rc = %d\n",
1334 } else if (rc > mds->mds_max_mdsize) {
1336 CERROR("MD size %d larger than maximum possible %u\n",
1337 rc, mds->mds_max_mdsize);
1339 size[bufcount] = rc;
1342 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
1343 if (inode->i_size + 1 != body->eadatasize)
1344 CERROR("symlink size: %Lu, reply space: %d\n",
1345 inode->i_size + 1, body->eadatasize);
1346 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
1348 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
1349 inode->i_size + 1, body->eadatasize);
1350 } else if ((body->valid & OBD_MD_FLXATTR)) {
1351 char *ea_name = lustre_msg_string(req->rq_reqmsg,
1355 if (!strcmp(ea_name, XATTR_NAME_LUSTRE_ACL)) {
1356 size[bufcount] = LUSTRE_ACL_SIZE_MAX;
1358 if (inode->i_op && inode->i_op->getxattr)
1359 rc = inode->i_op->getxattr(de, ea_name,
1363 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1364 CERROR("error get inode %lu EA: %d\n",
1368 size[bufcount] = min_t(int,
1369 body->eadatasize, rc);
1373 } else if (body->valid & OBD_MD_FLXATTRLIST) {
1375 if (inode->i_op && inode->i_op->getxattr)
1376 rc = inode->i_op->listxattr(de, NULL, 0);
1379 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1380 CERROR("error getting inode %lu EA: rc = %d\n",
1384 size[bufcount] = min_t(int, body->eadatasize, rc);
1389 /* may co-exist with OBD_MD_FLEASIZE */
1390 if (body->valid & OBD_MD_FLACL) {
1391 if (req->rq_export->exp_mds_data.med_remote) {
1392 size[bufcount++] = sizeof(int);
1393 size[bufcount++] = sizeof(struct mds_remote_perm);
1395 size[bufcount++] = sizeof(int);
1396 size[bufcount++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
1400 if (body->valid & OBD_MD_FLKEY) {
1401 size[bufcount++] = sizeof(int);
1402 size[bufcount++] = sizeof(struct crypto_key);
1405 if (body->valid & OBD_MD_CAPA)
1406 size[bufcount++] = sizeof(struct lustre_capa);
1408 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1409 CERROR("failed MDS_GETATTR_PACK test\n");
1410 req->rq_status = -ENOMEM;
1411 GOTO(out, rc = -ENOMEM);
1414 rc = lustre_pack_reply(req, bufcount, size, NULL);
1416 CERROR("out of memory\n");
1417 GOTO(out, req->rq_status = rc);
1425 int mds_check_mds_num(struct obd_device *obd, struct inode *inode,
1426 char *name, int namelen)
1428 struct mea *mea = NULL;
1429 int mea_size, rc = 0;
1432 rc = mds_md_get_attr(obd, inode, &mea, &mea_size);
1435 if (mea != NULL && mea->mea_count) {
1437 * dir is already splitted, check if requested filename should
1438 * live at this MDS or at another one.
1440 int i = mea_name2idx(mea, name, namelen - 1);
1441 if (mea->mea_master != id_group(&mea->mea_ids[i])) {
1443 "inapropriate MDS(%d) for %s. should be "
1444 "%lu(%d)\n", mea->mea_master, name,
1445 (unsigned long)id_group(&mea->mea_ids[i]), i);
1451 OBD_FREE(mea, mea_size);
1455 int mds_getattr_size(struct obd_device *obd, struct dentry *dentry,
1456 struct ptlrpc_request *req, struct mds_body *body)
1458 struct inode *inode = dentry->d_inode;
1461 LASSERT(body != NULL);
1463 if (dentry->d_inode == NULL || !S_ISREG(inode->i_mode))
1466 /* XXX: quite a ugly hack, need to check old code
1467 * drop FLSIZE/FLBLOCKS prior any checking to */
1468 body->valid &= ~(OBD_MD_FLSIZE | OBD_MD_FLBLOCKS|OBD_MD_FLMTIME);
1470 if (obd->obd_recovering) {
1471 CDEBUG(D_INODE, "size for "DLID4" is unknown yet (recovering)\n",
1476 if (atomic_read(&inode->i_writecount)) {
1477 /* some one has opened the file for write.
1478 * mds doesn't know actual size */
1479 CDEBUG(D_INODE, "MDS doesn't know actual size for "DLID4"\n",
1483 CDEBUG(D_INODE, "MDS returns "LPD64"/"LPD64" for"DLID4"\n",
1484 body->size, body->blocks, OLID4(&body->id1));
1485 body->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLMTIME;
1489 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
1490 struct lustre_handle *child_lockh, int child_part)
1492 struct obd_device *obd = req->rq_export->exp_obd;
1493 struct mds_obd *mds = &obd->u.mds;
1494 struct ldlm_reply *rep = NULL;
1495 struct lvfs_run_ctxt saved;
1496 struct mds_req_sec_desc *rsd;
1497 struct mds_body *body;
1498 struct dentry *dparent = NULL, *dchild = NULL;
1499 struct lvfs_ucred uc = {NULL, NULL,};
1500 struct lustre_handle parent_lockh[2] = {{0}, {0}};
1501 unsigned int namesize = 0;
1502 int rc = 0, cleanup_phase = 0, resent_req = 0, update_mode, reply_offset;
1506 LASSERT(!strcmp(obd->obd_type->typ_name, OBD_MDS_DEVICENAME));
1507 MD_COUNTER_INCREMENT(obd, getattr_lock);
1509 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1511 CERROR("Can't unpack security desc\n");
1515 /* swab now, before anyone looks inside the request. */
1516 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1517 lustre_swab_mds_body);
1519 CERROR("Can't swab mds_body\n");
1520 GOTO(cleanup, rc = -EFAULT);
1523 LASSERT_REQSWAB(req, offset + 1);
1524 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
1526 CERROR("Can't unpack name\n");
1527 GOTO(cleanup, rc = -EFAULT);
1529 namesize = req->rq_reqmsg->buflens[offset + 1];
1531 /* namesize less than 2 means we have empty name, probably came from
1532 revalidate by cfid, so no point in having name to be set */
1536 LASSERT (offset == 1 || offset == 3);
1538 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
1544 rc = mds_init_ucred(&uc, req, rsd);
1546 if (child_lockh->cookie == 0)
1547 mds_audit_auth(req, &uc, AUDIT_STAT, &body->id1,
1548 name, namesize - 1);
1552 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1553 cleanup_phase = 1; /* kernel context */
1554 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
1556 LASSERT(namesize > 0);
1557 if (child_lockh->cookie != 0) {
1558 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1562 if (body->valid == OBD_MD_FLID) {
1563 struct mds_body *mds_reply;
1564 int size = sizeof(*mds_reply);
1568 dparent = mds_id2dentry(obd, &body->id1, NULL);
1569 if (IS_ERR(dparent)) {
1570 rc = PTR_ERR(dparent);
1574 * the user requested ONLY the inode number, so do a raw lookup.
1576 rc = lustre_pack_reply(req, 1, &size, NULL);
1578 CERROR("out of memory\n");
1582 dir = dparent->d_inode;
1583 LASSERT(dir->i_op->lookup_raw != NULL);
1584 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
1586 mds_reply = lustre_msg_buf(req->rq_repmsg, 0,
1587 sizeof(*mds_reply));
1589 id_ino(&mds_reply->id1) = inum;
1590 mds_reply->valid = OBD_MD_FLID;
1594 if (resent_req == 0) {
1595 LASSERT(id_fid(&body->id1) != 0);
1597 rc = mds_get_parent_child_locked(obd, mds, &body->id1,
1598 parent_lockh, &dparent,
1600 MDS_INODELOCK_UPDATE,
1603 child_lockh, &dchild,
1604 LCK_PR, child_part);
1608 cleanup_phase = 2; /* dchild, dparent, locks */
1611 * let's make sure this name should leave on this mds
1614 rc = mds_check_mds_num(obd, dparent->d_inode, name, namesize);
1618 /* we have no dentry here, drop LOOKUP bit */
1619 /* FIXME: we need MDS_INODELOCK_LOOKUP or not. */
1620 child_part &= ~MDS_INODELOCK_LOOKUP;
1621 CDEBUG(D_OTHER, "%s: retrieve attrs for "DLID4"\n",
1622 obd->obd_name, OLID4(&body->id1));
1624 dchild = mds_id2locked_dentry(obd, &body->id1, NULL,
1625 LCK_PR, parent_lockh,
1626 &update_mode, NULL, 0,
1627 MDS_INODELOCK_UPDATE);
1628 if (IS_ERR(dchild)) {
1629 CERROR("can't find inode with id "DLID4", err = %d\n",
1630 OLID4(&body->id1), (int)PTR_ERR(dchild));
1631 rc = PTR_ERR(dchild);
1635 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
1638 struct ldlm_lock *granted_lock;
1640 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
1641 granted_lock = ldlm_handle2lock(child_lockh);
1643 LASSERTF(granted_lock != NULL, LPU64"/%lu lockh "LPX64"\n",
1644 id_fid(&body->id1), (unsigned long)id_group(&body->id1),
1645 child_lockh->cookie);
1648 /* usual named request */
1649 dparent = mds_id2dentry(obd, &body->id1, NULL);
1650 LASSERT(!IS_ERR(dparent));
1651 dchild = ll_lookup_one_len(name, dparent, namesize - 1);
1652 LASSERT(!IS_ERR(dchild));
1654 /* client wants to get attr. by id */
1655 dchild = mds_id2dentry(obd, &body->id1, NULL);
1656 LASSERT(!IS_ERR(dchild));
1658 LDLM_LOCK_PUT(granted_lock);
1661 cleanup_phase = 2; /* dchild, dparent, locks */
1663 if (!DENTRY_VALID(dchild)) {
1664 intent_set_disposition(rep, DISP_LOOKUP_NEG);
1666 * in the intent case, the policy clears this error: the
1667 * disposition is enough.
1672 intent_set_disposition(rep, DISP_LOOKUP_POS);
1675 if (req->rq_repmsg == NULL) {
1676 if (dchild->d_flags & DCACHE_CROSS_REF)
1677 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
1679 rc = mds_getattr_pack_msg(req, dchild, offset);
1681 CERROR ("mds_getattr_pack_msg: %d\n", rc);
1686 rc = mds_getattr_internal(obd, dchild, req, offset, body,
1689 GOTO(cleanup, rc); /* returns the lock to the client */
1691 /* probably MDS knows actual size? */
1692 body = lustre_msg_buf(req->rq_repmsg, reply_offset, sizeof(*body));
1693 LASSERT(body != NULL);
1694 mds_getattr_size(obd, dchild, req, body);
1699 switch (cleanup_phase) {
1701 if (resent_req == 0) {
1702 mds_audit(req, dchild, name, namesize - 1,
1704 if (rc && DENTRY_VALID(dchild))
1705 ldlm_lock_decref(child_lockh, LCK_PR);
1707 ldlm_lock_decref(parent_lockh, LCK_PR);
1709 if (parent_lockh[1].cookie != 0)
1710 ldlm_lock_decref(parent_lockh + 1, update_mode);
1718 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1720 mds_exit_ucred(&uc);
1725 static int mds_getattr(struct ptlrpc_request *req, int offset)
1727 struct obd_device *obd = req->rq_export->exp_obd;
1728 struct lvfs_run_ctxt saved;
1730 struct mds_req_sec_desc *rsd;
1731 struct mds_body *body;
1732 struct lvfs_ucred uc = {NULL, NULL,};
1736 MD_COUNTER_INCREMENT(obd, getattr);
1738 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1740 CERROR("Can't unpack security desc\n");
1744 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1745 lustre_swab_mds_body);
1747 CERROR ("Can't unpack body\n");
1751 rc = mds_init_ucred(&uc, req, rsd);
1753 mds_exit_ucred(&uc);
1757 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1758 de = mds_id2dentry(obd, &body->id1, NULL);
1764 rc = mds_getattr_pack_msg(req, de, offset);
1766 CERROR("mds_getattr_pack_msg: %d\n", rc);
1771 rc = mds_getattr_internal(obd, de, req, offset, body, 0, rsd);
1776 req->rq_status = rc;
1777 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1778 if (req->rq_reply_state == NULL)
1779 lustre_pack_reply(req, 0, NULL, NULL);
1780 mds_exit_ucred(&uc);
1784 static int mds_access_check(struct ptlrpc_request *req, int offset)
1786 struct obd_device *obd = req->rq_export->exp_obd;
1787 struct lvfs_run_ctxt saved;
1789 struct mds_req_sec_desc *rsd;
1790 struct mds_body *body;
1791 struct lvfs_ucred uc;
1792 int rep_size[2] = {sizeof(*body),
1793 sizeof(struct mds_remote_perm)};
1797 if (!req->rq_export->exp_mds_data.med_remote) {
1798 CERROR("from local client "LPU64"\n", req->rq_peer.peer_id.nid);
1802 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1804 CERROR("Can't unpack security desc\n");
1808 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1809 lustre_swab_mds_body);
1811 CERROR ("Can't unpack body\n");
1815 MD_COUNTER_INCREMENT(obd, access_check);
1817 rc = mds_init_ucred(&uc, req, rsd);
1819 CERROR("init ucred error: %d\n", rc);
1822 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1824 de = mds_id2dentry(obd, &body->id1, NULL);
1826 CERROR("grab ino "LPU64": err %ld\n",
1827 body->id1.li_stc.u.e3s.l3s_ino, PTR_ERR(de));
1828 GOTO(out_pop, rc = PTR_ERR(de));
1831 rc = lustre_pack_reply(req, 2, rep_size, NULL);
1833 CERROR("pack reply error: %d\n", rc);
1834 GOTO(out_dput, rc = -EINVAL);
1837 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1840 rc = mds_pack_remote_perm(req, 1, body, de->d_inode);
1847 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1848 mds_exit_ucred(&uc);
1852 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1853 unsigned long max_age)
1858 spin_lock(&obd->obd_osfs_lock);
1859 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
1861 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1862 spin_unlock(&obd->obd_osfs_lock);
1867 static int mds_statfs(struct ptlrpc_request *req)
1869 struct obd_device *obd = req->rq_export->exp_obd;
1870 int rc, size = sizeof(struct obd_statfs);
1873 /* This will trigger a watchdog timeout */
1874 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1875 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1877 rc = lustre_pack_reply(req, 1, &size, NULL);
1878 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1879 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1883 OBD_COUNTER_INCREMENT(obd, statfs);
1885 /* We call this so that we can cache a bit - 1 jiffie worth */
1886 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
1889 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1895 req->rq_status = rc;
1899 static int mds_sync(struct ptlrpc_request *req, int offset)
1901 struct obd_device *obd = req->rq_export->exp_obd;
1902 struct mds_obd *mds = &obd->u.mds;
1903 struct mds_body *body;
1904 int rc, size = sizeof(*body);
1907 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1908 lustre_swab_mds_body);
1910 GOTO(out, rc = -EPROTO);
1912 rc = lustre_pack_reply(req, 1, &size, NULL);
1913 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1914 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1918 if (id_ino(&body->id1) == 0) {
1919 /* an id of zero is taken to mean "sync whole filesystem" */
1920 rc = fsfilt_sync(obd, mds->mds_sb);
1924 /* just any file to grab fsync method - "file" arg unused */
1925 struct file *file = mds->mds_rcvd_filp;
1926 struct mds_body *rep_body;
1929 de = mds_id2dentry(obd, &body->id1, NULL);
1931 GOTO(out, rc = PTR_ERR(de));
1933 rc = file->f_op->fsync(NULL, de, 1);
1937 rep_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_body));
1938 mds_pack_inode2body(obd, rep_body, de->d_inode,
1939 (body->valid & OBD_MD_FID) ? 1 : 0);
1945 req->rq_status = rc;
1949 /* mds_readpage does not take a DLM lock on the inode, because the client must
1950 * already have a PR lock.
1952 * If we were to take another one here, a deadlock will result, if another
1953 * thread is already waiting for a PW lock. */
1954 static int mds_readpage(struct ptlrpc_request *req, int offset)
1956 struct obd_device *obd = req->rq_export->exp_obd;
1957 struct vfsmount *mnt;
1960 struct mds_req_sec_desc *rsd;
1961 struct mds_body *body, *repbody;
1962 struct lvfs_run_ctxt saved;
1963 int rc, size = sizeof(*repbody);
1964 struct lvfs_ucred uc = {NULL, NULL,};
1967 rc = lustre_pack_reply(req, 1, &size, NULL);
1968 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1969 CERROR("mds: out of memory\n");
1970 GOTO(out, rc = -ENOMEM);
1973 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1975 CERROR("Can't unpack security desc\n");
1976 GOTO (out, rc = -EFAULT);
1979 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1980 lustre_swab_mds_body);
1982 CERROR("Can't unpack body\n");
1983 GOTO (out, rc = -EFAULT);
1986 rc = mds_init_ucred(&uc, req, rsd);
1988 mds_audit_auth(req, &uc, AUDIT_READDIR, &body->id1,
1993 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1994 de = mds_id2dentry(obd, &body->id1, &mnt);
1996 GOTO(out_pop, rc = PTR_ERR(de));
1998 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
2000 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
2001 /* note: in case of an error, dentry_open puts dentry */
2003 GOTO(out_pop, rc = PTR_ERR(file));
2005 /* body->size is actually the offset -eeb */
2006 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
2007 CERROR("offset "LPU64" not on a block boundary of %lu\n",
2008 body->size, de->d_inode->i_blksize);
2009 GOTO(out_file, rc = -EFAULT);
2012 /* body->nlink is actually the #bytes to read -eeb */
2013 if (body->nlink & (de->d_inode->i_blksize - 1)) {
2014 CERROR("size %u is not multiple of blocksize %lu\n",
2015 body->nlink, de->d_inode->i_blksize);
2016 GOTO(out_file, rc = -EFAULT);
2019 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
2020 repbody->size = file->f_dentry->d_inode->i_size;
2021 repbody->valid = OBD_MD_FLSIZE;
2023 /* to make this asynchronous make sure that the handling function
2024 doesn't send a reply when this function completes. Instead a
2025 callback function would send the reply */
2026 /* body->size is actually the offset -eeb */
2027 rc = mds_sendpage(req, file, body->size, body->nlink);
2031 filp_close(file, 0);
2033 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2035 mds_exit_ucred(&uc);
2036 req->rq_status = rc;
2040 int mds_read_md(struct obd_device *obd, struct lustre_id *id,
2041 char **data, int *datalen)
2043 struct dentry *dentry;
2044 struct mds_obd *mds = &obd->u.mds;
2045 int rc = 0, mea = 0;
2052 dentry = mds_id2dentry(obd, id, NULL);
2054 GOTO(out, rc = PTR_ERR(dentry));
2056 if (!dentry->d_inode) {
2057 CERROR("Can't find object "DLID4".\n",
2059 GOTO(out_dentry, rc = -EINVAL);
2061 if (S_ISDIR(dentry->d_inode->i_mode)) {
2062 *datalen = obd_packmd(mds->mds_md_exp, NULL, NULL);
2065 *datalen = obd_packmd(mds->mds_dt_exp, NULL, NULL);
2068 OBD_ALLOC(ea, *datalen);
2071 GOTO(out_dentry, rc = PTR_ERR(dentry));
2074 down(&dentry->d_inode->i_sem);
2075 rc = fsfilt_get_md(obd, dentry->d_inode, *data, *datalen,
2076 (mea ? EA_MEA : EA_LOV));
2077 up(&dentry->d_inode->i_sem);
2080 CERROR("Error %d reading eadata for ino %lu\n",
2081 rc, dentry->d_inode->i_ino);
2087 EXPORT_SYMBOL(mds_read_md);
2089 int mds_reint(struct ptlrpc_request *req, int offset,
2090 struct lustre_handle *lockh)
2092 struct mds_update_record *rec;
2093 struct mds_req_sec_desc *rsd;
2097 OBD_ALLOC(rec, sizeof(*rec));
2101 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
2103 CERROR("Can't unpack security desc\n");
2104 GOTO(out, rc = -EFAULT);
2107 rc = mds_update_unpack(req, offset, rec);
2108 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
2109 CERROR("invalid record\n");
2110 GOTO(out, req->rq_status = -EINVAL);
2113 rc = mds_init_ucred(&rec->ur_uc, req, rsd);
2115 mds_audit_reint(req, rec);
2119 /* rc will be used to interrupt a for loop over multiple records */
2120 rc = mds_reint_rec(rec, offset, req, lockh);
2123 mds_exit_ucred(&rec->ur_uc);
2124 OBD_FREE(rec, sizeof(*rec));
2128 static int mds_filter_recovery_request(struct ptlrpc_request *req,
2129 struct obd_device *obd, int *process)
2131 switch (req->rq_reqmsg->opc) {
2132 case MDS_CONNECT: /* This will never get here, but for completeness. */
2133 case OST_CONNECT: /* This will never get here, but for completeness. */
2134 case MDS_DISCONNECT:
2135 case OST_DISCONNECT:
2140 case MDS_SYNC: /* used in unmounting */
2145 *process = target_queue_recovery_request(req, obd);
2149 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2151 /* XXX what should we set rq_status to here? */
2152 req->rq_status = -EAGAIN;
2153 RETURN(ptlrpc_error(req));
2157 static char *reint_names[] = {
2158 [REINT_SETATTR] "setattr",
2159 [REINT_CREATE] "create",
2160 [REINT_LINK] "link",
2161 [REINT_UNLINK] "unlink",
2162 [REINT_RENAME] "rename",
2163 [REINT_OPEN] "open",
2166 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER | \
2167 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ| \
2168 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME| \
2171 static void reconstruct_create(struct ptlrpc_request *req)
2173 struct mds_export_data *med = &req->rq_export->exp_mds_data;
2174 struct mds_client_data *mcd = med->med_mcd;
2175 struct dentry *dentry;
2176 struct ost_body *body;
2177 struct lustre_id id;
2181 /* copy rc, transno and disp; steal locks */
2182 mds_req_from_mcd(req, mcd);
2183 if (req->rq_status) {
2191 id_ino(&id) = mcd->mcd_last_data;
2192 LASSERT(id_ino(&id) != 0);
2194 dentry = mds_id2dentry(req2obd(req), &id, NULL);
2195 if (IS_ERR(dentry)) {
2196 CERROR("can't find inode "LPU64"\n", id_ino(&id));
2197 req->rq_status = PTR_ERR(dentry);
2202 CWARN("reconstruct reply for x"LPU64" (remote ino) "LPU64" -> %lu/%u\n",
2203 req->rq_xid, id_ino(&id), dentry->d_inode->i_ino,
2204 dentry->d_inode->i_generation);
2206 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
2207 obdo_from_inode(&body->oa, dentry->d_inode, FILTER_VALID_FLAGS);
2208 body->oa.o_id = dentry->d_inode->i_ino;
2209 body->oa.o_generation = dentry->d_inode->i_generation;
2210 body->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2212 down(&dentry->d_inode->i_sem);
2213 rc = mds_read_inode_sid(req2obd(req), dentry->d_inode, &id);
2214 up(&dentry->d_inode->i_sem);
2216 CERROR("Can't read inode self id, inode %lu, "
2217 "rc %d\n", dentry->d_inode->i_ino, rc);
2221 body->oa.o_fid = id_fid(&id);
2222 body->oa.o_mds = id_group(&id);
2228 static int mds_inode_init_acl(struct obd_device *obd, void *handle,
2229 struct dentry *de, void *xattr, int xattr_size)
2231 struct inode *inode = de->d_inode;
2232 struct posix_acl *acl;
2239 LASSERT(xattr_size > 0);
2241 if (!inode->i_op->getxattr || !inode->i_op->setxattr) {
2242 CERROR("backend fs dosen't support xattr\n");
2246 /* set default acl */
2247 if (S_ISDIR(inode->i_mode)) {
2248 rc = inode->i_op->setxattr(de, XATTR_NAME_ACL_DEFAULT,
2249 xattr, xattr_size, 0);
2251 CERROR("set default acl err: %d\n", rc);
2256 /* set access acl */
2257 acl = posix_acl_from_xattr(xattr, xattr_size);
2258 if (acl == NULL || IS_ERR(acl)) {
2259 CERROR("insane attr data\n");
2260 return PTR_ERR(acl);
2263 if (posix_acl_valid(acl)) {
2264 CERROR("default acl not valid: %d\n", rc);
2269 mode = inode->i_mode;
2270 rc = posix_acl_create_masq(acl, &mode);
2272 CERROR("create masq err %d\n", rc);
2276 if (inode->i_mode != mode) {
2277 struct iattr iattr = { .ia_valid = ATTR_MODE,
2281 rc2 = fsfilt_setattr(obd, de, handle, &iattr, 0);
2283 CERROR("setattr mode err: %d\n", rc2);
2290 /* we didn't change acl except mode bits of some
2291 * entries, so should be fit into original size.
2293 rc = posix_acl_to_xattr(acl, xattr, xattr_size);
2296 rc = inode->i_op->setxattr(de, XATTR_NAME_ACL_ACCESS,
2297 xattr, xattr_size, 0);
2299 CERROR("set access acl err: %d\n", rc);
2302 posix_acl_release(acl);
2306 static int mdt_obj_create(struct ptlrpc_request *req)
2308 struct obd_device *obd = req->rq_export->exp_obd;
2309 struct mds_obd *mds = &obd->u.mds;
2310 struct ost_body *body, *repbody;
2313 char idname[LL_ID_NAMELEN];
2314 int size = sizeof(*repbody);
2315 struct inode *parent_inode;
2316 struct lvfs_run_ctxt saved;
2317 int rc, cleanup_phase = 0;
2318 struct dentry *new = NULL;
2319 struct dentry_params dp;
2320 int mealen, flags = 0;
2321 struct lvfs_ucred uc;
2322 struct lustre_id id;
2324 void *handle = NULL;
2325 unsigned long cr_inum = 0;
2329 DEBUG_REQ(D_HA, req, "create remote object");
2330 parent_inode = mds->mds_unnamed_dir->d_inode;
2332 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
2333 lustre_swab_ost_body);
2337 /* acl data is packed transparently, no swab here */
2338 LASSERT(req->rq_reqmsg->bufcount >= 2);
2339 acl_size = req->rq_reqmsg->buflens[1];
2341 acl = lustre_msg_buf(req->rq_reqmsg, 1, acl_size);
2343 CERROR("No default acl buf?\n");
2348 rc = lustre_pack_reply(req, 1, &size, NULL);
2352 MDS_CHECK_RESENT(req, reconstruct_create(req));
2355 uc.luc_ginfo = NULL;
2356 uc.luc_uid = body->oa.o_uid;
2357 uc.luc_gid = body->oa.o_gid;
2358 uc.luc_fsuid = body->oa.o_uid;
2359 uc.luc_fsgid = body->oa.o_gid;
2361 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2362 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
2364 /* in REPLAY case inum should be given (client or other MDS fills it) */
2365 if (body->oa.o_id && ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2366 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY))) {
2368 * this is re-create request from MDS holding directory name.
2369 * we have to lookup given ino/gen first. if it exists (good
2370 * case) then there is nothing to do. if it does not then we
2371 * have to recreate it.
2373 id_ino(&id) = body->oa.o_id;
2374 id_gen(&id) = body->oa.o_generation;
2376 new = mds_id2dentry(obd, &id, NULL);
2377 if (!IS_ERR(new) && new->d_inode) {
2378 struct lustre_id sid;
2380 CDEBUG(D_OTHER, "mkdir repairing %lu/%lu\n",
2381 (unsigned long)id_ino(&id),
2382 (unsigned long)id_gen(&id));
2384 obdo_from_inode(&repbody->oa, new->d_inode,
2385 FILTER_VALID_FLAGS);
2387 repbody->oa.o_id = new->d_inode->i_ino;
2388 repbody->oa.o_generation = new->d_inode->i_generation;
2389 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2392 down(&new->d_inode->i_sem);
2393 rc = mds_read_inode_sid(obd, new->d_inode, &sid);
2394 up(&new->d_inode->i_sem);
2396 CERROR("Can't read inode self id "
2397 "inode %lu, rc %d.\n",
2398 new->d_inode->i_ino, rc);
2402 repbody->oa.o_fid = id_fid(&sid);
2403 repbody->oa.o_mds = id_group(&sid);
2404 LASSERT(id_fid(&sid) != 0);
2407 * here we could use fid passed in body->oa.o_fid and
2408 * thus avoid mds_read_inode_sid().
2410 cr_inum = new->d_inode->i_ino;
2411 GOTO(cleanup, rc = 0);
2415 down(&parent_inode->i_sem);
2416 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
2417 if (IS_ERR(handle)) {
2418 up(&parent_inode->i_sem);
2419 CERROR("fsfilt_start() failed, rc = %d\n",
2420 (int)PTR_ERR(handle));
2421 GOTO(cleanup, rc = PTR_ERR(handle));
2423 cleanup_phase = 1; /* transaction */
2426 rc = sprintf(idname, "%u.%u", ll_insecure_random_int(), current->pid);
2427 new = lookup_one_len(idname, mds->mds_unnamed_dir, rc);
2429 CERROR("%s: can't lookup new inode (%s) for mkdir: %d\n",
2430 obd->obd_name, idname, (int) PTR_ERR(new));
2431 fsfilt_commit(obd, mds->mds_sb, new->d_inode, handle, 0);
2432 up(&parent_inode->i_sem);
2433 RETURN(PTR_ERR(new));
2434 } else if (new->d_inode) {
2435 CERROR("%s: name exists. repeat\n", obd->obd_name);
2438 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2439 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2440 fid = body->oa.o_fid;
2442 fid = mds_alloc_fid(obd);
2444 new->d_fsdata = (void *)&dp;
2449 dp.p_group = mds->mds_num;
2451 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) ||
2452 (body->oa.o_flags & OBD_FL_RECREATE_OBJS)) {
2453 LASSERT(body->oa.o_id != 0);
2454 dp.p_inum = body->oa.o_id;
2455 DEBUG_REQ(D_HA, req, "replay create obj %lu/%lu",
2456 (unsigned long)body->oa.o_id,
2457 (unsigned long)body->oa.o_generation);
2460 rc = vfs_mkdir(parent_inode, new, body->oa.o_mode);
2463 rc = mds_inode_init_acl(obd, handle, new,
2466 up(&parent_inode->i_sem);
2470 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2471 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2472 new->d_inode->i_generation = body->oa.o_generation;
2473 mark_inode_dirty(new->d_inode);
2476 * avoiding asserts in cache flush case, as
2477 * @body->oa.o_id should be zero.
2479 if (body->oa.o_id) {
2480 LASSERTF(body->oa.o_id == new->d_inode->i_ino,
2481 "BUG 3550: failed to recreate obj "
2482 LPU64" -> %lu\n", body->oa.o_id,
2483 new->d_inode->i_ino);
2485 LASSERTF(body->oa.o_generation ==
2486 new->d_inode->i_generation,
2487 "BUG 3550: failed to recreate obj/gen "
2488 LPU64"/%u -> %lu/%u\n", body->oa.o_id,
2489 body->oa.o_generation,
2490 new->d_inode->i_ino,
2491 new->d_inode->i_generation);
2495 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
2496 repbody->oa.o_id = new->d_inode->i_ino;
2497 repbody->oa.o_generation = new->d_inode->i_generation;
2498 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FID;
2500 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2501 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2502 LASSERT(body->oa.o_id != 0);
2503 LASSERT(body->oa.o_fid != 0);
2506 mds_inode2id(obd, &id, new->d_inode, fid);
2507 mds_update_inode_ids(obd, new->d_inode, handle, &id,
2508 body->oa.o_valid & OBD_MD_FLID ?
2509 NULL : obdo_id(&body->oa));
2511 /* initializing o_fid after it is allocated. */
2512 repbody->oa.o_fid = id_fid(&id);
2513 repbody->oa.o_mds = id_group(&id);
2515 rc = fsfilt_del_dir_entry(obd, new);
2516 up(&parent_inode->i_sem);
2518 CERROR("can't remove name for object: %d\n", rc);
2522 cleanup_phase = 2; /* created directory object */
2524 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
2525 (unsigned long)new->d_inode->i_ino,
2526 (unsigned long)new->d_inode->i_generation,
2527 (unsigned)new->d_inode->i_mode);
2528 cr_inum = new->d_inode->i_ino;
2530 up(&parent_inode->i_sem);
2531 CERROR("%s: can't create dirobj: %d\n", obd->obd_name, rc);
2535 if (body->oa.o_valid & OBD_MD_FLID) {
2536 /* this is new object for splitted dir. We have to prevent
2537 * recursive splitting on it -bzzz */
2538 mealen = obd_size_diskmd(mds->mds_md_exp, NULL);
2540 OBD_ALLOC(mea, mealen);
2542 GOTO(cleanup, rc = -ENOMEM);
2544 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2545 mea->mea_master = body->oa.o_mds; /* master mds num */
2548 obdo2id(&mea->mea_ids[body->oa.o_mds], &body->oa);
2550 down(&new->d_inode->i_sem);
2551 rc = fsfilt_set_md(obd, new->d_inode, handle,
2552 mea, mealen, EA_MEA);
2553 up(&new->d_inode->i_sem);
2555 CERROR("fsfilt_set_md() failed, "
2558 OBD_FREE(mea, mealen);
2560 CDEBUG(D_OTHER, "%s: mark non-splittable %lu/%u - %d\n",
2561 obd->obd_name, new->d_inode->i_ino,
2562 new->d_inode->i_generation, flags);
2563 } else if (body->oa.o_easize) {
2564 /* we pass LCK_EX to split routine to signal that we have
2565 * exclusive access to the directory. simple because nobody
2566 * knows it already exists -bzzz */
2567 rc = mds_try_to_split_dir(obd, new, NULL,
2568 body->oa.o_easize, LCK_EX);
2570 CERROR("Can't split directory %lu, error = %d.\n",
2571 new->d_inode->i_ino, rc);
2579 if (rc == 0 && (body->oa.o_flags & OBD_FL_REINT)) {
2580 rc = mds_fidmap_add(obd, &id);
2582 CERROR("can't create fid->ino mapping, "
2589 switch (cleanup_phase) {
2590 case 2: /* object has been created, but we'll may want to replay it later */
2592 ptlrpc_require_repack(req);
2593 case 1: /* transaction */
2594 rc = mds_finish_transno(mds, parent_inode, handle,
2599 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2603 static int mdt_get_info(struct ptlrpc_request *req)
2605 struct obd_export *exp = req->rq_export;
2610 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2612 DEBUG_REQ(D_HA, req, "no get_info key");
2615 keylen = req->rq_reqmsg->buflens[0];
2617 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
2618 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
2619 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
2620 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
2621 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0))
2624 if (keylen >= strlen("rootid") && !strcmp(key, "rootid")) {
2625 struct lustre_id *reply;
2626 int size = sizeof(*reply);
2628 rc = lustre_pack_reply(req, 1, &size, NULL);
2632 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2633 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2634 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
2635 struct lov_desc *reply;
2636 int size = sizeof(*reply);
2638 rc = lustre_pack_reply(req, 1, &size, NULL);
2642 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2643 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2644 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
2645 struct fid_extent *reply;
2646 int size = sizeof(*reply);
2648 rc = lustre_pack_reply(req, 1, &size, NULL);
2652 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2653 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2656 int size = sizeof(*reply);
2658 rc = lustre_pack_reply(req, 1, &size, NULL);
2662 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2663 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2666 req->rq_repmsg->status = 0;
2670 static int mds_set_info(struct obd_export *exp, __u32 keylen,
2671 void *key, __u32 vallen, void *val)
2673 struct obd_device *obd;
2674 struct mds_obd *mds;
2678 obd = class_exp2obd(exp);
2680 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2681 exp->exp_handle.h_cookie);
2686 if (keylen == 5 && memcmp(key, "audit", 5) == 0) {
2687 rc = mds_set_audit(obd, val);
2689 } else if (keylen >= strlen("ids") && memcmp(key, "ids", keylen) == 0) {
2690 struct lustre_id *ids = (struct lustre_id *)val;
2692 struct inode *inode;
2696 de = mds_id2dentry(obd, ids, NULL);
2699 CERROR("lookup by an id error rc=%d\n ", rc);
2702 inode = de->d_inode;
2704 GOTO(out_put, rc = -ENOENT);
2706 down(&inode->i_sem);
2707 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
2708 if (IS_ERR(handle)) {
2710 GOTO(out_put, rc = PTR_ERR(handle));
2713 rc = mds_update_inode_ids(obd, inode, handle, NULL, ids + 1);
2715 err = fsfilt_commit(obd, mds->mds_sb, inode, handle,
2718 CERROR("error committing transaction: %d\n", err);
2727 if (keylen >= strlen("crypto_type") &&
2728 memcmp(key, "crypto_type", keylen) == 0) {
2729 rc = mds_set_crypto_type(obd, val, vallen);
2733 if (keylen >= strlen("setext") && !memcmp(key, "setext", keylen)) {
2734 struct fid_extent *ext = val;
2736 CDEBUG(D_IOCTL, "set last fid to extent ["LPD64"-"LPD64"]\n",
2737 ext->fe_start, ext->fe_width);
2739 /* set lastfid into fid extent start. All next object creates
2740 * will use that fid. */
2741 mds_set_last_fid(obd, ext->fe_start);
2743 /* setting the same extent to OSC to avoid ids intersecting in
2744 * object ids, as all cache MDSs have the same group 0. */
2745 rc = obd_set_info(mds->mds_dt_exp, strlen("setext"),
2746 "setext", sizeof(*ext), ext);
2748 CERROR("can't set extent ["LPD64"-"LPD64"] to %s, "
2749 "err %d\n", ext->fe_start, ext->fe_width,
2750 mds->mds_dt_exp->exp_obd->obd_name, rc);
2754 CDEBUG(D_IOCTL, "invalid key\n");
2758 static int mdt_set_info(struct ptlrpc_request *req)
2761 struct obd_export *exp = req->rq_export;
2762 int keylen, rc = 0, vallen = 0;
2765 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2767 DEBUG_REQ(D_HA, req, "no set_info key");
2770 keylen = req->rq_reqmsg->buflens[0];
2772 if ((keylen == strlen("crypto_type") &&
2773 memcmp(key, "crypto_type", keylen) == 0)) {
2774 rc = lustre_pack_reply(req, 0, NULL, NULL);
2778 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2779 vallen = req->rq_reqmsg->buflens[1];
2781 rc = obd_set_info(exp, keylen, key, vallen, val);
2782 req->rq_repmsg->status = 0;
2784 } else if (keylen == 5 && memcmp(key, "audit", 5) == 0) {
2785 struct audit_attr_msg msg, *p;
2788 rc = lustre_pack_reply(req, 0, NULL, NULL);
2792 p = lustre_swab_reqbuf(req, 1, sizeof(msg),
2793 lustre_swab_audit_attr);
2796 //CDEBUG(D_INFO, "Get new audit setting 0x%x\n", (__u32)msg.attr);
2797 rc = obd_set_info(exp, keylen, key, sizeof(msg), &msg);
2799 req->rq_repmsg->status = rc;
2801 } else if (keylen == strlen("ids") &&
2802 memcmp(key, "ids", keylen) == 0) {
2803 struct lustre_id *id, ids[2];
2805 rc = lustre_pack_reply(req, 0, NULL, NULL);
2808 id = lustre_swab_reqbuf(req, 1, sizeof(struct lustre_id),
2809 lustre_swab_lustre_id);
2811 id = lustre_swab_reqbuf(req, 2, sizeof(struct lustre_id),
2812 lustre_swab_lustre_id);
2815 rc = obd_set_info(exp, keylen, key, vallen, ids);
2816 req->rq_repmsg->status = rc;
2818 } else if (keylen == strlen("setext") &&
2819 memcmp(key, "setext", keylen) == 0) {
2820 rc = lustre_pack_reply(req, 0, NULL, NULL);
2824 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2825 vallen = req->rq_reqmsg->buflens[1];
2827 rc = obd_set_info(exp, keylen, key, vallen, val);
2828 req->rq_repmsg->status = 0;
2832 CDEBUG(D_IOCTL, "invalid key\n");
2836 static void mds_revoke_export_locks(struct obd_export *exp)
2838 struct list_head *locklist = &exp->exp_ldlm_data.led_held_locks;
2839 struct list_head rpc_list;
2840 struct ldlm_lock *lock, *next;
2841 struct ldlm_lock_desc desc;
2843 /* don't do this for local client */
2844 if (!exp->u.eu_mds_data.med_remote)
2847 /* don't revoke locks during recovery */
2848 if (exp->exp_obd->obd_recovering)
2852 INIT_LIST_HEAD(&rpc_list);
2854 spin_lock(&exp->exp_ldlm_data.led_lock);
2855 list_for_each_entry_safe(lock, next, locklist, l_export_chain) {
2857 lock_res_and_lock(lock);
2858 if (lock->l_req_mode != lock->l_granted_mode) {
2859 unlock_res_and_lock(lock);
2863 LASSERT(lock->l_resource);
2864 if (lock->l_resource->lr_type != LDLM_IBITS &&
2865 lock->l_resource->lr_type != LDLM_PLAIN) {
2866 unlock_res_and_lock(lock);
2870 if (lock->l_flags & LDLM_FL_AST_SENT) {
2871 unlock_res_and_lock(lock);
2875 LASSERT(lock->l_blocking_ast);
2876 LASSERT(!lock->l_blocking_lock);
2878 lock->l_flags |= LDLM_FL_AST_SENT;
2879 unlock_res_and_lock(lock);
2881 list_move(&lock->l_export_chain, &rpc_list);
2883 spin_unlock(&exp->exp_ldlm_data.led_lock);
2885 while (!list_empty(&rpc_list)) {
2886 lock = list_entry(rpc_list.next, struct ldlm_lock,
2888 list_del_init(&lock->l_export_chain);
2890 /* the desc just pretend to exclusive */
2891 ldlm_lock2desc(lock, &desc);
2892 desc.l_req_mode = LCK_EX;
2893 desc.l_granted_mode = 0;
2895 lock->l_blocking_ast(lock, &desc, NULL, LDLM_CB_BLOCKING);
2900 static int mds_msg_check_version(struct lustre_msg *msg)
2906 case MDS_DISCONNECT:
2908 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2910 CERROR("bad opc %u version %08x, expecting %08x\n",
2911 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2916 case MDS_GETATTR_LOCK:
2917 case MDS_ACCESS_CHECK:
2921 case MDS_DONE_WRITING:
2925 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2927 CERROR("bad opc %u version %08x, expecting %08x\n",
2928 msg->opc, msg->version, LUSTRE_MDS_VERSION);
2932 case LDLM_BL_CALLBACK:
2933 case LDLM_CP_CALLBACK:
2934 case LDLM_FLK_DEADLOCK_CHK:
2935 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2937 CERROR("bad opc %u version %08x, expecting %08x\n",
2938 msg->opc, msg->version, LUSTRE_DLM_VERSION);
2940 case OBD_LOG_CANCEL:
2941 case LLOG_ORIGIN_HANDLE_OPEN:
2942 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2943 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2944 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2945 case LLOG_ORIGIN_HANDLE_CLOSE:
2947 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2949 CERROR("bad opc %u version %08x, expecting %08x\n",
2950 msg->opc, msg->version, LUSTRE_LOG_VERSION);
2956 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2958 CERROR("bad opc %u version %08x, expecting %08x\n",
2959 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2962 case SEC_INIT_CONTINUE:
2967 CERROR("MDS unknown opcode %d\n", msg->opc);
2975 int mds_handle(struct ptlrpc_request *req)
2977 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
2978 struct obd_device *obd = NULL;
2979 struct mds_obd *mds = NULL; /* quell gcc overwarning */
2983 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2985 rc = mds_msg_check_version(req->rq_reqmsg);
2987 CERROR("MDS drop mal-formed request\n");
2991 /* Security opc should NOT trigger any recovery events */
2992 if (req->rq_reqmsg->opc == SEC_INIT ||
2993 req->rq_reqmsg->opc == SEC_INIT_CONTINUE) {
2994 if (req->rq_export) {
2995 mds_req_add_idmapping(req,
2996 &req->rq_export->exp_mds_data);
2997 mds_revoke_export_locks(req->rq_export);
3000 } else if (req->rq_reqmsg->opc == SEC_FINI) {
3001 if (req->rq_export) {
3002 mds_req_del_idmapping(req,
3003 &req->rq_export->exp_mds_data);
3004 mds_revoke_export_locks(req->rq_export);
3009 LASSERT(current->journal_info == NULL);
3010 /* XXX identical to OST */
3011 if (req->rq_reqmsg->opc != MDS_CONNECT) {
3012 struct mds_export_data *med;
3015 if (req->rq_export == NULL) {
3016 CERROR("operation %d on unconnected MDS from %s\n",
3017 req->rq_reqmsg->opc,
3019 req->rq_status = -ENOTCONN;
3020 GOTO(out, rc = -ENOTCONN);
3023 med = &req->rq_export->exp_mds_data;
3024 obd = req->rq_export->exp_obd;
3027 /* sanity check: if the xid matches, the request must
3028 * be marked as a resent or replayed */
3029 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
3030 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid)) {
3031 LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
3032 (MSG_RESENT | MSG_REPLAY),
3033 "rq_xid "LPU64" matches last_xid, "
3034 "expected RESENT flag\n",
3037 /* else: note the opposite is not always true; a
3038 * RESENT req after a failover will usually not match
3039 * the last_xid, since it was likely never
3040 * committed. A REPLAYed request will almost never
3041 * match the last xid, however it could for a
3042 * committed, but still retained, open. */
3044 spin_lock_bh(&obd->obd_processing_task_lock);
3045 recovering = obd->obd_recovering;
3046 spin_unlock_bh(&obd->obd_processing_task_lock);
3048 rc = mds_filter_recovery_request(req, obd,
3050 if (rc || should_process == 0) {
3052 } else if (should_process < 0) {
3053 req->rq_status = should_process;
3054 rc = ptlrpc_error(req);
3060 switch (req->rq_reqmsg->opc) {
3062 DEBUG_REQ(D_INODE, req, "connect");
3063 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
3064 rc = target_handle_connect(req);
3066 struct mds_export_data *med;
3068 LASSERT(req->rq_export);
3069 med = &req->rq_export->u.eu_mds_data;
3070 mds_init_export_data(req, med);
3071 mds_req_add_idmapping(req, med);
3073 /* Now that we have an export, set mds. */
3074 obd = req->rq_export->exp_obd;
3075 mds = mds_req2mds(req);
3079 case MDS_DISCONNECT:
3080 DEBUG_REQ(D_INODE, req, "disconnect");
3081 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
3082 rc = target_handle_disconnect(req);
3083 req->rq_status = rc; /* superfluous? */
3087 DEBUG_REQ(D_INODE, req, "getstatus");
3088 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
3089 rc = mds_getstatus(req);
3093 DEBUG_REQ(D_INODE, req, "getattr");
3094 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
3095 rc = mds_getattr(req, MDS_REQ_REC_OFF);
3098 case MDS_ACCESS_CHECK:
3099 DEBUG_REQ(D_INODE, req, "access_check");
3100 OBD_FAIL_RETURN(OBD_FAIL_MDS_ACCESS_CHECK_NET, 0);
3101 rc = mds_access_check(req, MDS_REQ_REC_OFF);
3104 case MDS_GETATTR_LOCK: {
3105 struct lustre_handle lockh;
3106 DEBUG_REQ(D_INODE, req, "getattr_lock");
3107 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_LOCK_NET, 0);
3109 /* If this request gets a reconstructed reply, we won't be
3110 * acquiring any new locks in mds_getattr_lock, so we don't
3114 rc = mds_getattr_lock(req, MDS_REQ_REC_OFF, &lockh,
3115 MDS_INODELOCK_UPDATE);
3116 /* this non-intent call (from an ioctl) is special */
3117 req->rq_status = rc;
3118 if (rc == 0 && lockh.cookie)
3119 ldlm_lock_decref(&lockh, LCK_PR);
3123 DEBUG_REQ(D_INODE, req, "statfs");
3124 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
3125 rc = mds_statfs(req);
3129 DEBUG_REQ(D_INODE, req, "readpage");
3130 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
3131 rc = mds_readpage(req, MDS_REQ_REC_OFF);
3133 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
3134 if (req->rq_reply_state) {
3135 lustre_free_reply_state (req->rq_reply_state);
3136 req->rq_reply_state = NULL;
3143 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
3146 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
3147 mds->mds_max_cookiesize};
3150 /* NB only peek inside req now; mds_reint() will swab it */
3152 CERROR ("Can't inspect opcode\n");
3157 if (lustre_msg_swabbed (req->rq_reqmsg))
3160 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
3161 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
3162 reint_names[opc] == NULL) ? reint_names[opc] :
3165 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
3167 if (opc == REINT_UNLINK || opc == REINT_RENAME)
3169 else if (opc == REINT_OPEN)
3174 /* for SETATTR: I have different reply setting for
3175 * remote setfacl, so delay the reply buffer allocation.
3177 if (opc != REINT_SETATTR) {
3178 rc = lustre_pack_reply(req, bufcount, size, NULL);
3183 rc = mds_reint(req, MDS_REQ_REC_OFF, NULL);
3184 fail = OBD_FAIL_MDS_REINT_NET_REP;
3189 DEBUG_REQ(D_INODE, req, "close");
3190 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
3191 rc = mds_close(req, MDS_REQ_REC_OFF);
3194 case MDS_DONE_WRITING:
3195 DEBUG_REQ(D_INODE, req, "done_writing");
3196 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
3197 rc = mds_done_writing(req, MDS_REQ_REC_OFF);
3201 DEBUG_REQ(D_INODE, req, "pin");
3202 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
3203 rc = mds_pin(req, MDS_REQ_REC_OFF);
3207 DEBUG_REQ(D_INODE, req, "sync");
3208 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
3209 rc = mds_sync(req, MDS_REQ_REC_OFF);
3212 DEBUG_REQ(D_INODE, req, "parseid");
3213 rc = mds_parse_id(req);
3216 DEBUG_REQ(D_INODE, req, "ping");
3217 rc = target_handle_ping(req);
3220 case OBD_LOG_CANCEL:
3221 CDEBUG(D_INODE, "log cancel\n");
3222 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
3223 rc = -ENOTSUPP; /* la la la */
3227 DEBUG_REQ(D_INODE, req, "enqueue");
3228 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
3229 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
3230 ldlm_server_blocking_ast, NULL);
3231 fail = OBD_FAIL_LDLM_REPLY;
3234 DEBUG_REQ(D_INODE, req, "convert");
3235 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
3236 rc = ldlm_handle_convert(req);
3238 case LDLM_BL_CALLBACK:
3239 case LDLM_CP_CALLBACK:
3240 DEBUG_REQ(D_INODE, req, "callback");
3241 CERROR("callbacks should not happen on MDS\n");
3243 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
3245 case LDLM_FLK_DEADLOCK_CHK:
3246 DEBUG_REQ(D_INODE, req, "flock deadlock check");
3247 rc = ldlm_handle_flock_deadlock_check(req);
3249 case LLOG_ORIGIN_HANDLE_OPEN:
3250 DEBUG_REQ(D_INODE, req, "llog_init");
3251 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3252 rc = llog_origin_handle_open(req);
3254 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3255 DEBUG_REQ(D_INODE, req, "llog next block");
3256 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3257 rc = llog_origin_handle_next_block(req);
3259 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3260 DEBUG_REQ(D_INODE, req, "llog prev block");
3261 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3262 rc = llog_origin_handle_prev_block(req);
3264 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3265 DEBUG_REQ(D_INODE, req, "llog read header");
3266 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3267 rc = llog_origin_handle_read_header(req);
3269 case LLOG_ORIGIN_HANDLE_CLOSE:
3270 DEBUG_REQ(D_INODE, req, "llog close");
3271 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3272 rc = llog_origin_handle_close(req);
3275 DEBUG_REQ(D_INODE, req, "ost_create");
3276 rc = mdt_obj_create(req);
3279 DEBUG_REQ(D_INODE, req, "get_info");
3280 rc = mdt_get_info(req);
3283 DEBUG_REQ(D_INODE, req, "set_info");
3284 rc = mdt_set_info(req);
3287 CDEBUG(D_INODE, "write\n");
3288 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
3289 rc = ost_brw_write(req, NULL);
3290 LASSERT(current->journal_info == NULL);
3291 /* mdt_brw sends its own replies */
3295 DEBUG_REQ(D_INODE, req, "llog catinfo");
3296 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3297 rc = llog_catinfo(req);
3300 req->rq_status = -ENOTSUPP;
3301 rc = ptlrpc_error(req);
3305 LASSERT(current->journal_info == NULL);
3307 /* If we're DISCONNECTing, the mds_export_data is already freed */
3308 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
3309 struct mds_export_data *med = &req->rq_export->exp_mds_data;
3310 struct obd_device *obd = list_entry(mds, struct obd_device,
3312 req->rq_repmsg->last_xid =
3313 le64_to_cpu(med->med_mcd->mcd_last_xid);
3315 if (!obd->obd_no_transno) {
3316 req->rq_repmsg->last_committed =
3317 obd->obd_last_committed;
3319 DEBUG_REQ(D_IOCTL, req,
3320 "not sending last_committed update");
3322 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
3324 mds->mds_last_transno, obd->obd_last_committed,
3330 target_send_reply(req, rc, fail);
3334 /* Update the server data on disk. This stores the new mount_count and also the
3335 * last_rcvd value to disk. If we don't have a clean shutdown, then the server
3336 * last_rcvd value may be less than that of the clients. This will alert us
3337 * that we may need to do client recovery.
3339 * Also assumes for mds_last_transno that we are not modifying it (no locking).
3341 int mds_update_server_data(struct obd_device *obd, int force_sync)
3343 struct mds_obd *mds = &obd->u.mds;
3344 struct mds_server_data *msd = mds->mds_server_data;
3345 struct file *filp = mds->mds_rcvd_filp;
3346 struct lvfs_run_ctxt saved;
3351 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3352 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
3354 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
3355 mds->mds_mount_count, mds->mds_last_transno);
3356 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off, force_sync);
3358 CERROR("error writing MDS server data: rc = %d\n", rc);
3359 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3364 /* saves last allocated fid counter to file. */
3365 int mds_update_last_fid(struct obd_device *obd, void *handle,
3368 struct mds_obd *mds = &obd->u.mds;
3369 struct file *filp = mds->mds_fid_filp;
3370 struct lvfs_run_ctxt saved;
3376 spin_lock(&mds->mds_last_fid_lock);
3377 last_fid = mds->mds_last_fid;
3378 spin_unlock(&mds->mds_last_fid_lock);
3380 CDEBUG(D_SUPER, "MDS last_fid is #"LPU64"\n",
3384 fsfilt_add_journal_cb(obd, mds->mds_sb, last_fid,
3385 handle, mds_commit_last_fid_cb,
3389 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3390 rc = fsfilt_write_record(obd, filp, &last_fid, sizeof(last_fid),
3392 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3395 CERROR("error writing MDS last_fid #"LPU64
3396 ", err = %d\n", last_fid, rc);
3400 CDEBUG(D_SUPER, "wrote fid #"LPU64" at idx "
3401 "%llu: err = %d\n", last_fid, off, rc);
3406 void mds_set_last_fid(struct obd_device *obd, __u64 fid)
3408 struct mds_obd *mds = &obd->u.mds;
3410 spin_lock(&mds->mds_last_fid_lock);
3411 if (fid > mds->mds_last_fid)
3412 mds->mds_last_fid = fid;
3413 spin_unlock(&mds->mds_last_fid_lock);
3416 void mds_commit_last_transno_cb(struct obd_device *obd,
3417 __u64 transno, void *data,
3420 obd_transno_commit_cb(obd, transno, error);
3423 void mds_commit_last_fid_cb(struct obd_device *obd,
3424 __u64 fid, void *data,
3428 CERROR("%s: fid "LPD64" commit error: %d\n",
3429 obd->obd_name, fid, error);
3433 CDEBUG(D_HA, "%s: fid "LPD64" committed\n",
3434 obd->obd_name, fid);
3437 __u64 mds_alloc_fid(struct obd_device *obd)
3439 struct mds_obd *mds = &obd->u.mds;
3442 spin_lock(&mds->mds_last_fid_lock);
3443 fid = ++mds->mds_last_fid;
3444 spin_unlock(&mds->mds_last_fid_lock);
3450 * reads inode self id from inode EA. Probably later this should be replaced by
3451 * caching inode self id to avoid raeding it every time it is needed.
3453 int mds_read_inode_sid(struct obd_device *obd, struct inode *inode,
3454 struct lustre_id *id)
3459 LASSERT(id != NULL);
3460 LASSERT(obd != NULL);
3461 LASSERT(inode != NULL);
3463 rc = fsfilt_get_md(obd, inode, &id->li_fid,
3464 sizeof(id->li_fid), EA_SID);
3466 CERROR("fsfilt_get_md() failed, "
3475 id_ino(id) = inode->i_ino;
3476 id_gen(id) = inode->i_generation;
3477 id_type(id) = S_IFMT & inode->i_mode;
3482 int mds_read_inode_pid(struct obd_device *obd, struct inode *inode,
3483 struct lustre_id *id)
3488 LASSERT(inode && id);
3490 rc = fsfilt_get_md(obd, inode, id, sizeof(*id), EA_PID);
3492 CERROR("get parent id from EA failed, rc=%d\n", rc);
3501 /* updates inode self id in EA. */
3502 int mds_update_inode_ids(struct obd_device *obd, struct inode *inode,
3503 void *handle, struct lustre_id *id,
3504 struct lustre_id *pid)
3510 LASSERT(id == NULL || id_fid(id) != 0);
3511 LASSERT(pid == NULL || id_fid(pid) != 0);
3512 LASSERT(obd != NULL);
3513 LASSERT(inode != NULL);
3516 mds_set_last_fid(obd, id_fid(id));
3517 rc = fsfilt_set_md(obd, inode, handle, &id->li_fid,
3518 sizeof(id->li_fid), EA_SID);
3519 LASSERTF(rc == 0, "failed to update fid: %d\n", rc);
3522 rc = fsfilt_set_md(obd, inode, handle, pid,
3523 sizeof(*pid), EA_PID);
3524 LASSERTF(rc == 0, "failed to update parent fid: %d\n", rc);
3530 /* mount the file system (secretly) */
3531 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
3533 struct lustre_cfg* lcfg = buf;
3534 struct mds_obd *mds = &obd->u.mds;
3535 struct lvfs_obd_ctxt *lvfs_ctxt = NULL;
3536 char *options = NULL;
3537 struct vfsmount *mnt;
3543 if (lcfg->lcfg_bufcount < 3)
3544 RETURN(rc = -EINVAL);
3546 if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0)
3547 RETURN(rc = -EINVAL);
3549 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
3550 if (IS_ERR(obd->obd_fsops))
3551 RETURN(rc = PTR_ERR(obd->obd_fsops));
3553 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
3555 page = get_zeroed_page(GFP_KERNEL);
3559 options = (char *)page;
3562 * here we use "iopen_nopriv" hardcoded, because it affects MDS utility
3563 * and the rest of options are passed by mount options. Probably this
3564 * should be moved to somewhere else like startup scripts or lconf. */
3565 sprintf(options, "iopen_nopriv");
3567 if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0 && lustre_cfg_buf(lcfg, 4))
3568 sprintf(options + strlen(options), ",%s",
3569 lustre_cfg_string(lcfg, 4));
3571 /* we have to know mdsnum before touching underlying fs -bzzz */
3572 atomic_set(&mds->mds_open_count, 0);
3573 sema_init(&mds->mds_md_sem, 1);
3574 mds->mds_md_connected = 0;
3575 mds->mds_md_name = NULL;
3577 if (LUSTRE_CFG_BUFLEN(lcfg, 5) > 0 && lustre_cfg_buf(lcfg, 5) &&
3578 strncmp(lustre_cfg_string(lcfg, 5), "dumb", LUSTRE_CFG_BUFLEN(lcfg, 5))) {
3581 generate_random_uuid(uuid);
3582 class_uuid_unparse(uuid, &mds->mds_md_uuid);
3584 OBD_ALLOC(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5));
3585 if (mds->mds_md_name == NULL)
3586 RETURN(rc = -ENOMEM);
3588 memcpy(mds->mds_md_name, lustre_cfg_buf(lcfg, 5),
3589 LUSTRE_CFG_BUFLEN(lcfg, 5));
3591 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
3592 obd->obd_name, mds->mds_md_name);
3594 rc = mds_md_connect(obd, mds->mds_md_name);
3596 OBD_FREE(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5));
3601 mds->mds_obd_type = MDS_MASTER_OBD;
3603 if (LUSTRE_CFG_BUFLEN(lcfg, 6) > 0 && lustre_cfg_buf(lcfg, 6) &&
3604 strncmp(lustre_cfg_string(lcfg, 6), "dumb",
3605 LUSTRE_CFG_BUFLEN(lcfg, 6))) {
3606 if (!memcmp(lustre_cfg_string(lcfg, 6), "master",
3607 strlen("master"))) {
3608 mds->mds_obd_type = MDS_MASTER_OBD;
3609 } else if (!memcmp(lustre_cfg_string(lcfg, 6), "cache",
3611 mds->mds_obd_type = MDS_CACHE_OBD;
3615 rc = lvfs_mount_fs(lustre_cfg_string(lcfg, 1),
3616 lustre_cfg_string(lcfg, 2),
3617 options, 0, &lvfs_ctxt);
3621 if (rc || !lvfs_ctxt) {
3622 CERROR("lvfs_mount_fs failed: rc = %d\n", rc);
3626 mnt = lvfs_ctxt->loc_mnt;
3627 mds->mds_lvfs_ctxt = lvfs_ctxt;
3628 ll_clear_rdonly(ll_sbdev(mnt->mnt_sb));
3630 CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt);
3632 mds->mds_fidext_thumb = 0;
3633 sema_init(&mds->mds_epoch_sem, 1);
3634 atomic_set(&mds->mds_real_clients, 0);
3635 spin_lock_init(&mds->mds_fidext_lock);
3636 spin_lock_init(&mds->mds_fidmap_lock);
3637 spin_lock_init(&mds->mds_transno_lock);
3638 spin_lock_init(&mds->mds_last_fid_lock);
3639 sema_init(&mds->mds_orphan_recovery_sem, 1);
3640 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
3642 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
3643 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
3645 if (obd->obd_namespace == NULL) {
3646 mds_cleanup(obd, 0);
3647 GOTO(err_put, rc = -ENOMEM);
3649 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
3651 mds->mds_capa_timeout = CAPA_TIMEOUT;
3652 mds->mds_capa_key_timeout = CAPA_KEY_TIMEOUT;
3654 rc = mds_fs_setup(obd, mnt);
3656 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
3661 rc = llog_start_commit_thread();
3666 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 && lustre_cfg_buf(lcfg, 3) &&
3667 strncmp(lustre_cfg_string(lcfg, 3), "dumb",
3668 LUSTRE_CFG_BUFLEN(lcfg, 3))) {
3671 generate_random_uuid(uuid);
3672 class_uuid_unparse(uuid, &mds->mds_dt_uuid);
3674 OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
3675 if (mds->mds_profile == NULL)
3676 GOTO(err_fs, rc = -ENOMEM);
3678 strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
3679 LUSTRE_CFG_BUFLEN(lcfg, 3));
3683 * setup root dir and files ID dir if lmv already connected, or there is
3686 if (mds->mds_md_exp || (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 &&
3687 lustre_cfg_buf(lcfg, 3) &&
3688 strncmp(lustre_cfg_string(lcfg, 3), "dumb",
3689 LUSTRE_CFG_BUFLEN(lcfg, 3)))) {
3690 rc = mds_fs_setup_rootid(obd);
3694 rc = mds_fs_setup_virtid(obd);
3700 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3701 "mds_ldlm_client", &obd->obd_ldlm_client);
3702 obd->obd_replayable = 1;
3704 mds->mds_crypto_type = NO_CRYPTO;
3706 rc = mds_postsetup(obd);
3713 /* No extra cleanup needed for llog_init_commit_thread() */
3714 mds_fs_cleanup(obd, 0);
3716 ldlm_namespace_free(obd->obd_namespace, 0);
3717 obd->obd_namespace = NULL;
3720 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3724 fsfilt_put_ops(obd->obd_fsops);
3728 static int mds_fs_post_setup(struct obd_device *obd)
3730 struct mds_obd *mds = &obd->u.mds;
3731 struct dentry *dentry;
3735 dentry = mds_id2dentry(obd, &mds->mds_rootid, NULL);
3736 if (IS_ERR(dentry)) {
3737 CERROR("Can't find ROOT, err = %d\n",
3738 (int)PTR_ERR(dentry));
3739 RETURN(PTR_ERR(dentry));
3741 rc = fsfilt_post_setup(obd, dentry);
3742 //set id2name function handler
3743 fsfilt_set_info(obd, mds->mds_sb, NULL, 7, "id2name",
3744 sizeof(mds_audit_id2name), mds_audit_id2name);
3750 static int mds_postsetup(struct obd_device *obd)
3752 struct mds_obd *mds = &obd->u.mds;
3756 rc = obd_llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
3757 obd, 0, NULL, &llog_lvfs_ops);
3761 if (mds->mds_profile) {
3762 struct llog_ctxt *lgctxt;
3763 struct lvfs_run_ctxt saved;
3764 struct lustre_profile *lprof;
3765 struct config_llog_instance cfg;
3767 cfg.cfg_instance = NULL;
3768 cfg.cfg_uuid = mds->mds_dt_uuid;
3769 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3771 lgctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
3773 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3774 GOTO(err_llog, rc = -EINVAL);
3777 rc = class_config_process_llog(lgctxt, mds->mds_profile, &cfg);
3778 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3783 lprof = class_get_profile(mds->mds_profile);
3784 if (lprof == NULL) {
3785 CERROR("No profile found: %s\n", mds->mds_profile);
3786 GOTO(err_cleanup, rc = -ENOENT);
3788 rc = mds_dt_connect(obd, lprof->lp_lov);
3790 GOTO(err_cleanup, rc);
3792 rc = mds_md_postsetup(obd);
3794 GOTO(err_cleanup, rc);
3796 rc = mds_fs_post_setup(obd);
3798 CERROR("can not post setup fsfilt\n");
3803 obd_llog_cleanup(llog_get_context(&obd->obd_llogs,
3804 LLOG_CONFIG_ORIG_CTXT));
3808 int mds_postrecov_common(struct obd_device *obd)
3810 struct mds_obd *mds = &obd->u.mds;
3811 struct llog_ctxt *ctxt;
3812 int rc, item = 0, valsize;
3813 struct timeval tstart, now;
3817 CDEBUG(D_ERROR, "%s: post-recovery\n", obd->obd_name);
3818 LASSERT(!obd->obd_recovering);
3819 ctxt = llog_get_context(&obd->obd_llogs, LLOG_UNLINK_ORIG_CTXT);
3820 LASSERT(ctxt != NULL);
3822 /* clean PENDING dir */
3823 do_gettimeofday(&tstart);
3824 rc = mds_cleanup_orphans(obd);
3825 do_gettimeofday(&now);
3826 CDEBUG(D_ERROR, "%s: cleaned %d MDS orphans in %us\n",
3827 obd->obd_name, rc, (unsigned) (now.tv_sec - tstart.tv_sec));
3832 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
3833 valsize = sizeof(group);
3834 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
3835 "mds_conn", valsize, &group);
3837 CERROR("%s: failed to obd_set_info(): %d\n",
3842 rc = llog_connect(ctxt, obd->u.mds.mds_dt_desc.ld_tgt_count,
3845 CERROR("%s: failed at llog_origin_connect: %d\n",
3850 /* remove the orphaned precreated objects */
3851 do_gettimeofday(&tstart);
3852 rc = mds_dt_clear_orphans(mds, NULL /* all OSTs */);
3853 do_gettimeofday(&now);
3854 CDEBUG(D_ERROR, "%s: cleaned OSS orphans in %us: %d\n",
3855 obd->obd_name, (unsigned) (now.tv_sec - tstart.tv_sec), rc);
3857 CERROR("%s: can't clear OSS orphans: %d\n",
3863 RETURN(rc < 0 ? rc : item);
3866 /* cleanup all llogging subsystems */
3867 rc = obd_llog_finish(obd, &obd->obd_llogs,
3868 mds->mds_dt_desc.ld_tgt_count);
3870 CERROR("%s: failed to cleanup llogging subsystems\n",
3875 int mds_postrecov(struct obd_device *obd)
3879 rc = mds_postrecov_common(obd);
3881 rc = mds_md_reconnect(obd);
3885 int mds_dt_clean(struct obd_device *obd)
3887 struct mds_obd *mds = &obd->u.mds;
3890 if (mds->mds_profile) {
3892 struct llog_ctxt *llctx;
3893 struct lvfs_run_ctxt saved;
3894 struct config_llog_instance cfg;
3895 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
3897 OBD_ALLOC(cln_prof, len);
3899 CERROR("can't allocate memory, processing cleanup "
3900 "profile is skipped\n");
3904 sprintf(cln_prof, "%s-clean", mds->mds_profile);
3906 cfg.cfg_instance = NULL;
3907 cfg.cfg_uuid = mds->mds_dt_uuid;
3909 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3910 llctx = llog_get_context(&obd->obd_llogs,
3911 LLOG_CONFIG_ORIG_CTXT);
3912 class_config_process_llog(llctx, cln_prof, &cfg);
3913 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3915 OBD_FREE(cln_prof, len);
3917 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
3918 mds->mds_profile = NULL;
3923 int mds_md_clean(struct obd_device *obd)
3925 struct mds_obd *mds = &obd->u.mds;
3928 if (mds->mds_md_name) {
3929 OBD_FREE(mds->mds_md_name, strlen(mds->mds_md_name) + 1);
3930 mds->mds_md_name = NULL;
3935 static int mds_precleanup(struct obd_device *obd, int flags)
3941 mds_dt_disconnect(obd, flags);
3943 obd_llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
3947 extern void lgss_svc_cache_purge_all(void);
3948 static int mds_cleanup(struct obd_device *obd, int flags)
3950 struct mds_obd *mds = &obd->u.mds;
3953 if (mds->mds_sb == NULL)
3956 mds_update_server_data(obd, 1);
3957 mds_update_last_fid(obd, NULL, 1);
3959 if (mds->mds_dt_objids != NULL) {
3960 int size = mds->mds_dt_desc.ld_tgt_count *
3962 OBD_FREE(mds->mds_dt_objids, size);
3964 mds_fs_cleanup(obd, flags);
3968 /* 2 seems normal on mds, (may_umount() also expects 2
3969 fwiw), but we only see 1 at this point in obdfilter. */
3970 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3974 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
3976 spin_lock_bh(&obd->obd_processing_task_lock);
3977 if (obd->obd_recovering) {
3978 target_cancel_recovery_timer(obd);
3979 obd->obd_recovering = 0;
3981 spin_unlock_bh(&obd->obd_processing_task_lock);
3984 fsfilt_put_ops(obd->obd_fsops);
3988 lgss_svc_cache_purge_all();
3991 spin_lock(&mds->mds_denylist_lock);
3992 while (!list_empty( &mds->mds_denylist ) ) {
3993 deny_sec_t *p_deny_sec = list_entry(mds->mds_denylist.next,
3995 list_del(&p_deny_sec->list);
3996 OBD_FREE(p_deny_sec, sizeof(*p_deny_sec));
3998 spin_unlock(&mds->mds_denylist_lock);
4000 mds_capa_keys_cleanup(obd);
4005 static int set_security(const char *value, char **sec)
4007 if (!strcmp(value, "null"))
4009 else if (!strcmp(value, "krb5i"))
4011 else if (!strcmp(value, "krb5p"))
4014 CERROR("Unrecognized security flavor %s\n", value);
4021 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
4023 struct lustre_cfg *lcfg = buf;
4024 struct mds_obd *mds = &obd->u.mds;
4028 switch(lcfg->lcfg_command) {
4029 case LCFG_SET_SECURITY: {
4030 if ((LUSTRE_CFG_BUFLEN(lcfg, 1) == 0) ||
4031 (LUSTRE_CFG_BUFLEN(lcfg, 2) == 0))
4032 GOTO(out, rc = -EINVAL);
4034 if (!strcmp(lustre_cfg_string(lcfg, 1), "mds_sec"))
4035 rc = set_security(lustre_cfg_string(lcfg, 2),
4037 else if (!strcmp(lustre_cfg_string(lcfg, 1), "oss_sec"))
4038 rc = set_security(lustre_cfg_string(lcfg, 2),
4040 else if (!strcmp(lustre_cfg_string(lcfg, 1), "deny_sec")){
4041 spin_lock(&mds->mds_denylist_lock);
4042 rc = add_deny_security(lustre_cfg_string(lcfg, 2),
4043 &mds->mds_denylist);
4044 spin_unlock(&mds->mds_denylist_lock);
4046 CERROR("Unrecognized key\n");
4052 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
4053 GOTO(out, rc = -EINVAL);
4059 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
4061 struct ldlm_lock *new_lock,
4062 struct ldlm_lock **old_lock,
4063 struct lustre_handle *lockh)
4065 struct obd_export *exp = req->rq_export;
4066 struct obd_device *obd = exp->exp_obd;
4067 struct ldlm_request *dlmreq =
4068 lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq));
4069 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
4070 struct list_head *iter;
4072 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
4075 spin_lock(&obd->obd_namespace->ns_hash_lock);
4076 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
4077 struct ldlm_lock *lock;
4078 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
4079 if (lock == new_lock)
4081 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
4082 lockh->cookie = lock->l_handle.h_cookie;
4083 LDLM_DEBUG(lock, "restoring lock cookie");
4084 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
4087 *old_lock = LDLM_LOCK_GET(lock);
4088 spin_unlock(&obd->obd_namespace->ns_hash_lock);
4092 spin_unlock(&obd->obd_namespace->ns_hash_lock);
4094 /* If the xid matches, then we know this is a resent request,
4095 * and allow it. (It's probably an OPEN, for which we don't
4098 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
4102 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
4105 /* This remote handle isn't enqueued, so we never received or
4106 * processed this request. Clear MSG_RESENT, because it can
4107 * be handled like any normal request now. */
4109 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
4111 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
4115 int intent_disposition(struct ldlm_reply *rep, int flag)
4119 return (rep->lock_policy_res1 & flag);
4122 void intent_set_disposition(struct ldlm_reply *rep, int flag)
4126 rep->lock_policy_res1 |= flag;
4129 static int mds_intent_prepare_reply_buffers(struct ptlrpc_request *req,
4130 struct ldlm_intent *it)
4132 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
4133 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
4134 int rc, reply_buffers;
4135 int repsize[8] = {sizeof(struct ldlm_reply),
4136 sizeof(struct mds_body),
4137 mds->mds_max_mdsize};
4141 if (it->opc & ( IT_OPEN | IT_GETATTR | IT_LOOKUP | IT_CHDIR )) {
4142 /*Ugly here, Actually, we should prepare the reply buffer
4143 *after we know whether these stuff exist or not, which should
4144 * be fixed in future, Now each item is in the fix position,
4145 * the sequence is lsm, acl, crypto ea, capa.*/
4146 repsize[reply_buffers++] = sizeof(int);
4147 if (med->med_remote)
4148 repsize[reply_buffers++] =
4149 sizeof(struct mds_remote_perm);
4151 repsize[reply_buffers++] =
4152 xattr_acl_size(LL_ACL_MAX_ENTRIES);
4154 repsize[reply_buffers++] = sizeof(int);
4155 repsize[reply_buffers++] = sizeof(struct crypto_key);
4157 /* XXX: if new buffer is to be added, capability reply
4158 * buffer should always been reserved. */
4159 if (it->opc & IT_OPEN)
4160 repsize[reply_buffers++] = sizeof(struct lustre_capa);
4163 rc = lustre_pack_reply(req, reply_buffers, repsize, NULL);
4168 static int mds_intent_policy(struct ldlm_namespace *ns,
4169 struct ldlm_lock **lockp, void *req_cookie,
4170 ldlm_mode_t mode, int flags, void *data)
4172 struct ptlrpc_request *req = req_cookie;
4173 struct ldlm_lock *lock = *lockp;
4174 struct ldlm_intent *it;
4175 struct ldlm_reply *rep;
4176 struct lustre_handle lockh[2] = {{0}, {0}};
4177 struct ldlm_lock *new_lock = NULL;
4178 int getattr_part = MDS_INODELOCK_UPDATE;
4181 int offset = MDS_REQ_INTENT_REC_OFF;
4184 LASSERT(req != NULL);
4185 MD_COUNTER_INCREMENT(req->rq_export->exp_obd, intent_lock);
4187 if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) {
4188 /* No intent was provided */
4189 int size = sizeof(struct ldlm_reply);
4190 rc = lustre_pack_reply(req, 1, &size, NULL);
4195 it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it),
4196 lustre_swab_ldlm_intent);
4198 CERROR("Intent missing\n");
4199 RETURN(req->rq_status = -EFAULT);
4202 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
4204 rc = mds_intent_prepare_reply_buffers(req, it);
4207 RETURN(req->rq_status = rc);
4209 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
4210 LASSERT(rep != NULL);
4212 intent_set_disposition(rep, DISP_IT_EXECD);
4214 /* execute policy */
4215 switch ((long)it->opc) {
4217 case IT_CREAT|IT_OPEN:
4218 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4220 /* XXX swab here to assert that an mds_open reint
4221 * packet is following */
4222 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4224 rep->lock_policy_res2 = mds_reint(req, offset, lockh);
4226 if (rep->lock_policy_res2) {
4228 * mds_open() returns ENOLCK where it should return
4229 * zero, but it has no lock to return.
4231 if (rep->lock_policy_res2 == ENOLCK)
4232 rep->lock_policy_res2 = 0;
4234 RETURN(ELDLM_LOCK_ABORTED);
4238 * IT_OPEN may return lock on cross-node dentry that we want to
4239 * hold during attr retrival -bzzz
4241 if (lockh[0].cookie == 0)
4242 RETURN(ELDLM_LOCK_ABORTED);
4246 getattr_part = MDS_INODELOCK_LOOKUP;
4249 getattr_part |= MDS_INODELOCK_LOOKUP;
4251 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4252 lock, &new_lock, lockh);
4253 rep->lock_policy_res2 = mds_getattr_lock(req, offset, lockh,
4255 /* FIXME: LDLM can set req->rq_status. MDS sets
4256 policy_res{1,2} with disposition and status.
4257 - replay: returns 0 & req->status is old status
4258 - otherwise: returns req->status */
4259 if (intent_disposition(rep, DISP_LOOKUP_NEG))
4260 rep->lock_policy_res2 = 0;
4261 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
4262 rep->lock_policy_res2)
4263 RETURN(ELDLM_LOCK_ABORTED);
4264 if (req->rq_status != 0) {
4266 rep->lock_policy_res2 = req->rq_status;
4267 RETURN(ELDLM_LOCK_ABORTED);
4271 rc = mds_lock_and_check_slave(offset, req, lockh);
4272 if ((rep->lock_policy_res2 = rc)) {
4274 rep->lock_policy_res2 = 0;
4275 RETURN(ELDLM_LOCK_ABORTED);
4279 CERROR("Unhandled intent "LPD64"\n", it->opc);
4283 /* By this point, whatever function we called above must have either
4284 * filled in 'lockh', been an intent replay, or returned an error. We
4285 * want to allow replayed RPCs to not get a lock, since we would just
4286 * drop it below anyways because lock replay is done separately by the
4287 * client afterwards. For regular RPCs we want to give the new lock to
4288 * the client instead of whatever lock it was about to get. */
4289 if (new_lock == NULL)
4290 new_lock = ldlm_handle2lock(&lockh[0]);
4291 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
4294 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
4295 it->opc, lockh[0].cookie);
4297 /* If we've already given this lock to a client once, then we should
4298 * have no readers or writers. Otherwise, we should have one reader
4299 * _or_ writer ref (which will be zeroed below) before returning the
4300 * lock to a client. */
4301 if (new_lock->l_export == req->rq_export) {
4302 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
4304 LASSERT(new_lock->l_export == NULL);
4305 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
4310 if (new_lock->l_export == req->rq_export) {
4311 /* Already gave this to the client, which means that we
4312 * reconstructed a reply. */
4313 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
4315 RETURN(ELDLM_LOCK_REPLACED);
4318 /* Fixup the lock to be given to the client */
4319 lock_res_and_lock(new_lock);
4320 new_lock->l_readers = 0;
4321 new_lock->l_writers = 0;
4323 new_lock->l_export = class_export_get(req->rq_export);
4325 spin_lock(&new_lock->l_export->exp_ldlm_data.led_lock);
4326 list_add(&new_lock->l_export_chain,
4327 &new_lock->l_export->exp_ldlm_data.led_held_locks);
4328 spin_unlock(&new_lock->l_export->exp_ldlm_data.led_lock);
4330 new_lock->l_blocking_ast = lock->l_blocking_ast;
4331 new_lock->l_completion_ast = lock->l_completion_ast;
4333 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
4334 sizeof(lock->l_remote_handle));
4336 new_lock->l_flags &= ~LDLM_FL_LOCAL;
4338 unlock_res_and_lock(new_lock);
4339 LDLM_LOCK_PUT(new_lock);
4341 RETURN(ELDLM_LOCK_REPLACED);
4344 int mds_attach(struct obd_device *dev, obd_count len, void *data)
4346 struct lprocfs_static_vars lvars;
4348 struct mds_obd *mds = &dev->u.mds;
4350 spin_lock_init(&mds->mds_denylist_lock);
4351 INIT_LIST_HEAD(&mds->mds_denylist);
4353 lprocfs_init_multi_vars(0, &lvars);
4355 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
4359 return lprocfs_alloc_md_stats(dev, 0);
4362 int mds_detach(struct obd_device *dev)
4364 lprocfs_free_md_stats(dev);
4365 return lprocfs_obd_detach(dev);
4368 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
4370 struct lprocfs_static_vars lvars;
4372 lprocfs_init_multi_vars(1, &lvars);
4373 return lprocfs_obd_attach(dev, lvars.obd_vars);
4376 int mdt_detach(struct obd_device *dev)
4378 return lprocfs_obd_detach(dev);
4381 static int mdt_setup(struct obd_device *obd, obd_count len, void *buf)
4383 struct mds_obd *mds = &obd->u.mds;
4388 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4389 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
4390 MDS_SERVICE_WATCHDOG_TIMEOUT,
4391 mds_handle, "mds", obd->obd_proc_entry);
4393 if (!mds->mds_service) {
4394 CERROR("failed to start service\n");
4398 rc = ptlrpc_start_n_threads(obd, mds->mds_service, MDT_NUM_THREADS,
4401 GOTO(err_thread, rc);
4403 mds->mds_setattr_service =
4404 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4405 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
4406 MDS_SERVICE_WATCHDOG_TIMEOUT,
4407 mds_handle, "mds_setattr",
4408 obd->obd_proc_entry);
4409 if (!mds->mds_setattr_service) {
4410 CERROR("failed to start getattr service\n");
4411 GOTO(err_thread, rc = -ENOMEM);
4414 rc = ptlrpc_start_n_threads(obd, mds->mds_setattr_service,
4415 MDT_NUM_THREADS, "ll_mdt_attr");
4417 GOTO(err_thread2, rc);
4419 mds->mds_readpage_service =
4420 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4421 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
4422 MDS_SERVICE_WATCHDOG_TIMEOUT,
4423 mds_handle, "mds_readpage",
4424 obd->obd_proc_entry);
4425 if (!mds->mds_readpage_service) {
4426 CERROR("failed to start readpage service\n");
4427 GOTO(err_thread2, rc = -ENOMEM);
4430 rc = ptlrpc_start_n_threads(obd, mds->mds_readpage_service,
4431 MDT_NUM_THREADS, "ll_mdt_rdpg");
4434 GOTO(err_thread3, rc);
4436 mds->mds_close_service =
4437 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4438 MDS_CLOSE_PORTAL, MDC_REPLY_PORTAL,
4439 MDS_SERVICE_WATCHDOG_TIMEOUT,
4440 mds_handle, "mds_close",
4441 obd->obd_proc_entry);
4442 if (!mds->mds_close_service) {
4443 CERROR("failed to start close service\n");
4444 GOTO(err_thread3, rc = -ENOMEM);
4447 rc = ptlrpc_start_n_threads(obd, mds->mds_close_service,
4448 MDT_NUM_THREADS, "ll_mdt_clos");
4451 GOTO(err_thread4, rc);
4455 ptlrpc_unregister_service(mds->mds_close_service);
4457 ptlrpc_unregister_service(mds->mds_readpage_service);
4459 ptlrpc_unregister_service(mds->mds_setattr_service);
4461 ptlrpc_unregister_service(mds->mds_service);
4465 static int mdt_cleanup(struct obd_device *obd, int flags)
4467 struct mds_obd *mds = &obd->u.mds;
4470 ptlrpc_stop_all_threads(mds->mds_close_service);
4471 ptlrpc_unregister_service(mds->mds_close_service);
4473 ptlrpc_stop_all_threads(mds->mds_readpage_service);
4474 ptlrpc_unregister_service(mds->mds_readpage_service);
4476 ptlrpc_stop_all_threads(mds->mds_setattr_service);
4477 ptlrpc_unregister_service(mds->mds_setattr_service);
4479 ptlrpc_stop_all_threads(mds->mds_service);
4480 ptlrpc_unregister_service(mds->mds_service);
4485 static struct dentry *mds_lvfs_id2dentry(__u64 ino, __u32 gen,
4486 __u64 gr, void *data)
4488 struct lustre_id id;
4489 struct obd_device *obd = data;
4493 return mds_id2dentry(obd, &id, NULL);
4496 static int mds_get_info(struct obd_export *exp, __u32 keylen,
4497 void *key, __u32 *valsize, void *val)
4499 struct obd_device *obd;
4500 struct mds_obd *mds;
4504 obd = class_exp2obd(exp);
4508 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
4509 exp->exp_handle.h_cookie);
4513 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
4514 /* get log_context handle. */
4515 struct llog_ctxt *ctxt;
4516 unsigned long *llh_handle = val;
4517 *valsize = sizeof(unsigned long);
4518 ctxt = llog_get_context(&obd->obd_llogs, LLOG_REINT_ORIG_CTXT);
4520 CERROR("Cannot get REINT llog context\n");
4523 *llh_handle = (unsigned long)ctxt;
4526 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
4527 /* get log_context handle. */
4528 unsigned long *sb = val;
4529 *valsize = sizeof(unsigned long);
4530 *sb = (unsigned long)obd->u.mds.mds_sb;
4534 if (keylen >= strlen("mdsize") && memcmp(key, "mdsize", keylen) == 0) {
4535 __u32 *mdsize = val;
4536 *valsize = sizeof(*mdsize);
4537 *mdsize = mds->mds_max_mdsize;
4541 if (keylen >= strlen("mdsnum") && strcmp(key, "mdsnum") == 0) {
4542 __u32 *mdsnum = val;
4543 *valsize = sizeof(*mdsnum);
4544 *mdsnum = mds->mds_num;
4548 if (keylen >= strlen("rootid") && strcmp(key, "rootid") == 0) {
4549 struct lustre_id *rootid = val;
4550 *valsize = sizeof(*rootid);
4551 *rootid = mds->mds_rootid;
4555 if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
4556 struct lov_desc *desc = val;
4557 *valsize = sizeof(*desc);
4558 *desc = mds->mds_dt_desc;
4562 if (keylen >= strlen("getext") && strcmp(key, "getext") == 0) {
4563 struct fid_extent *ext = val;
4564 *valsize = sizeof(*ext);
4566 spin_lock(&mds->mds_fidext_lock);
4567 ext->fe_width = MDS_FIDEXT_SIZE;
4568 ext->fe_start = mds->mds_fidext_thumb + 1;
4569 mds->mds_fidext_thumb += MDS_FIDEXT_SIZE;
4570 spin_unlock(&mds->mds_fidext_lock);
4575 rc = fsfilt_get_info(obd, mds->mds_sb, NULL, keylen, key, valsize, val);
4577 CDEBUG(D_IOCTL, "invalid key\n");
4582 struct lvfs_callback_ops mds_lvfs_ops = {
4583 l_id2dentry: mds_lvfs_id2dentry,
4586 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
4587 int objcount, struct obd_ioobj *obj,
4588 int niocount, struct niobuf_remote *nb,
4589 struct niobuf_local *res,
4590 struct obd_trans_info *oti, struct lustre_capa *capa);
4592 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
4593 int objcount, struct obd_ioobj *obj, int niocount,
4594 struct niobuf_local *res, struct obd_trans_info *oti,
4597 /* use obd ops to offer management infrastructure */
4598 static struct obd_ops mds_obd_ops = {
4599 .o_owner = THIS_MODULE,
4600 .o_attach = mds_attach,
4601 .o_detach = mds_detach,
4602 .o_connect = mds_connect,
4603 .o_connect_post = mds_connect_post,
4604 .o_init_export = mds_init_export,
4605 .o_destroy_export = mds_destroy_export,
4606 .o_disconnect = mds_disconnect,
4607 .o_setup = mds_setup,
4608 .o_precleanup = mds_precleanup,
4609 .o_cleanup = mds_cleanup,
4610 .o_process_config = mds_process_config,
4611 .o_postrecov = mds_postrecov,
4612 .o_statfs = mds_obd_statfs,
4613 .o_iocontrol = mds_iocontrol,
4614 .o_create = mds_obd_create,
4615 .o_destroy = mds_obd_destroy,
4616 .o_llog_init = mds_llog_init,
4617 .o_llog_finish = mds_llog_finish,
4618 .o_notify = mds_notify,
4619 .o_get_info = mds_get_info,
4620 .o_set_info = mds_set_info,
4621 .o_preprw = mds_preprw,
4622 .o_commitrw = mds_commitrw,
4625 static struct obd_ops mdt_obd_ops = {
4626 .o_owner = THIS_MODULE,
4627 .o_attach = mdt_attach,
4628 .o_detach = mdt_detach,
4629 .o_setup = mdt_setup,
4630 .o_cleanup = mdt_cleanup,
4633 static int __init mds_init(void)
4635 struct lprocfs_static_vars lvars;
4639 mds_init_lsd_cache();
4640 mds_init_rmtacl_upcall_cache();
4642 lprocfs_init_multi_vars(0, &lvars);
4643 class_register_type(&mds_obd_ops, NULL, lvars.module_vars,
4644 OBD_MDS_DEVICENAME);
4645 lprocfs_init_multi_vars(1, &lvars);
4646 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars,
4647 OBD_MDT_DEVICENAME);
4649 rc = mds_capa_key_start_thread();
4651 class_unregister_type(OBD_MDT_DEVICENAME);
4652 class_unregister_type(OBD_MDS_DEVICENAME);
4653 mds_cleanup_lsd_cache();
4656 mds_eck_timer.function = mds_capa_key_timer_callback;
4657 mds_eck_timer.data = 0;
4658 init_timer(&mds_eck_timer);
4663 static void /*__exit*/ mds_exit(void)
4665 mds_capa_key_stop_thread();
4666 mds_cleanup_rmtacl_upcall_cache();
4667 mds_cleanup_lsd_cache();
4669 class_unregister_type(OBD_MDS_DEVICENAME);
4670 class_unregister_type(OBD_MDT_DEVICENAME);
4673 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4674 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
4675 MODULE_LICENSE("GPL");
4677 module_init(mds_init);
4678 module_exit(mds_exit);