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_gs.h>
60 #include "mds_internal.h"
61 #include <linux/lustre_sec.h>
62 #include <linux/lustre_audit.h>
64 extern int mds_audit_auth(struct ptlrpc_request *, struct lvfs_ucred *,
65 audit_op, struct lustre_id *,
67 extern int mds_audit_stat(struct ptlrpc_request *, struct lustre_id *,
68 struct dentry *, int);
69 extern int mds_audit_open(struct ptlrpc_request *, struct mds_update_record *,
72 static int mds_intent_policy(struct ldlm_namespace *ns,
73 struct ldlm_lock **lockp, void *req_cookie,
74 ldlm_mode_t mode, int flags, void *data);
75 static int mds_postsetup(struct obd_device *obd);
76 static int mds_cleanup(struct obd_device *obd, int flags);
79 /* Assumes caller has already pushed into the kernel filesystem context */
80 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
81 loff_t offset, int count)
83 struct ptlrpc_bulk_desc *desc;
84 struct l_wait_info lwi;
86 int rc = 0, npages, i, tmpcount, tmpsize = 0;
89 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
91 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
92 OBD_ALLOC(pages, sizeof(*pages) * npages);
94 GOTO(out, rc = -ENOMEM);
96 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
99 GOTO(out_free, rc = -ENOMEM);
101 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
102 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
104 pages[i] = alloc_pages(GFP_KERNEL, 0);
105 if (pages[i] == NULL)
106 GOTO(cleanup_buf, rc = -ENOMEM);
108 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
111 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
112 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
113 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
114 tmpsize, offset, file->f_dentry->d_inode->i_ino,
115 file->f_dentry->d_inode->i_size);
117 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
118 kmap(pages[i]), tmpsize, &offset);
122 GOTO(cleanup_buf, rc = -EIO);
125 LASSERT(desc->bd_nob == count);
127 rc = ptlrpc_start_bulk_transfer(desc);
129 GOTO(cleanup_buf, rc);
131 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
132 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
133 OBD_FAIL_MDS_SENDPAGE, rc = -EIO);
134 GOTO(abort_bulk, rc);
137 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
138 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
139 LASSERT (rc == 0 || rc == -ETIMEDOUT);
142 if (desc->bd_success &&
143 desc->bd_nob_transferred == count)
144 GOTO(cleanup_buf, rc);
146 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
149 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
150 (rc == -ETIMEDOUT) ? "timeout" : "network error",
151 desc->bd_nob_transferred, count,
152 req->rq_export->exp_client_uuid.uuid,
153 req->rq_export->exp_connection->c_remote_uuid.uuid);
155 ptlrpc_fail_export(req->rq_export);
159 ptlrpc_abort_bulk (desc);
161 for (i = 0; i < npages; i++)
163 __free_pages(pages[i], 0);
165 ptlrpc_free_bulk(desc);
167 OBD_FREE(pages, sizeof(*pages) * npages);
172 extern char *ldlm_lockname[];
174 int mds_lock_mode_for_dir(struct obd_device *obd,
175 struct dentry *dentry, int mode)
177 int ret_mode = 0, split;
179 /* any dir access needs couple locks:
180 * 1) on part of dir we gonna lookup/modify in
181 * 2) on a whole dir to protect it from concurrent splitting
182 * and to flush client's cache for readdir()
183 * so, for a given mode and dentry this routine decides what
184 * lock mode to use for lock #2:
185 * 1) if caller's gonna lookup in dir then we need to protect
186 * dir from being splitted only - LCK_CR
187 * 2) if caller's gonna modify dir then we need to protect
188 * dir from being splitted and to flush cache - LCK_CW
189 * 3) if caller's gonna modify dir and that dir seems ready
190 * for splitting then we need to protect it from any
191 * type of access (lookup/modify/split) - LCK_EX -bzzz */
193 split = mds_splitting_expected(obd, dentry);
196 * it is important to check here only for MDS_NO_SPLITTABLE. The reason
197 * is that MDS_NO_SPLITTABLE means dir is not splittable in principle
198 * and another thread will not split it on the quiet. But if we have
199 * MDS_NO_SPLIT_EXPECTED, this means, that dir may be splitted anytime,
200 * but not now (for current thread) and we should consider that it can
201 * happen soon and go that branch which can yield LCK_EX to protect from
202 * possible splitting.
204 if (split == MDS_NO_SPLITTABLE) {
206 * this inode won't be splitted. so we need not to protect from
207 * just flush client's cache on modification.
214 if (mode == LCK_EX) {
216 } else if (mode == LCK_PR) {
218 } else if (mode == LCK_PW) {
220 * caller gonna modify directory. We use concurrent
221 * write lock here to retract client's cache for
224 if (split == MDS_EXPECT_SPLIT) {
226 * splitting possible. serialize any access the
227 * idea is that first one seen dir is splittable
228 * is given exclusive lock and split
229 * directory. caller passes lock mode to
230 * mds_try_to_split_dir() and splitting would be
231 * done with exclusive lock only -bzzz.
233 CDEBUG(D_OTHER, "%s: gonna split %lu/%lu\n",
235 (unsigned long)dentry->d_inode->i_ino,
236 (unsigned long)dentry->d_inode->i_generation);
247 /* only valid locked dentries or errors should be returned */
248 struct dentry *mds_id2locked_dentry(struct obd_device *obd, struct lustre_id *id,
249 struct vfsmount **mnt, int lock_mode,
250 struct lustre_handle *lockh, int *mode,
251 char *name, int namelen, __u64 lockpart)
253 struct dentry *de = mds_id2dentry(obd, id, mnt), *retval = de;
254 ldlm_policy_data_t policy = { .l_inodebits = { lockpart } };
255 struct ldlm_res_id res_id = { .name = {0} };
256 int flags = LDLM_FL_ATOMIC_CB, rc;
263 res_id.name[0] = id_fid(id);
264 res_id.name[1] = id_group(id);
267 if (name && IS_PDIROPS(de->d_inode)) {
268 ldlm_policy_data_t cpolicy =
269 { .l_inodebits = { MDS_INODELOCK_UPDATE } };
270 LASSERT(mode != NULL);
271 *mode = mds_lock_mode_for_dir(obd, de, lock_mode);
273 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace,
275 &cpolicy, *mode, &flags,
277 ldlm_completion_ast, NULL, NULL,
278 NULL, 0, NULL, lockh + 1);
279 if (rc != ELDLM_OK) {
281 RETURN(ERR_PTR(-ENOLCK));
284 flags = LDLM_FL_ATOMIC_CB;
286 res_id.name[2] = full_name_hash((unsigned char *)name, namelen);
288 CDEBUG(D_INFO, "take lock on "DLID4":"LPX64"\n",
289 OLID4(id), res_id.name[2]);
292 #warning "No PDIROPS support in the kernel"
294 rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, res_id,
295 LDLM_IBITS, &policy, lock_mode, &flags,
296 mds_blocking_ast, ldlm_completion_ast,
297 NULL, NULL, NULL, 0, NULL, lockh);
298 if (rc != ELDLM_OK) {
300 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
303 ldlm_lock_decref(lockh + 1, *mode);
305 } else if (de->d_inode && de->d_inode->i_nlink == 0) {
306 /* as sometimes we lookup inode by ino/generation through
307 iopen mechanism, it's possible to find already unlinked
308 inode with nlink == 0. let's interpretate the case as
310 CWARN("found already unlinked inode %lu/%u\n",
311 de->d_inode->i_ino, de->d_inode->i_generation);
313 retval = ERR_PTR(-ENOENT);
314 ldlm_lock_decref(lockh, lock_mode);
317 ldlm_lock_decref(lockh + 1, *mode);
324 #ifndef DCACHE_DISCONNECTED
325 #define DCACHE_DISCONNECTED DCACHE_NFSD_DISCONNECTED
328 /* Look up an entry by inode number. This function ONLY returns valid dget'd
329 * dentries with an initialized inode or errors */
330 struct dentry *mds_id2dentry(struct obd_device *obd, struct lustre_id *id,
331 struct vfsmount **mnt)
333 struct mds_obd *mds = &obd->u.mds;
334 struct dentry *result;
336 unsigned long ino = 0;
340 if (!id_ino(id) && id_fid(id)) {
341 struct lustre_id *lid;
343 /* if this is reint case we should use fidmap for resolving
344 * correct local store cookie. */
345 lid = mds_fidmap_lookup(obd, id);
347 RETURN(ERR_PTR(-ENOENT));
349 ino = (unsigned long)id_ino(lid);
350 generation = (__u32)id_gen(lid);
352 CDEBUG(D_DENTRY, "fidmap resolved "DLID4"->"DLID4"\n",
353 OLID4(id), OLID4(lid));
355 } else if (id_ino(id)) {
356 ino = (unsigned long)id_ino(id);
357 generation = (__u32)id_gen(id);
359 CERROR("invalid id for lookup "
360 DLID4"\n", OLID4(id));
364 RETURN(ERR_PTR(-ESTALE));
366 snprintf(idname, sizeof(idname), "0x%lx", ino);
368 CDEBUG(D_DENTRY, "--> mds_id2dentry: ino/gen %lu/%u, sb %p\n",
369 ino, generation, mds->mds_sb);
371 /* under ext3 this is neither supposed to return bad inodes nor NULL
373 result = ll_lookup_one_len(idname, mds->mds_id_de,
378 inode = result->d_inode;
380 RETURN(ERR_PTR(-ENOENT));
382 if (is_bad_inode(inode)) {
383 CERROR("bad inode returned %lu/%u\n",
384 inode->i_ino, inode->i_generation);
386 RETURN(ERR_PTR(-ENOENT));
389 /* here we disabled generation check, as root inode i_generation
390 * of cache mds and real mds are different. */
391 if (id_fid(id) != id_fid(&mds->mds_rootid) && generation != 0 &&
392 inode->i_generation != generation) {
393 /* we didn't find the right inode.. */
394 if (id_group(id) != mds->mds_num) {
395 CERROR("bad inode %lu found, link: %lu, ct: %d, generation "
396 "%u != %u, mds %u != %u, request to wrong MDS?\n",
397 inode->i_ino, (unsigned long)inode->i_nlink,
398 atomic_read(&inode->i_count), inode->i_generation,
399 generation, mds->mds_num, (unsigned)id_group(id));
401 CERROR("bad inode %lu found, link: %lu, ct: %d, generation "
402 "%u != %u, inode is recreated while request handled?\n",
403 inode->i_ino, (unsigned long)inode->i_nlink,
404 atomic_read(&inode->i_count), inode->i_generation,
408 RETURN(ERR_PTR(-ENOENT));
412 *mnt = mds->mds_vfsmnt;
420 int mds_req_add_idmapping(struct ptlrpc_request *req,
421 struct mds_export_data *med)
423 struct mds_req_sec_desc *rsd;
424 struct lustre_sec_desc *lsd;
427 if (!med->med_remote)
430 /* maybe we should do it more completely: invalidate the gss ctxt? */
431 if (req->rq_mapped_uid == MDS_IDMAP_NOTFOUND) {
432 CWARN("didn't find mapped uid\n");
436 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
438 CERROR("Can't unpack security desc\n");
442 lsd = mds_get_lsd(req->rq_mapped_uid);
444 CERROR("can't get LSD(%u), no mapping added\n",
449 rc = mds_idmap_add(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
450 rsd->rsd_gid, lsd->lsd_gid);
456 int mds_req_del_idmapping(struct ptlrpc_request *req,
457 struct mds_export_data *med)
459 struct mds_req_sec_desc *rsd;
460 struct lustre_sec_desc *lsd;
463 if (!med->med_remote)
466 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
468 CERROR("Can't unpack security desc\n");
472 LASSERT(req->rq_mapped_uid != -1);
473 lsd = mds_get_lsd(req->rq_mapped_uid);
475 CERROR("can't get LSD(%u), no idmapping deleted\n",
480 rc = mds_idmap_del(med->med_idmap, rsd->rsd_uid, lsd->lsd_uid,
481 rsd->rsd_gid, lsd->lsd_gid);
486 static int mds_init_export_data(struct ptlrpc_request *req,
487 struct mds_export_data *med)
489 struct obd_connect_data *data, *reply;
490 int ask_remote, ask_local;
493 data = lustre_msg_buf(req->rq_reqmsg, 5, sizeof(*data));
494 reply = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*data));
495 LASSERT(data && reply);
497 if (med->med_initialized) {
498 CDEBUG(D_SEC, "med already initialized, reconnect?\n");
502 ask_remote = data->ocd_connect_flags & OBD_CONNECT_REMOTE;
503 ask_local = data->ocd_connect_flags & OBD_CONNECT_LOCAL;
505 /* currently the policy is simple: satisfy client as possible
508 if (req->rq_auth_uid == -1) {
510 CWARN("null sec is used, force to be local\n");
514 if (!req->rq_remote_realm)
515 CWARN("local realm asked to be remote\n");
517 } else if (ask_local) {
518 if (req->rq_remote_realm)
519 CWARN("remote realm asked to be local\n");
522 med->med_remote = (req->rq_remote_realm != 0);
525 med->med_nllu = data->ocd_nllu[0];
526 med->med_nllg = data->ocd_nllu[1];
528 med->med_initialized = 1;
530 reply->ocd_connect_flags &= ~(OBD_CONNECT_REMOTE | OBD_CONNECT_LOCAL);
531 if (med->med_remote) {
533 med->med_idmap = mds_idmap_alloc();
536 CERROR("Failed to alloc idmap, following request from "
537 "this client will be refused\n");
539 reply->ocd_connect_flags |= OBD_CONNECT_REMOTE;
540 CDEBUG(D_SEC, "set client as remote\n");
542 reply->ocd_connect_flags |= OBD_CONNECT_LOCAL;
543 CDEBUG(D_SEC, "set client as local\n");
549 static void mds_free_export_data(struct mds_export_data *med)
554 LASSERT(med->med_remote);
555 mds_idmap_free(med->med_idmap);
556 med->med_idmap = NULL;
559 /* Establish a connection to the MDS.
561 * This will set up an export structure for the client to hold state data about
562 * that client, like open files, the last operation number it did on the server,
565 static int mds_connect(struct lustre_handle *conn, struct obd_device *obd,
566 struct obd_uuid *cluuid, struct obd_connect_data *data,
569 struct mds_export_data *med;
570 struct mds_client_data *mcd;
571 struct obd_export *exp;
575 if (!conn || !obd || !cluuid)
578 /* XXX There is a small race between checking the list and adding a new
579 * connection for the same UUID, but the real threat (list corruption
580 * when multiple different clients connect) is solved.
582 * There is a second race between adding the export to the list, and
583 * filling in the client data below. Hence skipping the case of NULL
584 * mcd above. We should already be controlling multiple connects at the
585 * client, and we can't hold the spinlock over memory allocations
586 * without risk of deadlocking.
588 rc = class_connect(conn, obd, cluuid);
591 exp = class_conn2export(conn);
593 LASSERT(exp != NULL);
594 med = &exp->exp_mds_data;
596 OBD_ALLOC(mcd, sizeof(*mcd));
598 CERROR("%s: out of memory for client data.\n",
600 GOTO(out, rc = -ENOMEM);
603 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
606 rc = mds_client_add(obd, &obd->u.mds, med, -1);
614 OBD_FREE(mcd, sizeof(*mcd));
615 class_disconnect(exp, 0);
617 class_export_put(exp);
622 static int mds_connect_post(struct obd_export *exp, unsigned initial,
625 struct obd_device *obd = exp->exp_obd;
626 struct mds_obd *mds = &obd->u.mds;
627 struct mds_export_data *med;
628 struct mds_client_data *mcd;
632 med = &exp->exp_mds_data;
636 /* some one reconnect initially, we have to reset
637 * data existing export can have. bug 6102 */
638 if (mcd->mcd_last_xid != 0)
639 CDEBUG(D_HA, "initial reconnect to existing export\n");
640 mcd->mcd_last_transno = 0;
641 mcd->mcd_last_xid = 0;
642 mcd->mcd_last_close_xid = 0;
643 mcd->mcd_last_result = 0;
644 mcd->mcd_last_data = 0;
647 if (!(flags & OBD_OPT_MDS_CONNECTION)) {
648 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)) {
649 atomic_inc(&mds->mds_real_clients);
650 CDEBUG(D_OTHER,"%s: peer from %s is real client (%d)\n",
651 obd->obd_name, exp->exp_client_uuid.uuid,
652 atomic_read(&mds->mds_real_clients));
653 exp->exp_flags |= OBD_OPT_REAL_CLIENT;
655 if (mds->mds_md_name)
656 rc = mds_md_connect(obd, mds->mds_md_name);
661 static int mds_init_export(struct obd_export *exp)
663 struct mds_export_data *med = &exp->exp_mds_data;
665 INIT_LIST_HEAD(&med->med_open_head);
666 spin_lock_init(&med->med_open_lock);
670 static int mds_destroy_export(struct obd_export *export)
672 struct obd_device *obd = export->exp_obd;
673 struct mds_export_data *med = &export->exp_mds_data;
674 struct lvfs_run_ctxt saved;
678 mds_free_export_data(med);
679 target_destroy_export(export);
681 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
684 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
686 /* Close any open files (which may also cause orphan unlinking). */
687 spin_lock(&med->med_open_lock);
688 while (!list_empty(&med->med_open_head)) {
689 struct list_head *tmp = med->med_open_head.next;
690 struct mds_file_data *mfd =
691 list_entry(tmp, struct mds_file_data, mfd_list);
692 struct lustre_id sid;
694 BDEVNAME_DECLARE_STORAGE(btmp);
696 /* bug 1579: fix force-closing for 2.5 */
697 struct dentry *dentry = mfd->mfd_dentry;
699 list_del(&mfd->mfd_list);
700 spin_unlock(&med->med_open_lock);
702 down(&dentry->d_inode->i_sem);
703 rc = mds_read_inode_sid(obd, dentry->d_inode, &sid);
704 up(&dentry->d_inode->i_sem);
706 CERROR("Can't read inode self id, inode %lu, "
707 "rc %d\n", dentry->d_inode->i_ino, rc);
708 memset(&sid, 0, sizeof(sid));
711 /* If you change this message, be sure to update
712 * replay_single:test_46 */
713 CERROR("force closing client file handle for %.*s (%s:"
714 DLID4")\n", dentry->d_name.len, dentry->d_name.name,
715 ll_bdevname(dentry->d_inode->i_sb, btmp),
718 /* child inode->i_alloc_sem protects orphan_dec_test and
719 * is_orphan race, mds_mfd_close drops it */
720 DOWN_WRITE_I_ALLOC_SEM(dentry->d_inode);
721 rc = mds_mfd_close(NULL, 0, obd, mfd,
722 !(export->exp_flags & OBD_OPT_FAILOVER));
724 CDEBUG(D_INODE, "Error closing file: %d\n", rc);
725 spin_lock(&med->med_open_lock);
727 spin_unlock(&med->med_open_lock);
728 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
732 mds_client_free(export, !(export->exp_flags & OBD_OPT_FAILOVER));
736 static int mds_disconnect(struct obd_export *exp, unsigned long flags)
738 unsigned long irqflags;
739 struct obd_device *obd;
744 LASSERT(exp != NULL);
745 obd = class_exp2obd(exp);
747 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
748 exp->exp_handle.h_cookie);
754 * suppress any inter-mds requests durring disconnecting lmv if this is
755 * detected --force mode. This is needed to avoid endless recovery.
757 if (atomic_read(&mds->mds_real_clients) > 0 &&
758 !(exp->exp_flags & OBD_OPT_REAL_CLIENT))
759 flags |= OBD_OPT_FORCE;
761 if (!(exp->exp_flags & OBD_OPT_REAL_CLIENT)
762 && !atomic_read(&mds->mds_real_clients)) {
763 /* there was no client at all */
764 mds_md_disconnect(obd, flags);
767 if ((exp->exp_flags & OBD_OPT_REAL_CLIENT)
768 && atomic_dec_and_test(&mds->mds_real_clients)) {
769 /* time to drop LMV connections */
770 CDEBUG(D_OTHER, "%s: last real client %s disconnected. "
771 "Disconnnect from LMV now\n",
772 obd->obd_name, exp->exp_client_uuid.uuid);
773 mds_md_disconnect(obd, flags);
776 spin_lock_irqsave(&exp->exp_lock, irqflags);
777 exp->exp_flags = flags;
778 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
780 /* disconnect early so that clients can't keep using export */
781 rc = class_disconnect(exp, flags);
782 ldlm_cancel_locks_for_export(exp);
784 /* complete all outstanding replies */
785 spin_lock_irqsave(&exp->exp_lock, irqflags);
786 while (!list_empty(&exp->exp_outstanding_replies)) {
787 struct ptlrpc_reply_state *rs =
788 list_entry(exp->exp_outstanding_replies.next,
789 struct ptlrpc_reply_state, rs_exp_list);
790 struct ptlrpc_service *svc = rs->rs_srv_ni->sni_service;
792 spin_lock(&svc->srv_lock);
793 list_del_init(&rs->rs_exp_list);
794 ptlrpc_schedule_difficult_reply(rs);
795 spin_unlock(&svc->srv_lock);
797 spin_unlock_irqrestore(&exp->exp_lock, irqflags);
801 static int mds_getstatus(struct ptlrpc_request *req)
803 struct mds_obd *mds = mds_req2mds(req);
804 struct mds_body *body;
808 size = sizeof(*body);
810 rc = lustre_pack_reply(req, 1, &size, NULL);
811 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
812 CERROR("mds: out of memory for message: size=%d\n", size);
813 req->rq_status = -ENOMEM; /* superfluous? */
817 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
818 body->valid |= OBD_MD_FID;
820 memcpy(&body->id1, &mds->mds_rootid, sizeof(body->id1));
823 * the last_committed and last_xid fields are filled in for all replies
824 * already - no need to do so here also.
829 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
830 void *data, int flag)
835 if (flag == LDLM_CB_CANCELING) {
836 /* Don't need to do anything here. */
840 /* XXX layering violation! -phil */
841 lock_res_and_lock(lock);
844 * get this: if mds_blocking_ast is racing with mds_intent_policy, such
845 * that mds_blocking_ast is called just before l_i_p takes the ns_lock,
846 * then by the time we get the lock, we might not be the correct
847 * blocking function anymore. So check, and return early, if so.
849 if (lock->l_blocking_ast != mds_blocking_ast) {
850 unlock_res_and_lock(lock);
854 lock->l_flags |= LDLM_FL_CBPENDING;
855 do_ast = (!lock->l_readers && !lock->l_writers);
856 unlock_res_and_lock(lock);
859 struct lustre_handle lockh;
862 LDLM_DEBUG(lock, "already unused, calling ldlm_cli_cancel");
863 ldlm_lock2handle(lock, &lockh);
864 rc = ldlm_cli_cancel(&lockh);
866 CERROR("ldlm_cli_cancel: %d\n", rc);
868 LDLM_DEBUG(lock, "Lock still has references, will be "
874 static int mds_convert_md(struct obd_device *obd, struct inode *inode,
875 void *md, int size, int mea)
879 if (S_ISREG(inode->i_mode)) {
880 rc = mds_convert_lov_ea(obd, inode, md, size);
881 } else if (S_ISDIR(inode->i_mode)) {
883 rc = mds_convert_mea_ea(obd, inode, md, size);
885 rc = mds_convert_lov_ea(obd, inode, md, size);
888 CERROR("Invalid EA format (nor LOV or MEA) "
889 "is detected. Inode %lu/%u\n",
890 inode->i_ino, inode->i_generation);
896 int mds_get_md(struct obd_device *obd, struct inode *inode,
897 void *md, int *size, int lock, int mea)
906 rc = fsfilt_get_md(obd, inode, md, *size,
907 (mea ? EA_MEA : EA_LOV));
909 CERROR("Error %d reading eadata for ino %lu\n",
913 rc = mds_convert_md(obd, inode, md,
928 /* Call with lock=1 if you want mds_pack_md to take the i_sem.
929 * Call with lock=0 if the caller has already taken the i_sem. */
930 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
931 struct mds_body *body, struct inode *inode, int lock, int mea)
933 struct mds_obd *mds = &obd->u.mds;
938 lmm = lustre_msg_buf(msg, offset, 0);
940 /* Some problem with getting eadata when I sized the reply
942 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
946 lmm_size = msg->buflens[offset];
948 /* I don't really like this, but it is a sanity check on the client
949 * MD request. However, if the client doesn't know how much space
950 * to reserve for the MD, it shouldn't be bad to have too much space.
952 if (lmm_size > mds->mds_max_mdsize) {
953 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
954 inode->i_ino, lmm_size, mds->mds_max_mdsize);
958 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock, mea);
960 body->valid |= S_ISDIR(inode->i_mode) ?
961 OBD_MD_FLDIREA : OBD_MD_FLEASIZE;
964 body->valid |= OBD_MD_MEA;
966 body->eadatasize = lmm_size;
973 int mds_pack_link(struct dentry *dentry, struct ptlrpc_request *req,
974 struct mds_body *repbody, int reply_off)
976 struct inode *inode = dentry->d_inode;
981 symname = lustre_msg_buf(req->rq_repmsg, reply_off + 1,0);
982 LASSERT(symname != NULL);
983 len = req->rq_repmsg->buflens[reply_off + 1];
985 rc = inode->i_op->readlink(dentry, symname, len);
987 CERROR("readlink failed: %d\n", rc);
988 } else if (rc != len - 1) {
989 CERROR ("Unexpected readlink rc %d: expecting %d\n",
993 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
994 repbody->valid |= OBD_MD_LINKNAME;
995 repbody->eadatasize = rc + 1;
996 symname[rc] = 0; /* NULL terminate */
1003 int mds_pack_xattr(struct dentry *dentry, struct ptlrpc_request *req,
1004 struct mds_body *repbody, int req_off, int reply_off)
1006 struct inode *inode = dentry->d_inode;
1012 ea_name = lustre_msg_string(req->rq_reqmsg, req_off + 1, 0);
1013 len = req->rq_repmsg->buflens[reply_off + 1];
1015 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
1019 if (!strcmp(ea_name, XATTR_NAME_LUSTRE_ACL)) {
1020 struct rmtacl_upcall_desc desc;
1022 if (len != LUSTRE_ACL_SIZE_MAX || !value) {
1023 CERROR("no reply buffer prepared\n");
1027 memset(&desc, 0, sizeof(desc));
1029 desc.cmd = lustre_msg_string(req->rq_reqmsg, req_off + 2, 0);
1030 desc.cmdlen = req->rq_reqmsg->buflens[req_off + 2];
1031 desc.res = (char *) value;
1032 desc.reslen = LUSTRE_ACL_SIZE_MAX;
1034 mds_do_remote_acl_upcall(&desc);
1036 if (desc.upcall_status)
1037 RETURN(desc.upcall_status);
1039 if (desc.reslen > LUSTRE_ACL_SIZE_MAX) {
1040 CERROR("downcall claim reslen %u\n", desc.reslen);
1043 /* like remote setfacl, steal "flags" in mds_body as the
1044 * exececution status
1046 repbody->flags = desc.status;
1047 repbody->valid |= OBD_MD_FLXATTR;
1048 repbody->eadatasize = desc.reslen;
1053 if (inode->i_op && inode->i_op->getxattr)
1054 rc = inode->i_op->getxattr(dentry, ea_name, value, len);
1057 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1058 CERROR("getxattr failed: %d", rc);
1060 repbody->valid |= OBD_MD_FLXATTR;
1061 repbody->eadatasize = rc;
1068 int mds_pack_xattr_list(struct dentry *dentry, struct ptlrpc_request *req,
1069 struct mds_body *repbody, int reply_off)
1071 struct inode *inode = dentry->d_inode;
1076 len = req->rq_repmsg->buflens[reply_off + 1];
1078 value = lustre_msg_buf(req->rq_repmsg, reply_off + 1, len);
1081 if (inode->i_op && inode->i_op->getxattr)
1082 rc = inode->i_op->listxattr(dentry, value, len);
1085 CERROR("listxattr failed: %d", rc);
1087 repbody->valid |= OBD_MD_FLXATTRLIST;
1088 repbody->eadatasize = rc;
1095 int mds_pack_posix_acl(struct lustre_msg *repmsg, int *offset,
1096 struct mds_body *body, struct inode *inode)
1098 struct dentry de = { .d_inode = inode };
1099 __u32 buflen, *sizep;
1101 int size, pack_off = *offset;
1104 sizep = lustre_msg_buf(repmsg, pack_off++, 4);
1106 CERROR("can't locate returned acl size buf\n");
1110 if (!inode->i_op->getxattr)
1113 buflen = repmsg->buflens[pack_off];
1114 buf = lustre_msg_buf(repmsg, pack_off++, buflen);
1116 size = inode->i_op->getxattr(&de, XATTR_NAME_ACL_ACCESS, buf, buflen);
1117 if (size == -ENODATA || size == -EOPNOTSUPP)
1122 body->valid |= OBD_MD_FLACL;
1124 *sizep = cpu_to_le32(size);
1130 int mds_pack_remote_perm(struct ptlrpc_request *req, int *reply_off,
1131 struct mds_body *body, struct inode *inode)
1133 struct lustre_sec_desc *lsd;
1134 struct mds_remote_perm *perm;
1135 int pack_off = *reply_off;
1138 LASSERT(inode->i_op);
1139 LASSERT(inode->i_op->permission);
1140 LASSERT(req->rq_export->exp_mds_data.med_remote);
1142 perm = (struct mds_remote_perm *)
1143 lustre_msg_buf(req->rq_repmsg, pack_off++, sizeof(perm));
1147 memset(perm, 0, sizeof(*perm));
1149 /* obtain authenticated uid/gid and LSD permissions, which
1150 * might be different from current process context, from LSD
1152 lsd = mds_get_lsd(current->uid);
1154 CWARN("can't LSD of uid %u\n", current->uid);
1158 perm->mrp_auth_uid = lsd->lsd_uid;
1159 perm->mrp_auth_gid = lsd->lsd_gid;
1161 lsd_perms = mds_lsd_get_perms(lsd, 1, 0, req->rq_peer.peer_id.nid);
1162 if (lsd_perms & LSD_PERM_SETUID)
1163 perm->mrp_allow_setuid = 1;
1164 if (lsd_perms & LSD_PERM_SETGID)
1165 perm->mrp_allow_setgid = 1;
1169 /* permission bits of current user
1170 * XXX this is low efficient, could we do it in one blow?
1172 if (inode->i_op->permission(inode, MAY_EXEC, NULL) == 0)
1173 perm->mrp_perm |= MAY_EXEC;
1174 if (inode->i_op->permission(inode, MAY_WRITE, NULL) == 0)
1175 perm->mrp_perm |= MAY_WRITE;
1176 if (inode->i_op->permission(inode, MAY_READ, NULL) == 0)
1177 perm->mrp_perm |= MAY_READ;
1179 body->valid |= (OBD_MD_FLACL | OBD_MD_FLRMTACL);
1181 *reply_off = pack_off;
1186 int mds_pack_acl(struct ptlrpc_request *req, int *reply_off,
1187 struct mds_body *body, struct inode *inode)
1191 if (!req->rq_export->exp_mds_data.med_remote)
1192 rc = mds_pack_posix_acl(req->rq_repmsg, reply_off, body, inode);
1194 rc = mds_pack_remote_perm(req, reply_off, body, inode);
1199 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
1200 struct ptlrpc_request *req, int req_off,
1201 struct mds_body *reqbody, int reply_off,
1202 struct mds_req_sec_desc *rsd)
1204 struct mds_export_data *med = &req->rq_export->u.eu_mds_data;
1205 struct inode *inode = dentry->d_inode;
1206 struct mds_body *body;
1207 int rc = 0, offset = 0;
1210 if (inode == NULL && !(dentry->d_flags & DCACHE_CROSS_REF))
1213 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
1214 LASSERT(body != NULL); /* caller prepped reply */
1216 if (dentry->d_flags & DCACHE_CROSS_REF) {
1217 mds_pack_dentry2body(obd, body, dentry,
1218 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1219 CDEBUG(D_OTHER, "cross reference: "DLID4"\n",
1224 mds_pack_inode2body(obd, body, inode,
1225 (reqbody->valid & OBD_MD_FID) ? 1 : 0);
1227 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
1228 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
1230 /* guessing what kind og attribute do we need. */
1231 int is_mea = (S_ISDIR(inode->i_mode) &&
1232 (reqbody->valid & OBD_MD_MEA) != 0);
1234 rc = mds_pack_md(obd, req->rq_repmsg, reply_off + 1,
1235 body, inode, 1, is_mea);
1237 /* if we have LOV EA data, the OST holds size, atime, mtime. */
1238 if (!(body->valid & OBD_MD_FLEASIZE) &&
1239 !(body->valid & OBD_MD_FLDIREA))
1240 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
1241 OBD_MD_FLATIME | OBD_MD_FLMTIME);
1242 } else if (S_ISLNK(inode->i_mode) &&
1243 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
1244 rc = mds_pack_link(dentry, req, body, reply_off);
1245 } else if (reqbody->valid & OBD_MD_FLXATTR) {
1246 rc = mds_pack_xattr(dentry, req, body, req_off, reply_off);
1247 } else if (reqbody->valid & OBD_MD_FLXATTRLIST) {
1248 rc = mds_pack_xattr_list(dentry, req, body, reply_off);
1251 offset = reply_off + ((reqbody->valid & OBD_MD_FLEASIZE) ? 2 : 1);
1252 if (reqbody->valid & OBD_MD_FLACL) {
1253 rc = mds_pack_acl(req, &offset, body, inode);
1256 if (reqbody->valid & OBD_MD_FLKEY) {
1257 rc = mds_pack_gskey(obd, req->rq_repmsg, &offset,
1261 mds_pack_audit(obd, inode, body);
1264 mds_body_do_reverse_map(med, body);
1269 static int mds_getattr_pack_msg_cf(struct ptlrpc_request *req,
1270 struct dentry *dentry,
1273 int rc = 0, size[1] = {sizeof(struct mds_body)};
1276 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1277 CERROR("failed MDS_GETATTR_PACK test\n");
1278 req->rq_status = -ENOMEM;
1282 rc = lustre_pack_reply(req, 1, size, NULL);
1284 CERROR("lustre_pack_reply failed: rc %d\n", rc);
1285 GOTO(out, req->rq_status = rc);
1293 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct dentry *de,
1296 struct inode *inode = de->d_inode;
1297 struct mds_obd *mds = mds_req2mds(req);
1298 struct mds_body *body;
1299 int rc = 0, size[4] = {sizeof(*body)}, bufcount = 1;
1302 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
1303 LASSERT(body != NULL); /* checked by caller */
1304 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
1306 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
1307 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
1310 down(&inode->i_sem);
1311 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
1312 ((body->valid & OBD_MD_MEA) ? EA_MEA : EA_LOV));
1315 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1316 CERROR("error getting inode %lu MD: rc = %d\n",
1319 } else if (rc > mds->mds_max_mdsize) {
1321 CERROR("MD size %d larger than maximum possible %u\n",
1322 rc, mds->mds_max_mdsize);
1324 size[bufcount] = rc;
1327 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
1328 if (inode->i_size + 1 != body->eadatasize)
1329 CERROR("symlink size: %Lu, reply space: %d\n",
1330 inode->i_size + 1, body->eadatasize);
1331 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
1333 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
1334 inode->i_size + 1, body->eadatasize);
1335 } else if ((body->valid & OBD_MD_FLXATTR)) {
1336 char *ea_name = lustre_msg_string(req->rq_reqmsg,
1340 if (!strcmp(ea_name, XATTR_NAME_LUSTRE_ACL)) {
1341 size[bufcount] = LUSTRE_ACL_SIZE_MAX;
1343 if (inode->i_op && inode->i_op->getxattr)
1344 rc = inode->i_op->getxattr(de, ea_name,
1348 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1349 CERROR("error get inode %lu EA: %d\n",
1353 size[bufcount] = min_t(int,
1354 body->eadatasize, rc);
1358 } else if (body->valid & OBD_MD_FLXATTRLIST) {
1360 if (inode->i_op && inode->i_op->getxattr)
1361 rc = inode->i_op->listxattr(de, NULL, 0);
1364 if (rc != -ENODATA && rc != -EOPNOTSUPP)
1365 CERROR("error getting inode %lu EA: rc = %d\n",
1369 size[bufcount] = min_t(int, body->eadatasize, rc);
1374 /* may co-exist with OBD_MD_FLEASIZE */
1375 if (body->valid & OBD_MD_FLACL) {
1376 if (req->rq_export->exp_mds_data.med_remote) {
1377 size[bufcount++] = sizeof(struct mds_remote_perm);
1379 size[bufcount++] = sizeof(int);
1380 size[bufcount++] = xattr_acl_size(LL_ACL_MAX_ENTRIES);
1384 if (body->valid & OBD_MD_FLKEY) {
1385 size[bufcount++] = sizeof(int);
1386 size[bufcount++] = sizeof(struct crypto_key);
1389 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
1390 CERROR("failed MDS_GETATTR_PACK test\n");
1391 req->rq_status = -ENOMEM;
1392 GOTO(out, rc = -ENOMEM);
1395 rc = lustre_pack_reply(req, bufcount, size, NULL);
1397 CERROR("out of memory\n");
1398 GOTO(out, req->rq_status = rc);
1406 int mds_check_mds_num(struct obd_device *obd, struct inode *inode,
1407 char *name, int namelen)
1409 struct mea *mea = NULL;
1410 int mea_size, rc = 0;
1413 rc = mds_md_get_attr(obd, inode, &mea, &mea_size);
1416 if (mea != NULL && mea->mea_count) {
1418 * dir is already splitted, check if requested filename should
1419 * live at this MDS or at another one.
1421 int i = mea_name2idx(mea, name, namelen - 1);
1422 if (mea->mea_master != id_group(&mea->mea_ids[i])) {
1424 "inapropriate MDS(%d) for %s. should be "
1425 "%lu(%d)\n", mea->mea_master, name,
1426 (unsigned long)id_group(&mea->mea_ids[i]), i);
1432 OBD_FREE(mea, mea_size);
1436 int mds_getattr_size(struct obd_device *obd, struct dentry *dentry,
1437 struct ptlrpc_request *req, struct mds_body *body)
1439 struct inode *inode = dentry->d_inode;
1442 LASSERT(body != NULL);
1444 if (dentry->d_inode == NULL || !S_ISREG(inode->i_mode))
1447 if (obd->obd_recovering) {
1448 CDEBUG(D_INODE, "size for "DLID4" is unknown yet (recovering)\n",
1453 if (atomic_read(&inode->i_writecount)) {
1454 /* some one has opened the file for write.
1455 * mds doesn't know actual size */
1456 CDEBUG(D_INODE, "MDS doesn't know actual size for "DLID4"\n",
1460 CDEBUG(D_INODE, "MDS returns "LPD64"/"LPD64" for"DLID4"\n",
1461 body->size, body->blocks, OLID4(&body->id1));
1462 body->valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
1466 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
1467 struct lustre_handle *child_lockh, int child_part)
1469 struct obd_device *obd = req->rq_export->exp_obd;
1470 struct mds_obd *mds = &obd->u.mds;
1471 struct ldlm_reply *rep = NULL;
1472 struct lvfs_run_ctxt saved;
1473 struct mds_req_sec_desc *rsd;
1474 struct mds_body *body;
1475 struct dentry *dparent = NULL, *dchild = NULL;
1476 struct lvfs_ucred uc = {NULL, NULL,};
1477 struct lustre_handle parent_lockh[2] = {{0}, {0}};
1478 unsigned int namesize;
1479 int rc = 0, cleanup_phase = 0, resent_req = 0, update_mode, reply_offset;
1483 LASSERT(!strcmp(obd->obd_type->typ_name, OBD_MDS_DEVICENAME));
1484 MD_COUNTER_INCREMENT(obd, getattr_lock);
1486 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1488 CERROR("Can't unpack security desc\n");
1492 /* swab now, before anyone looks inside the request. */
1493 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1494 lustre_swab_mds_body);
1496 CERROR("Can't swab mds_body\n");
1497 GOTO(cleanup, rc = -EFAULT);
1500 LASSERT_REQSWAB(req, offset + 1);
1501 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
1503 CERROR("Can't unpack name\n");
1504 GOTO(cleanup, rc = -EFAULT);
1506 namesize = req->rq_reqmsg->buflens[offset + 1];
1508 /* namesize less than 2 means we have empty name, probably came from
1509 revalidate by cfid, so no point in having name to be set */
1513 LASSERT (offset == 1 || offset == 3);
1515 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*rep));
1521 rc = mds_init_ucred(&uc, req, rsd);
1523 if (child_lockh->cookie == 0)
1524 mds_audit_auth(req, &uc, AUDIT_STAT, &body->id1,
1529 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1530 cleanup_phase = 1; /* kernel context */
1531 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
1533 LASSERT(namesize > 0);
1534 if (child_lockh->cookie != 0) {
1535 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
1539 if (body->valid == OBD_MD_FLID) {
1540 struct mds_body *mds_reply;
1541 int size = sizeof(*mds_reply);
1545 dparent = mds_id2dentry(obd, &body->id1, NULL);
1546 if (IS_ERR(dparent)) {
1547 rc = PTR_ERR(dparent);
1551 * the user requested ONLY the inode number, so do a raw lookup.
1553 rc = lustre_pack_reply(req, 1, &size, NULL);
1555 CERROR("out of memory\n");
1559 dir = dparent->d_inode;
1560 LASSERT(dir->i_op->lookup_raw != NULL);
1561 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
1563 mds_reply = lustre_msg_buf(req->rq_repmsg, 0,
1564 sizeof(*mds_reply));
1566 id_ino(&mds_reply->id1) = inum;
1567 mds_reply->valid = OBD_MD_FLID;
1571 if (resent_req == 0) {
1572 LASSERT(id_fid(&body->id1) != 0);
1574 rc = mds_get_parent_child_locked(obd, mds, &body->id1,
1575 parent_lockh, &dparent,
1577 MDS_INODELOCK_UPDATE,
1580 child_lockh, &dchild,
1581 LCK_PR, child_part);
1585 cleanup_phase = 2; /* dchild, dparent, locks */
1588 * let's make sure this name should leave on this mds
1591 rc = mds_check_mds_num(obd, dparent->d_inode, name, namesize);
1595 /* we have no dentry here, drop LOOKUP bit */
1596 /* FIXME: we need MDS_INODELOCK_LOOKUP or not. */
1597 child_part &= ~MDS_INODELOCK_LOOKUP;
1598 CDEBUG(D_OTHER, "%s: retrieve attrs for "DLID4"\n",
1599 obd->obd_name, OLID4(&body->id1));
1601 dchild = mds_id2locked_dentry(obd, &body->id1, NULL,
1602 LCK_PR, parent_lockh,
1603 &update_mode, NULL, 0,
1604 MDS_INODELOCK_UPDATE);
1605 if (IS_ERR(dchild)) {
1606 CERROR("can't find inode with id "DLID4", err = %d\n",
1607 OLID4(&body->id1), (int)PTR_ERR(dchild));
1608 GOTO(cleanup, rc = PTR_ERR(dchild));
1610 memcpy(child_lockh, parent_lockh, sizeof(parent_lockh[0]));
1613 struct ldlm_lock *granted_lock;
1615 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
1616 granted_lock = ldlm_handle2lock(child_lockh);
1618 LASSERTF(granted_lock != NULL, LPU64"/%lu lockh "LPX64"\n",
1619 id_fid(&body->id1), (unsigned long)id_group(&body->id1),
1620 child_lockh->cookie);
1623 /* usual named request */
1624 dparent = mds_id2dentry(obd, &body->id1, NULL);
1625 LASSERT(!IS_ERR(dparent));
1626 dchild = ll_lookup_one_len(name, dparent, namesize - 1);
1627 LASSERT(!IS_ERR(dchild));
1629 /* client wants to get attr. by id */
1630 dchild = mds_id2dentry(obd, &body->id1, NULL);
1631 LASSERT(!IS_ERR(dchild));
1633 LDLM_LOCK_PUT(granted_lock);
1636 cleanup_phase = 2; /* dchild, dparent, locks */
1638 if (!DENTRY_VALID(dchild)) {
1639 intent_set_disposition(rep, DISP_LOOKUP_NEG);
1641 * in the intent case, the policy clears this error: the
1642 * disposition is enough.
1647 intent_set_disposition(rep, DISP_LOOKUP_POS);
1650 if (req->rq_repmsg == NULL) {
1651 if (dchild->d_flags & DCACHE_CROSS_REF)
1652 rc = mds_getattr_pack_msg_cf(req, dchild, offset);
1654 rc = mds_getattr_pack_msg(req, dchild, offset);
1656 CERROR ("mds_getattr_pack_msg: %d\n", rc);
1661 rc = mds_getattr_internal(obd, dchild, req, offset, body,
1664 GOTO(cleanup, rc); /* returns the lock to the client */
1666 /* probably MDS knows actual size? */
1667 body = lustre_msg_buf(req->rq_repmsg, reply_offset, sizeof(*body));
1668 LASSERT(body != NULL);
1669 mds_getattr_size(obd, dchild, req, body);
1674 switch (cleanup_phase) {
1676 if (resent_req == 0) {
1677 if (rc && DENTRY_VALID(dchild))
1678 ldlm_lock_decref(child_lockh, LCK_PR);
1680 ldlm_lock_decref(parent_lockh, LCK_PR);
1682 if (parent_lockh[1].cookie != 0)
1683 ldlm_lock_decref(parent_lockh + 1, update_mode);
1688 /* audit stuff for getattr */
1689 if (dchild->d_inode)
1690 mds_audit_stat(req, &body->id1, dchild, rc);
1694 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1696 mds_exit_ucred(&uc);
1701 static int mds_getattr(struct ptlrpc_request *req, int offset)
1703 struct obd_device *obd = req->rq_export->exp_obd;
1704 struct lvfs_run_ctxt saved;
1706 struct mds_req_sec_desc *rsd;
1707 struct mds_body *body;
1708 struct lvfs_ucred uc = {NULL, NULL,};
1712 MD_COUNTER_INCREMENT(obd, getattr);
1714 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1716 CERROR("Can't unpack security desc\n");
1720 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1721 lustre_swab_mds_body);
1723 CERROR ("Can't unpack body\n");
1727 rc = mds_init_ucred(&uc, req, rsd);
1729 mds_exit_ucred(&uc);
1733 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1734 de = mds_id2dentry(obd, &body->id1, NULL);
1736 rc = req->rq_status = PTR_ERR(de);
1740 rc = mds_getattr_pack_msg(req, de, offset);
1742 CERROR("mds_getattr_pack_msg: %d\n", rc);
1746 req->rq_status = mds_getattr_internal(obd, de, req, offset, body,
1752 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1753 mds_exit_ucred(&uc);
1756 static int mds_access_check(struct ptlrpc_request *req, int offset)
1758 struct obd_device *obd = req->rq_export->exp_obd;
1759 struct lvfs_run_ctxt saved;
1761 struct mds_req_sec_desc *rsd;
1762 struct mds_body *body;
1763 struct lvfs_ucred uc;
1764 int rep_size[2] = {sizeof(*body),
1765 sizeof(struct mds_remote_perm)};
1766 int rc = 0, rep_offset;
1769 if (!req->rq_export->exp_mds_data.med_remote) {
1770 CERROR("from local client "LPU64"\n", req->rq_peer.peer_id.nid);
1774 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1776 CERROR("Can't unpack security desc\n");
1780 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1781 lustre_swab_mds_body);
1783 CERROR ("Can't unpack body\n");
1787 MD_COUNTER_INCREMENT(obd, access_check);
1789 rc = mds_init_ucred(&uc, req, rsd);
1791 CERROR("init ucred error: %d\n", rc);
1794 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1796 de = mds_id2dentry(obd, &body->id1, NULL);
1798 CERROR("grab ino "LPU64": err %ld\n",
1799 body->id1.li_stc.u.e3s.l3s_ino, PTR_ERR(de));
1800 GOTO(out_pop, rc = PTR_ERR(de));
1803 rc = lustre_pack_reply(req, 2, rep_size, NULL);
1805 CERROR("pack reply error: %d\n", rc);
1806 GOTO(out_dput, rc = -EINVAL);
1809 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1813 rc = mds_pack_remote_perm(req, &rep_offset, body, de->d_inode);
1820 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1821 mds_exit_ucred(&uc);
1825 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1826 unsigned long max_age)
1831 spin_lock(&obd->obd_osfs_lock);
1832 rc = fsfilt_statfs(obd, obd->u.mds.mds_sb, max_age);
1834 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1835 spin_unlock(&obd->obd_osfs_lock);
1840 static int mds_statfs(struct ptlrpc_request *req)
1842 struct obd_device *obd = req->rq_export->exp_obd;
1843 int rc, size = sizeof(struct obd_statfs);
1846 /* This will trigger a watchdog timeout */
1847 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1848 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1850 rc = lustre_pack_reply(req, 1, &size, NULL);
1851 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1852 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1856 OBD_COUNTER_INCREMENT(obd, statfs);
1858 /* We call this so that we can cache a bit - 1 jiffie worth */
1859 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, 0, size),
1862 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1868 req->rq_status = rc;
1872 static int mds_sync(struct ptlrpc_request *req, int offset)
1874 struct obd_device *obd = req->rq_export->exp_obd;
1875 struct mds_obd *mds = &obd->u.mds;
1876 struct mds_body *body;
1877 int rc, size = sizeof(*body);
1880 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1881 lustre_swab_mds_body);
1883 GOTO(out, rc = -EPROTO);
1885 rc = lustre_pack_reply(req, 1, &size, NULL);
1886 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1887 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1891 if (id_ino(&body->id1) == 0) {
1892 /* an id of zero is taken to mean "sync whole filesystem" */
1893 rc = fsfilt_sync(obd, mds->mds_sb);
1897 /* just any file to grab fsync method - "file" arg unused */
1898 struct file *file = mds->mds_rcvd_filp;
1899 struct mds_body *rep_body;
1902 de = mds_id2dentry(obd, &body->id1, NULL);
1904 GOTO(out, rc = PTR_ERR(de));
1906 rc = file->f_op->fsync(NULL, de, 1);
1910 rep_body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep_body));
1911 mds_pack_inode2body(obd, rep_body, de->d_inode,
1912 (body->valid & OBD_MD_FID) ? 1 : 0);
1918 req->rq_status = rc;
1922 /* mds_readpage does not take a DLM lock on the inode, because the client must
1923 * already have a PR lock.
1925 * If we were to take another one here, a deadlock will result, if another
1926 * thread is already waiting for a PW lock. */
1927 static int mds_readpage(struct ptlrpc_request *req, int offset)
1929 struct obd_device *obd = req->rq_export->exp_obd;
1930 struct vfsmount *mnt;
1933 struct mds_req_sec_desc *rsd;
1934 struct mds_body *body, *repbody;
1935 struct lvfs_run_ctxt saved;
1936 int rc, size = sizeof(*repbody);
1937 struct lvfs_ucred uc = {NULL, NULL,};
1940 rc = lustre_pack_reply(req, 1, &size, NULL);
1941 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
1942 CERROR("mds: out of memory\n");
1943 GOTO(out, rc = -ENOMEM);
1946 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
1948 CERROR("Can't unpack security desc\n");
1949 GOTO (out, rc = -EFAULT);
1952 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1953 lustre_swab_mds_body);
1955 CERROR("Can't unpack body\n");
1956 GOTO (out, rc = -EFAULT);
1959 rc = mds_init_ucred(&uc, req, rsd);
1961 mds_audit_auth(req, &uc, AUDIT_READDIR, &body->id1,
1966 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1967 de = mds_id2dentry(obd, &body->id1, &mnt);
1969 GOTO(out_pop, rc = PTR_ERR(de));
1971 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1973 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1974 /* note: in case of an error, dentry_open puts dentry */
1976 GOTO(out_pop, rc = PTR_ERR(file));
1978 /* body->size is actually the offset -eeb */
1979 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1980 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1981 body->size, de->d_inode->i_blksize);
1982 GOTO(out_file, rc = -EFAULT);
1985 /* body->nlink is actually the #bytes to read -eeb */
1986 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1987 CERROR("size %u is not multiple of blocksize %lu\n",
1988 body->nlink, de->d_inode->i_blksize);
1989 GOTO(out_file, rc = -EFAULT);
1992 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*repbody));
1993 repbody->size = file->f_dentry->d_inode->i_size;
1994 repbody->valid = OBD_MD_FLSIZE;
1996 /* to make this asynchronous make sure that the handling function
1997 doesn't send a reply when this function completes. Instead a
1998 callback function would send the reply */
1999 /* body->size is actually the offset -eeb */
2000 rc = mds_sendpage(req, file, body->size, body->nlink);
2004 filp_close(file, 0);
2006 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2008 mds_exit_ucred(&uc);
2009 req->rq_status = rc;
2013 int mds_read_md(struct obd_device *obd, struct lustre_id *id,
2014 char **data, int *datalen)
2016 struct dentry *dentry;
2017 struct mds_obd *mds = &obd->u.mds;
2018 int rc = 0, mea = 0;
2025 dentry = mds_id2dentry(obd, id, NULL);
2027 GOTO(out, rc = PTR_ERR(dentry));
2029 if (!dentry->d_inode) {
2030 CERROR("Can't find object "DLID4".\n",
2032 GOTO(out_dentry, rc = -EINVAL);
2034 if (S_ISDIR(dentry->d_inode->i_mode)) {
2035 *datalen = obd_packmd(mds->mds_md_exp, NULL, NULL);
2038 *datalen = obd_packmd(mds->mds_dt_exp, NULL, NULL);
2041 OBD_ALLOC(ea, *datalen);
2044 GOTO(out_dentry, rc = PTR_ERR(dentry));
2047 down(&dentry->d_inode->i_sem);
2048 rc = fsfilt_get_md(obd, dentry->d_inode, *data, *datalen,
2049 (mea ? EA_MEA : EA_LOV));
2050 up(&dentry->d_inode->i_sem);
2053 CERROR("Error %d reading eadata for ino %lu\n",
2054 rc, dentry->d_inode->i_ino);
2060 EXPORT_SYMBOL(mds_read_md);
2062 int mds_reint(struct ptlrpc_request *req, int offset,
2063 struct lustre_handle *lockh)
2065 struct mds_update_record *rec;
2066 struct mds_req_sec_desc *rsd;
2070 OBD_ALLOC(rec, sizeof(*rec));
2074 rsd = lustre_swab_mds_secdesc(req, MDS_REQ_SECDESC_OFF);
2076 CERROR("Can't unpack security desc\n");
2077 GOTO(out, rc = -EFAULT);
2080 rc = mds_update_unpack(req, offset, rec);
2081 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
2082 CERROR("invalid record\n");
2083 GOTO(out, req->rq_status = -EINVAL);
2086 rc = mds_init_ucred(&rec->ur_uc, req, rsd);
2088 audit_op code = AUDIT_NONE;
2089 char * au_name = NULL;
2091 switch (rec->ur_opcode) {
2093 code = AUDIT_SETATTR;
2096 code = AUDIT_CREATE;
2097 au_name = rec->ur_name;
2098 au_len = rec->ur_namelen;
2104 code = AUDIT_UNLINK;
2107 code = AUDIT_RENAME;
2110 au_name = rec->ur_name;
2111 au_len = rec->ur_namelen;
2115 CERROR("Wrong opcode in reint\n");
2119 mds_audit_auth(req, &rec->ur_uc, code, rec->ur_id1,
2124 /* rc will be used to interrupt a for loop over multiple records */
2125 rc = mds_reint_rec(rec, offset, req, lockh);
2127 /* audit stuff for OPEN */
2128 if (offset == 3 && rec->ur_opcode == REINT_OPEN)
2129 mds_audit_open(req, rec, rc);
2132 mds_exit_ucred(&rec->ur_uc);
2133 OBD_FREE(rec, sizeof(*rec));
2137 static int mds_filter_recovery_request(struct ptlrpc_request *req,
2138 struct obd_device *obd, int *process)
2140 switch (req->rq_reqmsg->opc) {
2141 case MDS_CONNECT: /* This will never get here, but for completeness. */
2142 case OST_CONNECT: /* This will never get here, but for completeness. */
2143 case MDS_DISCONNECT:
2144 case OST_DISCONNECT:
2149 case MDS_SYNC: /* used in unmounting */
2154 *process = target_queue_recovery_request(req, obd);
2158 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
2160 /* XXX what should we set rq_status to here? */
2161 req->rq_status = -EAGAIN;
2162 RETURN(ptlrpc_error(req));
2166 static char *reint_names[] = {
2167 [REINT_SETATTR] "setattr",
2168 [REINT_CREATE] "create",
2169 [REINT_LINK] "link",
2170 [REINT_UNLINK] "unlink",
2171 [REINT_RENAME] "rename",
2172 [REINT_OPEN] "open",
2175 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER | \
2176 OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ| \
2177 OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME| \
2180 static void reconstruct_create(struct ptlrpc_request *req)
2182 struct mds_export_data *med = &req->rq_export->exp_mds_data;
2183 struct mds_client_data *mcd = med->med_mcd;
2184 struct dentry *dentry;
2185 struct ost_body *body;
2186 struct lustre_id id;
2190 /* copy rc, transno and disp; steal locks */
2191 mds_req_from_mcd(req, mcd);
2192 if (req->rq_status) {
2200 id_ino(&id) = mcd->mcd_last_data;
2201 LASSERT(id_ino(&id) != 0);
2203 dentry = mds_id2dentry(req2obd(req), &id, NULL);
2204 if (IS_ERR(dentry)) {
2205 CERROR("can't find inode "LPU64"\n", id_ino(&id));
2206 req->rq_status = PTR_ERR(dentry);
2211 CWARN("reconstruct reply for x"LPU64" (remote ino) "LPU64" -> %lu/%u\n",
2212 req->rq_xid, id_ino(&id), dentry->d_inode->i_ino,
2213 dentry->d_inode->i_generation);
2215 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
2216 obdo_from_inode(&body->oa, dentry->d_inode, FILTER_VALID_FLAGS);
2217 body->oa.o_id = dentry->d_inode->i_ino;
2218 body->oa.o_generation = dentry->d_inode->i_generation;
2219 body->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2221 down(&dentry->d_inode->i_sem);
2222 rc = mds_read_inode_sid(req2obd(req), dentry->d_inode, &id);
2223 up(&dentry->d_inode->i_sem);
2225 CERROR("Can't read inode self id, inode %lu, "
2226 "rc %d\n", dentry->d_inode->i_ino, rc);
2230 body->oa.o_fid = id_fid(&id);
2231 body->oa.o_mds = id_group(&id);
2237 static int mds_inode_init_acl(struct obd_device *obd, void *handle,
2238 struct dentry *de, void *xattr, int xattr_size)
2240 struct inode *inode = de->d_inode;
2241 struct posix_acl *acl;
2248 LASSERT(xattr_size > 0);
2250 if (!inode->i_op->getxattr || !inode->i_op->setxattr) {
2251 CERROR("backend fs dosen't support xattr\n");
2255 /* set default acl */
2256 if (S_ISDIR(inode->i_mode)) {
2257 rc = inode->i_op->setxattr(de, XATTR_NAME_ACL_DEFAULT,
2258 xattr, xattr_size, 0);
2260 CERROR("set default acl err: %d\n", rc);
2265 /* set access acl */
2266 acl = posix_acl_from_xattr(xattr, xattr_size);
2267 if (acl == NULL || IS_ERR(acl)) {
2268 CERROR("insane attr data\n");
2269 return PTR_ERR(acl);
2272 if (posix_acl_valid(acl)) {
2273 CERROR("default acl not valid: %d\n", rc);
2278 mode = inode->i_mode;
2279 rc = posix_acl_create_masq(acl, &mode);
2281 CERROR("create masq err %d\n", rc);
2285 if (inode->i_mode != mode) {
2286 struct iattr iattr = { .ia_valid = ATTR_MODE,
2290 rc2 = fsfilt_setattr(obd, de, handle, &iattr, 0);
2292 CERROR("setattr mode err: %d\n", rc2);
2299 /* we didn't change acl except mode bits of some
2300 * entries, so should be fit into original size.
2302 rc = posix_acl_to_xattr(acl, xattr, xattr_size);
2305 rc = inode->i_op->setxattr(de, XATTR_NAME_ACL_ACCESS,
2306 xattr, xattr_size, 0);
2308 CERROR("set access acl err: %d\n", rc);
2311 posix_acl_release(acl);
2315 static int mdt_obj_create(struct ptlrpc_request *req)
2317 struct obd_device *obd = req->rq_export->exp_obd;
2318 struct mds_obd *mds = &obd->u.mds;
2319 struct ost_body *body, *repbody;
2322 char idname[LL_ID_NAMELEN];
2323 int size = sizeof(*repbody);
2324 struct inode *parent_inode;
2325 struct lvfs_run_ctxt saved;
2326 int rc, cleanup_phase = 0;
2327 struct dentry *new = NULL;
2328 struct dentry_params dp;
2329 int mealen, flags = 0;
2330 struct lvfs_ucred uc;
2331 struct lustre_id id;
2333 void *handle = NULL;
2334 unsigned long cr_inum = 0;
2338 DEBUG_REQ(D_HA, req, "create remote object");
2339 parent_inode = mds->mds_unnamed_dir->d_inode;
2341 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
2342 lustre_swab_ost_body);
2346 /* acl data is packed transparently, no swab here */
2347 LASSERT(req->rq_reqmsg->bufcount >= 2);
2348 acl_size = req->rq_reqmsg->buflens[1];
2350 acl = lustre_msg_buf(req->rq_reqmsg, 1, acl_size);
2352 CERROR("No default acl buf?\n");
2357 rc = lustre_pack_reply(req, 1, &size, NULL);
2361 MDS_CHECK_RESENT(req, reconstruct_create(req));
2364 uc.luc_ginfo = NULL;
2365 uc.luc_uid = body->oa.o_uid;
2366 uc.luc_gid = body->oa.o_gid;
2367 uc.luc_fsuid = body->oa.o_uid;
2368 uc.luc_fsgid = body->oa.o_gid;
2370 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2371 repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
2373 /* in REPLAY case inum should be given (client or other MDS fills it) */
2374 if (body->oa.o_id && ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2375 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY))) {
2377 * this is re-create request from MDS holding directory name.
2378 * we have to lookup given ino/gen first. if it exists (good
2379 * case) then there is nothing to do. if it does not then we
2380 * have to recreate it.
2382 id_ino(&id) = body->oa.o_id;
2383 id_gen(&id) = body->oa.o_generation;
2385 new = mds_id2dentry(obd, &id, NULL);
2386 if (!IS_ERR(new) && new->d_inode) {
2387 struct lustre_id sid;
2389 CDEBUG(D_OTHER, "mkdir repairing %lu/%lu\n",
2390 (unsigned long)id_ino(&id),
2391 (unsigned long)id_gen(&id));
2393 obdo_from_inode(&repbody->oa, new->d_inode,
2394 FILTER_VALID_FLAGS);
2396 repbody->oa.o_id = new->d_inode->i_ino;
2397 repbody->oa.o_generation = new->d_inode->i_generation;
2398 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
2401 down(&new->d_inode->i_sem);
2402 rc = mds_read_inode_sid(obd, new->d_inode, &sid);
2403 up(&new->d_inode->i_sem);
2405 CERROR("Can't read inode self id "
2406 "inode %lu, rc %d.\n",
2407 new->d_inode->i_ino, rc);
2411 repbody->oa.o_fid = id_fid(&sid);
2412 repbody->oa.o_mds = id_group(&sid);
2413 LASSERT(id_fid(&sid) != 0);
2416 * here we could use fid passed in body->oa.o_fid and
2417 * thus avoid mds_read_inode_sid().
2419 cr_inum = new->d_inode->i_ino;
2420 GOTO(cleanup, rc = 0);
2424 down(&parent_inode->i_sem);
2425 handle = fsfilt_start(obd, parent_inode, FSFILT_OP_MKDIR, NULL);
2426 if (IS_ERR(handle)) {
2427 up(&parent_inode->i_sem);
2428 CERROR("fsfilt_start() failed, rc = %d\n",
2429 (int)PTR_ERR(handle));
2430 GOTO(cleanup, rc = PTR_ERR(handle));
2432 cleanup_phase = 1; /* transaction */
2435 rc = sprintf(idname, "%u.%u", ll_insecure_random_int(), current->pid);
2436 new = lookup_one_len(idname, mds->mds_unnamed_dir, rc);
2438 CERROR("%s: can't lookup new inode (%s) for mkdir: %d\n",
2439 obd->obd_name, idname, (int) PTR_ERR(new));
2440 fsfilt_commit(obd, mds->mds_sb, new->d_inode, handle, 0);
2441 up(&parent_inode->i_sem);
2442 RETURN(PTR_ERR(new));
2443 } else if (new->d_inode) {
2444 CERROR("%s: name exists. repeat\n", obd->obd_name);
2447 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2448 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2449 fid = body->oa.o_fid;
2451 fid = mds_alloc_fid(obd);
2453 new->d_fsdata = (void *)&dp;
2458 dp.p_group = mds->mds_num;
2460 if ((lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) ||
2461 (body->oa.o_flags & OBD_FL_RECREATE_OBJS)) {
2462 LASSERT(body->oa.o_id != 0);
2463 dp.p_inum = body->oa.o_id;
2464 DEBUG_REQ(D_HA, req, "replay create obj %lu/%lu",
2465 (unsigned long)body->oa.o_id,
2466 (unsigned long)body->oa.o_generation);
2469 rc = vfs_mkdir(parent_inode, new, body->oa.o_mode);
2472 rc = mds_inode_init_acl(obd, handle, new,
2475 up(&parent_inode->i_sem);
2479 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2480 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2481 new->d_inode->i_generation = body->oa.o_generation;
2482 mark_inode_dirty(new->d_inode);
2485 * avoiding asserts in cache flush case, as
2486 * @body->oa.o_id should be zero.
2488 if (body->oa.o_id) {
2489 LASSERTF(body->oa.o_id == new->d_inode->i_ino,
2490 "BUG 3550: failed to recreate obj "
2491 LPU64" -> %lu\n", body->oa.o_id,
2492 new->d_inode->i_ino);
2494 LASSERTF(body->oa.o_generation ==
2495 new->d_inode->i_generation,
2496 "BUG 3550: failed to recreate obj/gen "
2497 LPU64"/%u -> %lu/%u\n", body->oa.o_id,
2498 body->oa.o_generation,
2499 new->d_inode->i_ino,
2500 new->d_inode->i_generation);
2504 obdo_from_inode(&repbody->oa, new->d_inode, FILTER_VALID_FLAGS);
2505 repbody->oa.o_id = new->d_inode->i_ino;
2506 repbody->oa.o_generation = new->d_inode->i_generation;
2507 repbody->oa.o_valid |= OBD_MD_FLID | OBD_MD_FLGENER | OBD_MD_FID;
2509 if ((body->oa.o_flags & OBD_FL_RECREATE_OBJS) ||
2510 lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
2511 LASSERT(body->oa.o_id != 0);
2512 LASSERT(body->oa.o_fid != 0);
2515 mds_inode2id(obd, &id, new->d_inode, fid);
2516 mds_update_inode_ids(obd, new->d_inode, handle, &id,
2517 body->oa.o_valid & OBD_MD_FLID ?
2518 NULL : obdo_id(&body->oa));
2520 /* initializing o_fid after it is allocated. */
2521 repbody->oa.o_fid = id_fid(&id);
2522 repbody->oa.o_mds = id_group(&id);
2524 rc = fsfilt_del_dir_entry(obd, new);
2525 up(&parent_inode->i_sem);
2527 CERROR("can't remove name for object: %d\n", rc);
2531 cleanup_phase = 2; /* created directory object */
2533 CDEBUG(D_OTHER, "created dirobj: %lu/%lu mode %o\n",
2534 (unsigned long)new->d_inode->i_ino,
2535 (unsigned long)new->d_inode->i_generation,
2536 (unsigned)new->d_inode->i_mode);
2537 cr_inum = new->d_inode->i_ino;
2539 up(&parent_inode->i_sem);
2540 CERROR("%s: can't create dirobj: %d\n", obd->obd_name, rc);
2544 if (body->oa.o_valid & OBD_MD_FLID) {
2545 /* this is new object for splitted dir. We have to prevent
2546 * recursive splitting on it -bzzz */
2547 mealen = obd_size_diskmd(mds->mds_md_exp, NULL);
2549 OBD_ALLOC(mea, mealen);
2551 GOTO(cleanup, rc = -ENOMEM);
2553 mea->mea_magic = MEA_MAGIC_ALL_CHARS;
2554 mea->mea_master = body->oa.o_mds; /* master mds num */
2557 obdo2id(&mea->mea_ids[body->oa.o_mds], &body->oa);
2559 down(&new->d_inode->i_sem);
2560 rc = fsfilt_set_md(obd, new->d_inode, handle,
2561 mea, mealen, EA_MEA);
2562 up(&new->d_inode->i_sem);
2564 CERROR("fsfilt_set_md() failed, "
2567 OBD_FREE(mea, mealen);
2569 CDEBUG(D_OTHER, "%s: mark non-splittable %lu/%u - %d\n",
2570 obd->obd_name, new->d_inode->i_ino,
2571 new->d_inode->i_generation, flags);
2572 } else if (body->oa.o_easize) {
2573 /* we pass LCK_EX to split routine to signal that we have
2574 * exclusive access to the directory. simple because nobody
2575 * knows it already exists -bzzz */
2576 rc = mds_try_to_split_dir(obd, new, NULL,
2577 body->oa.o_easize, LCK_EX);
2579 CERROR("Can't split directory %lu, error = %d.\n",
2580 new->d_inode->i_ino, rc);
2588 if (rc == 0 && (body->oa.o_flags & OBD_FL_REINT)) {
2589 rc = mds_fidmap_add(obd, &id);
2591 CERROR("can't create fid->ino mapping, "
2598 switch (cleanup_phase) {
2599 case 2: /* object has been created, but we'll may want to replay it later */
2601 ptlrpc_require_repack(req);
2602 case 1: /* transaction */
2603 rc = mds_finish_transno(mds, parent_inode, handle,
2608 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
2612 static int mdt_get_info(struct ptlrpc_request *req)
2614 struct obd_export *exp = req->rq_export;
2619 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2621 DEBUG_REQ(D_HA, req, "no get_info key");
2624 keylen = req->rq_reqmsg->buflens[0];
2626 if ((keylen < strlen("mdsize") || strcmp(key, "mdsize") != 0) &&
2627 (keylen < strlen("mdsnum") || strcmp(key, "mdsnum") != 0) &&
2628 (keylen < strlen("lovdesc") || strcmp(key, "lovdesc") != 0) &&
2629 (keylen < strlen("getext") || strcmp(key, "getext") != 0) &&
2630 (keylen < strlen("rootid") || strcmp(key, "rootid") != 0))
2633 if (keylen >= strlen("rootid") && !strcmp(key, "rootid")) {
2634 struct lustre_id *reply;
2635 int size = sizeof(*reply);
2637 rc = lustre_pack_reply(req, 1, &size, NULL);
2641 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2642 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2643 } else if (keylen >= strlen("lovdesc") && !strcmp(key, "lovdesc")) {
2644 struct lov_desc *reply;
2645 int size = sizeof(*reply);
2647 rc = lustre_pack_reply(req, 1, &size, NULL);
2651 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2652 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2653 } else if (keylen >= strlen("getext") && !strcmp(key, "getext")) {
2654 struct fid_extent *reply;
2655 int size = sizeof(*reply);
2657 rc = lustre_pack_reply(req, 1, &size, NULL);
2661 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2662 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2665 int size = sizeof(*reply);
2667 rc = lustre_pack_reply(req, 1, &size, NULL);
2671 reply = lustre_msg_buf(req->rq_repmsg, 0, size);
2672 rc = obd_get_info(exp, keylen, key, (__u32 *)&size, reply);
2675 req->rq_repmsg->status = 0;
2679 static int mds_set_info(struct obd_export *exp, __u32 keylen,
2680 void *key, __u32 vallen, void *val)
2682 struct obd_device *obd;
2683 struct mds_obd *mds;
2687 obd = class_exp2obd(exp);
2689 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
2690 exp->exp_handle.h_cookie);
2695 if (keylen == 5 && memcmp(key, "audit", 5) == 0) {
2696 rc = mds_set_audit(obd, val);
2698 } else if (keylen >= strlen("ids") && memcmp(key, "ids", keylen) == 0) {
2699 struct lustre_id *ids = (struct lustre_id *)val;
2701 struct inode *inode;
2705 de = mds_id2dentry(obd, ids, NULL);
2708 CERROR("lookup by an id error %d\n", rc);
2711 inode = de->d_inode;
2713 GOTO(out_put, rc = -ENOENT);
2715 down(&inode->i_sem);
2716 handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
2717 if (IS_ERR(handle)) {
2719 GOTO(out_put, rc = PTR_ERR(handle));
2722 rc = mds_update_inode_ids(obd, inode, handle, NULL, ids + 1);
2724 err = fsfilt_commit(obd, mds->mds_sb, inode, handle,
2727 CERROR("error committing transaction: %d\n", err);
2736 if (keylen >= strlen("crypto_type") &&
2737 memcmp(key, "crypto_type", keylen) == 0) {
2738 rc = mds_set_crypto_type(obd, val, vallen);
2742 if (keylen >= strlen("setext") && !memcmp(key, "setext", keylen)) {
2743 struct fid_extent *ext = val;
2745 CDEBUG(D_IOCTL, "set last fid to extent ["LPD64"-"LPD64"]\n",
2746 ext->fe_start, ext->fe_width);
2748 /* set lastfid into fid extent start. All next object creates
2749 * will use that fid. */
2750 mds_set_last_fid(obd, ext->fe_start);
2752 /* setting the same extent to OSC to avoid ids intersecting in
2753 * object ids, as all cache MDSs have the same group 0. */
2754 rc = obd_set_info(mds->mds_dt_exp, strlen("setext"),
2755 "setext", sizeof(*ext), ext);
2757 CERROR("can't set extent ["LPD64"-"LPD64"] to %s, "
2758 "err %d\n", ext->fe_start, ext->fe_width,
2759 mds->mds_dt_exp->exp_obd->obd_name, rc);
2763 CDEBUG(D_IOCTL, "invalid key\n");
2767 static int mdt_set_info(struct ptlrpc_request *req)
2770 struct obd_export *exp = req->rq_export;
2771 int keylen, rc = 0, vallen = 0;
2774 key = lustre_msg_buf(req->rq_reqmsg, 0, 1);
2776 DEBUG_REQ(D_HA, req, "no set_info key");
2779 keylen = req->rq_reqmsg->buflens[0];
2781 if ((keylen == strlen("crypto_type") &&
2782 memcmp(key, "crypto_type", keylen) == 0)) {
2783 rc = lustre_pack_reply(req, 0, NULL, NULL);
2787 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2788 vallen = req->rq_reqmsg->buflens[1];
2790 rc = obd_set_info(exp, keylen, key, vallen, val);
2791 req->rq_repmsg->status = 0;
2793 } else if (keylen == 5 && memcmp(key, "audit", 5) == 0) {
2794 struct audit_attr_msg msg, *p;
2797 rc = lustre_pack_reply(req, 0, NULL, NULL);
2801 p = lustre_swab_reqbuf(req, 1, sizeof(msg),
2802 lustre_swab_audit_attr);
2805 CDEBUG(D_INFO, "Get new audit setting 0x%x\n", (__u32)msg.attr);
2806 rc = obd_set_info(exp, keylen, key, sizeof(msg), &msg);
2808 req->rq_repmsg->status = rc;
2810 } else if (keylen == strlen("ids") &&
2811 memcmp(key, "ids", keylen) == 0) {
2812 struct lustre_id *id, ids[2];
2814 rc = lustre_pack_reply(req, 0, NULL, NULL);
2817 id = lustre_swab_reqbuf(req, 1, sizeof(struct lustre_id),
2818 lustre_swab_lustre_id);
2820 id = lustre_swab_reqbuf(req, 2, sizeof(struct lustre_id),
2821 lustre_swab_lustre_id);
2824 rc = obd_set_info(exp, keylen, key, vallen, ids);
2825 req->rq_repmsg->status = rc;
2827 } else if (keylen == strlen("setext") &&
2828 memcmp(key, "setext", keylen) == 0) {
2829 rc = lustre_pack_reply(req, 0, NULL, NULL);
2833 val = lustre_msg_buf(req->rq_reqmsg, 1, 0);
2834 vallen = req->rq_reqmsg->buflens[1];
2836 rc = obd_set_info(exp, keylen, key, vallen, val);
2837 req->rq_repmsg->status = 0;
2841 CDEBUG(D_IOCTL, "invalid key\n");
2845 static void mds_revoke_export_locks(struct obd_export *exp)
2847 struct list_head *locklist = &exp->exp_ldlm_data.led_held_locks;
2848 struct list_head rpc_list;
2849 struct ldlm_lock *lock, *next;
2850 struct ldlm_lock_desc desc;
2852 /* don't do this for local client */
2853 if (!exp->u.eu_mds_data.med_remote)
2856 /* don't revoke locks during recovery */
2857 if (exp->exp_obd->obd_recovering)
2861 INIT_LIST_HEAD(&rpc_list);
2863 spin_lock(&exp->exp_ldlm_data.led_lock);
2864 list_for_each_entry_safe(lock, next, locklist, l_export_chain) {
2866 lock_res_and_lock(lock);
2867 if (lock->l_req_mode != lock->l_granted_mode) {
2868 unlock_res_and_lock(lock);
2872 LASSERT(lock->l_resource);
2873 if (lock->l_resource->lr_type != LDLM_IBITS &&
2874 lock->l_resource->lr_type != LDLM_PLAIN) {
2875 unlock_res_and_lock(lock);
2879 if (lock->l_flags & LDLM_FL_AST_SENT) {
2880 unlock_res_and_lock(lock);
2884 LASSERT(lock->l_blocking_ast);
2885 LASSERT(!lock->l_blocking_lock);
2887 lock->l_flags |= LDLM_FL_AST_SENT;
2888 unlock_res_and_lock(lock);
2890 list_move(&lock->l_export_chain, &rpc_list);
2892 spin_unlock(&exp->exp_ldlm_data.led_lock);
2894 while (!list_empty(&rpc_list)) {
2895 lock = list_entry(rpc_list.next, struct ldlm_lock,
2897 list_del_init(&lock->l_export_chain);
2899 /* the desc just pretend to exclusive */
2900 ldlm_lock2desc(lock, &desc);
2901 desc.l_req_mode = LCK_EX;
2902 desc.l_granted_mode = 0;
2904 lock->l_blocking_ast(lock, &desc, NULL, LDLM_CB_BLOCKING);
2909 static int mds_msg_check_version(struct lustre_msg *msg)
2915 case MDS_DISCONNECT:
2917 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2919 CERROR("bad opc %u version %08x, expecting %08x\n",
2920 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2925 case MDS_GETATTR_LOCK:
2926 case MDS_ACCESS_CHECK:
2930 case MDS_DONE_WRITING:
2933 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
2935 CERROR("bad opc %u version %08x, expecting %08x\n",
2936 msg->opc, msg->version, LUSTRE_MDS_VERSION);
2940 case LDLM_BL_CALLBACK:
2941 case LDLM_CP_CALLBACK:
2942 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
2944 CERROR("bad opc %u version %08x, expecting %08x\n",
2945 msg->opc, msg->version, LUSTRE_DLM_VERSION);
2947 case OBD_LOG_CANCEL:
2948 case LLOG_ORIGIN_HANDLE_OPEN:
2949 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
2950 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
2951 case LLOG_ORIGIN_HANDLE_READ_HEADER:
2952 case LLOG_ORIGIN_HANDLE_CLOSE:
2954 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
2956 CERROR("bad opc %u version %08x, expecting %08x\n",
2957 msg->opc, msg->version, LUSTRE_LOG_VERSION);
2963 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
2965 CERROR("bad opc %u version %08x, expecting %08x\n",
2966 msg->opc, msg->version, LUSTRE_OBD_VERSION);
2969 case SEC_INIT_CONTINUE:
2974 CERROR("MDS unknown opcode %d\n", msg->opc);
2982 int mds_handle(struct ptlrpc_request *req)
2984 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
2985 struct obd_device *obd = NULL;
2986 struct mds_obd *mds = NULL; /* quell gcc overwarning */
2990 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
2992 rc = mds_msg_check_version(req->rq_reqmsg);
2994 CERROR("MDS drop mal-formed request\n");
2998 /* Security opc should NOT trigger any recovery events */
2999 if (req->rq_reqmsg->opc == SEC_INIT ||
3000 req->rq_reqmsg->opc == SEC_INIT_CONTINUE) {
3001 if (req->rq_export) {
3002 mds_req_add_idmapping(req,
3003 &req->rq_export->exp_mds_data);
3004 mds_revoke_export_locks(req->rq_export);
3007 } else if (req->rq_reqmsg->opc == SEC_FINI) {
3008 if (req->rq_export) {
3009 mds_req_del_idmapping(req,
3010 &req->rq_export->exp_mds_data);
3011 mds_revoke_export_locks(req->rq_export);
3016 LASSERT(current->journal_info == NULL);
3017 /* XXX identical to OST */
3018 if (req->rq_reqmsg->opc != MDS_CONNECT) {
3019 struct mds_export_data *med;
3022 if (req->rq_export == NULL) {
3023 CERROR("operation %d on unconnected MDS from %s\n",
3024 req->rq_reqmsg->opc,
3026 req->rq_status = -ENOTCONN;
3027 GOTO(out, rc = -ENOTCONN);
3030 med = &req->rq_export->exp_mds_data;
3031 obd = req->rq_export->exp_obd;
3034 /* sanity check: if the xid matches, the request must
3035 * be marked as a resent or replayed */
3036 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
3037 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid)) {
3038 LASSERTF(lustre_msg_get_flags(req->rq_reqmsg) &
3039 (MSG_RESENT | MSG_REPLAY),
3040 "rq_xid "LPU64" matches last_xid, "
3041 "expected RESENT flag\n",
3044 /* else: note the opposite is not always true; a
3045 * RESENT req after a failover will usually not match
3046 * the last_xid, since it was likely never
3047 * committed. A REPLAYed request will almost never
3048 * match the last xid, however it could for a
3049 * committed, but still retained, open. */
3051 spin_lock_bh(&obd->obd_processing_task_lock);
3052 recovering = obd->obd_recovering;
3053 spin_unlock_bh(&obd->obd_processing_task_lock);
3055 rc = mds_filter_recovery_request(req, obd,
3057 if (rc || should_process == 0) {
3059 } else if (should_process < 0) {
3060 req->rq_status = should_process;
3061 rc = ptlrpc_error(req);
3067 switch (req->rq_reqmsg->opc) {
3069 DEBUG_REQ(D_INODE, req, "connect");
3070 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
3071 rc = target_handle_connect(req);
3073 struct mds_export_data *med;
3075 LASSERT(req->rq_export);
3076 med = &req->rq_export->u.eu_mds_data;
3077 mds_init_export_data(req, med);
3078 mds_req_add_idmapping(req, med);
3080 /* Now that we have an export, set mds. */
3081 obd = req->rq_export->exp_obd;
3082 mds = mds_req2mds(req);
3086 case MDS_DISCONNECT:
3087 DEBUG_REQ(D_INODE, req, "disconnect");
3088 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
3089 rc = target_handle_disconnect(req);
3090 req->rq_status = rc; /* superfluous? */
3094 DEBUG_REQ(D_INODE, req, "getstatus");
3095 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
3096 rc = mds_getstatus(req);
3100 DEBUG_REQ(D_INODE, req, "getattr");
3101 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
3102 rc = mds_getattr(req, MDS_REQ_REC_OFF);
3105 case MDS_ACCESS_CHECK:
3106 DEBUG_REQ(D_INODE, req, "access_check");
3107 OBD_FAIL_RETURN(OBD_FAIL_MDS_ACCESS_CHECK_NET, 0);
3108 rc = mds_access_check(req, MDS_REQ_REC_OFF);
3111 case MDS_GETATTR_LOCK: {
3112 struct lustre_handle lockh;
3113 DEBUG_REQ(D_INODE, req, "getattr_lock");
3114 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_LOCK_NET, 0);
3116 /* If this request gets a reconstructed reply, we won't be
3117 * acquiring any new locks in mds_getattr_lock, so we don't
3121 rc = mds_getattr_lock(req, MDS_REQ_REC_OFF, &lockh,
3122 MDS_INODELOCK_UPDATE);
3123 /* this non-intent call (from an ioctl) is special */
3124 req->rq_status = rc;
3125 if (rc == 0 && lockh.cookie)
3126 ldlm_lock_decref(&lockh, LCK_PR);
3130 DEBUG_REQ(D_INODE, req, "statfs");
3131 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
3132 rc = mds_statfs(req);
3136 DEBUG_REQ(D_INODE, req, "readpage");
3137 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
3138 rc = mds_readpage(req, MDS_REQ_REC_OFF);
3140 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
3141 if (req->rq_reply_state) {
3142 lustre_free_reply_state (req->rq_reply_state);
3143 req->rq_reply_state = NULL;
3150 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, MDS_REQ_REC_OFF,
3153 int size[3] = {sizeof(struct mds_body), mds->mds_max_mdsize,
3154 mds->mds_max_cookiesize};
3157 /* NB only peek inside req now; mds_reint() will swab it */
3159 CERROR ("Can't inspect opcode\n");
3164 if (lustre_msg_swabbed (req->rq_reqmsg))
3167 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
3168 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
3169 reint_names[opc] == NULL) ? reint_names[opc] :
3172 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
3174 if (opc == REINT_UNLINK || opc == REINT_RENAME)
3176 else if (opc == REINT_OPEN)
3181 /* for SETATTR: I have different reply setting for
3182 * remote setfacl, so delay the reply buffer allocation.
3184 if (opc != REINT_SETATTR) {
3185 rc = lustre_pack_reply(req, bufcount, size, NULL);
3190 rc = mds_reint(req, MDS_REQ_REC_OFF, NULL);
3191 fail = OBD_FAIL_MDS_REINT_NET_REP;
3196 DEBUG_REQ(D_INODE, req, "close");
3197 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
3198 rc = mds_close(req, MDS_REQ_REC_OFF);
3201 case MDS_DONE_WRITING:
3202 DEBUG_REQ(D_INODE, req, "done_writing");
3203 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
3204 rc = mds_done_writing(req, MDS_REQ_REC_OFF);
3208 DEBUG_REQ(D_INODE, req, "pin");
3209 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
3210 rc = mds_pin(req, MDS_REQ_REC_OFF);
3214 DEBUG_REQ(D_INODE, req, "sync");
3215 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
3216 rc = mds_sync(req, MDS_REQ_REC_OFF);
3219 DEBUG_REQ(D_INODE, req, "parseid");
3220 rc = mds_parse_id(req);
3223 DEBUG_REQ(D_INODE, req, "ping");
3224 rc = target_handle_ping(req);
3227 case OBD_LOG_CANCEL:
3228 CDEBUG(D_INODE, "log cancel\n");
3229 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
3230 rc = -ENOTSUPP; /* la la la */
3234 DEBUG_REQ(D_INODE, req, "enqueue");
3235 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
3236 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
3237 ldlm_server_blocking_ast, NULL);
3238 fail = OBD_FAIL_LDLM_REPLY;
3241 DEBUG_REQ(D_INODE, req, "convert");
3242 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
3243 rc = ldlm_handle_convert(req);
3245 case LDLM_BL_CALLBACK:
3246 case LDLM_CP_CALLBACK:
3247 DEBUG_REQ(D_INODE, req, "callback");
3248 CERROR("callbacks should not happen on MDS\n");
3250 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
3252 case LLOG_ORIGIN_HANDLE_OPEN:
3253 DEBUG_REQ(D_INODE, req, "llog_init");
3254 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3255 rc = llog_origin_handle_open(req);
3257 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
3258 DEBUG_REQ(D_INODE, req, "llog next block");
3259 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3260 rc = llog_origin_handle_next_block(req);
3262 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
3263 DEBUG_REQ(D_INODE, req, "llog prev block");
3264 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3265 rc = llog_origin_handle_prev_block(req);
3267 case LLOG_ORIGIN_HANDLE_READ_HEADER:
3268 DEBUG_REQ(D_INODE, req, "llog read header");
3269 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3270 rc = llog_origin_handle_read_header(req);
3272 case LLOG_ORIGIN_HANDLE_CLOSE:
3273 DEBUG_REQ(D_INODE, req, "llog close");
3274 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3275 rc = llog_origin_handle_close(req);
3278 DEBUG_REQ(D_INODE, req, "ost_create");
3279 rc = mdt_obj_create(req);
3282 DEBUG_REQ(D_INODE, req, "get_info");
3283 rc = mdt_get_info(req);
3286 DEBUG_REQ(D_INODE, req, "set_info");
3287 rc = mdt_set_info(req);
3290 CDEBUG(D_INODE, "write\n");
3291 OBD_FAIL_RETURN(OBD_FAIL_OST_BRW_NET, 0);
3292 rc = ost_brw_write(req, NULL);
3293 LASSERT(current->journal_info == NULL);
3294 /* mdt_brw sends its own replies */
3298 DEBUG_REQ(D_INODE, req, "llog catinfo");
3299 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
3300 rc = llog_catinfo(req);
3303 req->rq_status = -ENOTSUPP;
3304 rc = ptlrpc_error(req);
3308 LASSERT(current->journal_info == NULL);
3312 /* If we're DISCONNECTing, the mds_export_data is already freed */
3313 if (!rc && req->rq_reqmsg->opc != MDS_DISCONNECT) {
3314 struct mds_export_data *med = &req->rq_export->exp_mds_data;
3315 struct obd_device *obd = list_entry(mds, struct obd_device,
3317 req->rq_repmsg->last_xid =
3318 le64_to_cpu(med->med_mcd->mcd_last_xid);
3320 if (!obd->obd_no_transno) {
3321 req->rq_repmsg->last_committed =
3322 obd->obd_last_committed;
3324 DEBUG_REQ(D_IOCTL, req,
3325 "not sending last_committed update");
3327 CDEBUG(D_INFO, "last_transno "LPU64", last_committed "LPU64
3329 mds->mds_last_transno, obd->obd_last_committed,
3335 target_send_reply(req, rc, fail);
3339 /* Update the server data on disk. This stores the new mount_count and also the
3340 * last_rcvd value to disk. If we don't have a clean shutdown, then the server
3341 * last_rcvd value may be less than that of the clients. This will alert us
3342 * that we may need to do client recovery.
3344 * Also assumes for mds_last_transno that we are not modifying it (no locking).
3346 int mds_update_server_data(struct obd_device *obd, int force_sync)
3348 struct mds_obd *mds = &obd->u.mds;
3349 struct mds_server_data *msd = mds->mds_server_data;
3350 struct file *filp = mds->mds_rcvd_filp;
3351 struct lvfs_run_ctxt saved;
3356 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3357 msd->msd_last_transno = cpu_to_le64(mds->mds_last_transno);
3359 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
3360 mds->mds_mount_count, mds->mds_last_transno);
3361 rc = fsfilt_write_record(obd, filp, msd, sizeof(*msd), &off, force_sync);
3363 CERROR("error writing MDS server data: rc = %d\n", rc);
3364 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3369 /* saves last allocated fid counter to file. */
3370 int mds_update_last_fid(struct obd_device *obd, void *handle,
3373 struct mds_obd *mds = &obd->u.mds;
3374 struct file *filp = mds->mds_fid_filp;
3375 struct lvfs_run_ctxt saved;
3381 spin_lock(&mds->mds_last_fid_lock);
3382 last_fid = mds->mds_last_fid;
3383 spin_unlock(&mds->mds_last_fid_lock);
3385 CDEBUG(D_SUPER, "MDS last_fid is #"LPU64"\n",
3389 fsfilt_add_journal_cb(obd, mds->mds_sb, last_fid,
3390 handle, mds_commit_last_fid_cb,
3394 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3395 rc = fsfilt_write_record(obd, filp, &last_fid, sizeof(last_fid),
3397 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3400 CERROR("error writing MDS last_fid #"LPU64
3401 ", err = %d\n", last_fid, rc);
3405 CDEBUG(D_SUPER, "wrote fid #"LPU64" at idx "
3406 "%llu: err = %d\n", last_fid, off, rc);
3411 void mds_set_last_fid(struct obd_device *obd, __u64 fid)
3413 struct mds_obd *mds = &obd->u.mds;
3415 spin_lock(&mds->mds_last_fid_lock);
3416 if (fid > mds->mds_last_fid)
3417 mds->mds_last_fid = fid;
3418 spin_unlock(&mds->mds_last_fid_lock);
3421 void mds_commit_last_transno_cb(struct obd_device *obd,
3422 __u64 transno, void *data,
3425 obd_transno_commit_cb(obd, transno, error);
3428 void mds_commit_last_fid_cb(struct obd_device *obd,
3429 __u64 fid, void *data,
3433 CERROR("%s: fid "LPD64" commit error: %d\n",
3434 obd->obd_name, fid, error);
3438 CDEBUG(D_HA, "%s: fid "LPD64" committed\n",
3439 obd->obd_name, fid);
3442 __u64 mds_alloc_fid(struct obd_device *obd)
3444 struct mds_obd *mds = &obd->u.mds;
3447 spin_lock(&mds->mds_last_fid_lock);
3448 fid = ++mds->mds_last_fid;
3449 spin_unlock(&mds->mds_last_fid_lock);
3455 * reads inode self id from inode EA. Probably later this should be replaced by
3456 * caching inode self id to avoid raeding it every time it is needed.
3458 int mds_read_inode_sid(struct obd_device *obd, struct inode *inode,
3459 struct lustre_id *id)
3464 LASSERT(id != NULL);
3465 LASSERT(obd != NULL);
3466 LASSERT(inode != NULL);
3468 rc = fsfilt_get_md(obd, inode, &id->li_fid,
3469 sizeof(id->li_fid), EA_SID);
3471 CERROR("fsfilt_get_md() failed, "
3480 id_ino(id) = inode->i_ino;
3481 id_gen(id) = inode->i_generation;
3482 id_type(id) = S_IFMT & inode->i_mode;
3487 int mds_read_inode_pid(struct obd_device *obd, struct inode *inode,
3488 struct lustre_id *id)
3493 LASSERT(inode && id);
3495 rc = fsfilt_get_md(obd, inode, id, sizeof(*id), EA_PID);
3497 CERROR("get parent id from EA failed, rc=%d\n", rc);
3506 /* updates inode self id in EA. */
3507 int mds_update_inode_ids(struct obd_device *obd, struct inode *inode,
3508 void *handle, struct lustre_id *id,
3509 struct lustre_id *pid)
3515 LASSERT(id == NULL || id_fid(id) != 0);
3516 LASSERT(pid == NULL || id_fid(pid) != 0);
3517 LASSERT(obd != NULL);
3518 LASSERT(inode != NULL);
3521 mds_set_last_fid(obd, id_fid(id));
3522 rc = fsfilt_set_md(obd, inode, handle, &id->li_fid,
3523 sizeof(id->li_fid), EA_SID);
3524 LASSERTF(rc == 0, "failed to update fid: %d\n", rc);
3527 rc = fsfilt_set_md(obd, inode, handle, pid,
3528 sizeof(*pid), EA_PID);
3529 LASSERTF(rc == 0, "failed to update parent fid: %d\n", rc);
3535 /* mount the file system (secretly) */
3536 static int mds_setup(struct obd_device *obd, obd_count len, void *buf)
3538 struct lustre_cfg* lcfg = buf;
3539 struct mds_obd *mds = &obd->u.mds;
3540 struct lvfs_obd_ctxt *lvfs_ctxt = NULL;
3541 char *options = NULL;
3542 struct vfsmount *mnt;
3548 if (lcfg->lcfg_bufcount < 3)
3549 RETURN(rc = -EINVAL);
3551 if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0)
3552 RETURN(rc = -EINVAL);
3554 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
3555 if (IS_ERR(obd->obd_fsops))
3556 RETURN(rc = PTR_ERR(obd->obd_fsops));
3558 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
3560 page = get_zeroed_page(GFP_KERNEL);
3564 options = (char *)page;
3567 * here we use "iopen_nopriv" hardcoded, because it affects MDS utility
3568 * and the rest of options are passed by mount options. Probably this
3569 * should be moved to somewhere else like startup scripts or lconf. */
3570 sprintf(options, "iopen_nopriv");
3572 if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0 && lustre_cfg_buf(lcfg, 4))
3573 sprintf(options + strlen(options), ",%s",
3574 lustre_cfg_string(lcfg, 4));
3576 /* we have to know mdsnum before touching underlying fs -bzzz */
3577 atomic_set(&mds->mds_open_count, 0);
3578 sema_init(&mds->mds_md_sem, 1);
3579 mds->mds_md_connected = 0;
3580 mds->mds_md_name = NULL;
3582 if (LUSTRE_CFG_BUFLEN(lcfg, 5) > 0 && lustre_cfg_buf(lcfg, 5) &&
3583 strncmp(lustre_cfg_string(lcfg, 5), "dumb", LUSTRE_CFG_BUFLEN(lcfg, 5))) {
3586 generate_random_uuid(uuid);
3587 class_uuid_unparse(uuid, &mds->mds_md_uuid);
3589 OBD_ALLOC(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5));
3590 if (mds->mds_md_name == NULL)
3591 RETURN(rc = -ENOMEM);
3593 memcpy(mds->mds_md_name, lustre_cfg_buf(lcfg, 5),
3594 LUSTRE_CFG_BUFLEN(lcfg, 5));
3596 CDEBUG(D_OTHER, "MDS: %s is master for %s\n",
3597 obd->obd_name, mds->mds_md_name);
3599 rc = mds_md_connect(obd, mds->mds_md_name);
3601 OBD_FREE(mds->mds_md_name, LUSTRE_CFG_BUFLEN(lcfg, 5));
3606 mds->mds_obd_type = MDS_MASTER_OBD;
3608 if (LUSTRE_CFG_BUFLEN(lcfg, 6) > 0 && lustre_cfg_buf(lcfg, 6) &&
3609 strncmp(lustre_cfg_string(lcfg, 6), "dumb",
3610 LUSTRE_CFG_BUFLEN(lcfg, 6))) {
3611 if (!memcmp(lustre_cfg_string(lcfg, 6), "master",
3612 strlen("master"))) {
3613 mds->mds_obd_type = MDS_MASTER_OBD;
3614 } else if (!memcmp(lustre_cfg_string(lcfg, 6), "cache",
3616 mds->mds_obd_type = MDS_CACHE_OBD;
3620 rc = lvfs_mount_fs(lustre_cfg_string(lcfg, 1),
3621 lustre_cfg_string(lcfg, 2),
3622 options, 0, &lvfs_ctxt);
3626 if (rc || !lvfs_ctxt) {
3627 CERROR("lvfs_mount_fs failed: rc = %d\n", rc);
3631 mnt = lvfs_ctxt->loc_mnt;
3632 mds->mds_lvfs_ctxt = lvfs_ctxt;
3633 ll_clear_rdonly(ll_sbdev(mnt->mnt_sb));
3635 CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt);
3637 mds->mds_fidext_thumb = 0;
3638 sema_init(&mds->mds_epoch_sem, 1);
3639 atomic_set(&mds->mds_real_clients, 0);
3640 spin_lock_init(&mds->mds_fidext_lock);
3641 spin_lock_init(&mds->mds_fidmap_lock);
3642 spin_lock_init(&mds->mds_transno_lock);
3643 spin_lock_init(&mds->mds_last_fid_lock);
3644 sema_init(&mds->mds_orphan_recovery_sem, 1);
3645 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
3647 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
3648 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
3650 if (obd->obd_namespace == NULL) {
3651 mds_cleanup(obd, 0);
3652 GOTO(err_put, rc = -ENOMEM);
3654 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
3656 rc = mds_fs_setup(obd, mnt);
3658 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
3663 rc = llog_start_commit_thread();
3668 if (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 && lustre_cfg_buf(lcfg, 3) &&
3669 strncmp(lustre_cfg_string(lcfg, 3), "dumb",
3670 LUSTRE_CFG_BUFLEN(lcfg, 3))) {
3673 generate_random_uuid(uuid);
3674 class_uuid_unparse(uuid, &mds->mds_dt_uuid);
3676 OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
3677 if (mds->mds_profile == NULL)
3678 GOTO(err_fs, rc = -ENOMEM);
3680 strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
3681 LUSTRE_CFG_BUFLEN(lcfg, 3));
3685 * setup root dir and files ID dir if lmv already connected, or there is
3688 if (mds->mds_md_exp || (LUSTRE_CFG_BUFLEN(lcfg, 3) > 0 &&
3689 lustre_cfg_buf(lcfg, 3) &&
3690 strncmp(lustre_cfg_string(lcfg, 3), "dumb",
3691 LUSTRE_CFG_BUFLEN(lcfg, 3)))) {
3692 rc = mds_fs_setup_rootid(obd);
3696 rc = mds_fs_setup_virtid(obd);
3702 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
3703 "mds_ldlm_client", &obd->obd_ldlm_client);
3704 obd->obd_replayable = 1;
3706 mds->mds_crypto_type = NO_CRYPTO;
3708 rc = mds_postsetup(obd);
3715 /* No extra cleanup needed for llog_init_commit_thread() */
3716 mds_fs_cleanup(obd, 0);
3718 ldlm_namespace_free(obd->obd_namespace, 0);
3719 obd->obd_namespace = NULL;
3722 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3726 fsfilt_put_ops(obd->obd_fsops);
3730 static int mds_fs_post_setup(struct obd_device *obd)
3732 struct mds_obd *mds = &obd->u.mds;
3733 struct dentry *dentry;
3737 dentry = mds_id2dentry(obd, &mds->mds_rootid, NULL);
3738 if (IS_ERR(dentry)) {
3739 CERROR("Can't find ROOT, err = %d\n",
3740 (int)PTR_ERR(dentry));
3741 RETURN(PTR_ERR(dentry));
3743 rc = fsfilt_post_setup(obd, dentry);
3744 //set id2name function handler
3745 fsfilt_set_info(obd, mds->mds_sb, NULL, 7, "id2name",
3746 sizeof(mds_audit_id2name), mds_audit_id2name);
3752 static int mds_postsetup(struct obd_device *obd)
3754 struct mds_obd *mds = &obd->u.mds;
3758 rc = obd_llog_setup(obd, &obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT,
3759 obd, 0, NULL, &llog_lvfs_ops);
3763 if (mds->mds_profile) {
3764 struct llog_ctxt *lgctxt;
3765 struct lvfs_run_ctxt saved;
3766 struct lustre_profile *lprof;
3767 struct config_llog_instance cfg;
3769 cfg.cfg_instance = NULL;
3770 cfg.cfg_uuid = mds->mds_dt_uuid;
3771 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3773 lgctxt = llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT);
3775 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3776 GOTO(err_llog, rc = -EINVAL);
3779 rc = class_config_process_llog(lgctxt, mds->mds_profile, &cfg);
3780 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3785 lprof = class_get_profile(mds->mds_profile);
3786 if (lprof == NULL) {
3787 CERROR("No profile found: %s\n", mds->mds_profile);
3788 GOTO(err_cleanup, rc = -ENOENT);
3790 rc = mds_dt_connect(obd, lprof->lp_lov);
3792 GOTO(err_cleanup, rc);
3794 rc = mds_md_postsetup(obd);
3796 GOTO(err_cleanup, rc);
3798 rc = mds_fs_post_setup(obd);
3800 CERROR("can not post setup fsfilt\n");
3805 obd_llog_cleanup(llog_get_context(&obd->obd_llogs,
3806 LLOG_CONFIG_ORIG_CTXT));
3810 int mds_postrecov_common(struct obd_device *obd)
3812 struct mds_obd *mds = &obd->u.mds;
3813 struct llog_ctxt *ctxt;
3814 int rc, item = 0, valsize;
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 rc = mds_cleanup_orphans(obd);
3828 group = FILTER_GROUP_FIRST_MDS + mds->mds_num;
3829 valsize = sizeof(group);
3830 rc = obd_set_info(mds->mds_dt_exp, strlen("mds_conn"),
3831 "mds_conn", valsize, &group);
3835 rc = llog_connect(ctxt, obd->u.mds.mds_dt_desc.ld_tgt_count,
3838 CERROR("%s: failed at llog_origin_connect: %d\n",
3843 /* remove the orphaned precreated objects */
3844 rc = mds_dt_clear_orphans(mds, NULL /* all OSTs */);
3849 RETURN(rc < 0 ? rc : item);
3852 /* cleanup all llogging subsystems */
3853 rc = obd_llog_finish(obd, &obd->obd_llogs,
3854 mds->mds_dt_desc.ld_tgt_count);
3856 CERROR("%s: failed to cleanup llogging subsystems\n",
3861 int mds_postrecov(struct obd_device *obd)
3865 rc = mds_postrecov_common(obd);
3867 rc = mds_md_reconnect(obd);
3871 int mds_dt_clean(struct obd_device *obd)
3873 struct mds_obd *mds = &obd->u.mds;
3876 if (mds->mds_profile) {
3878 struct llog_ctxt *llctx;
3879 struct lvfs_run_ctxt saved;
3880 struct config_llog_instance cfg;
3881 int len = strlen(mds->mds_profile) + sizeof("-clean") + 1;
3883 OBD_ALLOC(cln_prof, len);
3884 sprintf(cln_prof, "%s-clean", mds->mds_profile);
3886 cfg.cfg_instance = NULL;
3887 cfg.cfg_uuid = mds->mds_dt_uuid;
3889 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3890 llctx = llog_get_context(&obd->obd_llogs,
3891 LLOG_CONFIG_ORIG_CTXT);
3892 class_config_process_llog(llctx, cln_prof, &cfg);
3893 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
3895 OBD_FREE(cln_prof, len);
3896 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
3897 mds->mds_profile = NULL;
3902 int mds_md_clean(struct obd_device *obd)
3904 struct mds_obd *mds = &obd->u.mds;
3907 if (mds->mds_md_name) {
3908 OBD_FREE(mds->mds_md_name, strlen(mds->mds_md_name) + 1);
3909 mds->mds_md_name = NULL;
3914 static int mds_precleanup(struct obd_device *obd, int flags)
3920 mds_dt_disconnect(obd, flags);
3922 obd_llog_cleanup(llog_get_context(&obd->obd_llogs, LLOG_CONFIG_ORIG_CTXT));
3926 extern void lgss_svc_cache_purge_all(void);
3927 static int mds_cleanup(struct obd_device *obd, int flags)
3929 struct mds_obd *mds = &obd->u.mds;
3932 if (mds->mds_sb == NULL)
3935 mds_update_server_data(obd, 1);
3936 mds_update_last_fid(obd, NULL, 1);
3938 if (mds->mds_dt_objids != NULL) {
3939 int size = mds->mds_dt_desc.ld_tgt_count *
3941 OBD_FREE(mds->mds_dt_objids, size);
3943 mds_fs_cleanup(obd, flags);
3947 /* 2 seems normal on mds, (may_umount() also expects 2
3948 fwiw), but we only see 1 at this point in obdfilter. */
3949 lvfs_umount_fs(mds->mds_lvfs_ctxt);
3953 ldlm_namespace_free(obd->obd_namespace, flags & OBD_OPT_FORCE);
3955 spin_lock_bh(&obd->obd_processing_task_lock);
3956 if (obd->obd_recovering) {
3957 target_cancel_recovery_timer(obd);
3958 obd->obd_recovering = 0;
3960 spin_unlock_bh(&obd->obd_processing_task_lock);
3963 fsfilt_put_ops(obd->obd_fsops);
3967 lgss_svc_cache_purge_all();
3970 spin_lock(&mds->mds_denylist_lock);
3971 while (!list_empty( &mds->mds_denylist ) ) {
3972 deny_sec_t *p_deny_sec = list_entry(mds->mds_denylist.next,
3974 list_del(&p_deny_sec->list);
3975 OBD_FREE(p_deny_sec, sizeof(*p_deny_sec));
3977 spin_unlock(&mds->mds_denylist_lock);
3982 static int set_security(const char *value, char **sec)
3984 if (!strcmp(value, "null"))
3986 else if (!strcmp(value, "krb5i"))
3988 else if (!strcmp(value, "krb5p"))
3991 CERROR("Unrecognized security flavor %s\n", value);
3998 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
4000 struct lustre_cfg *lcfg = buf;
4001 struct mds_obd *mds = &obd->u.mds;
4005 switch(lcfg->lcfg_command) {
4006 case LCFG_SET_SECURITY: {
4007 if ((LUSTRE_CFG_BUFLEN(lcfg, 1) == 0) ||
4008 (LUSTRE_CFG_BUFLEN(lcfg, 2) == 0))
4009 GOTO(out, rc = -EINVAL);
4011 if (!strcmp(lustre_cfg_string(lcfg, 1), "mds_sec"))
4012 rc = set_security(lustre_cfg_string(lcfg, 2),
4014 else if (!strcmp(lustre_cfg_string(lcfg, 1), "oss_sec"))
4015 rc = set_security(lustre_cfg_string(lcfg, 2),
4017 else if (!strcmp(lustre_cfg_string(lcfg, 1), "deny_sec")){
4018 spin_lock(&mds->mds_denylist_lock);
4019 rc = add_deny_security(lustre_cfg_string(lcfg, 2),
4020 &mds->mds_denylist);
4021 spin_unlock(&mds->mds_denylist_lock);
4023 CERROR("Unrecognized key\n");
4029 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
4030 GOTO(out, rc = -EINVAL);
4036 static void fixup_handle_for_resent_req(struct ptlrpc_request *req,
4038 struct ldlm_lock *new_lock,
4039 struct ldlm_lock **old_lock,
4040 struct lustre_handle *lockh)
4042 struct obd_export *exp = req->rq_export;
4043 struct obd_device *obd = exp->exp_obd;
4044 struct ldlm_request *dlmreq =
4045 lustre_msg_buf(req->rq_reqmsg, offset, sizeof (*dlmreq));
4046 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
4047 struct list_head *iter;
4049 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
4052 spin_lock(&obd->obd_namespace->ns_hash_lock);
4053 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
4054 struct ldlm_lock *lock;
4055 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
4056 if (lock == new_lock)
4058 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
4059 lockh->cookie = lock->l_handle.h_cookie;
4060 LDLM_DEBUG(lock, "restoring lock cookie");
4061 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
4064 *old_lock = LDLM_LOCK_GET(lock);
4065 spin_unlock(&obd->obd_namespace->ns_hash_lock);
4069 spin_unlock(&obd->obd_namespace->ns_hash_lock);
4071 /* If the xid matches, then we know this is a resent request,
4072 * and allow it. (It's probably an OPEN, for which we don't
4075 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
4079 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
4082 /* This remote handle isn't enqueued, so we never received or
4083 * processed this request. Clear MSG_RESENT, because it can
4084 * be handled like any normal request now. */
4086 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
4088 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
4092 int intent_disposition(struct ldlm_reply *rep, int flag)
4096 return (rep->lock_policy_res1 & flag);
4099 void intent_set_disposition(struct ldlm_reply *rep, int flag)
4103 rep->lock_policy_res1 |= flag;
4106 static int mds_intent_prepare_reply_buffers(struct ptlrpc_request *req,
4107 struct ldlm_intent *it)
4109 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
4110 int rc, reply_buffers;
4111 int repsize[5] = {sizeof(struct ldlm_reply),
4112 sizeof(struct mds_body),
4113 mds->mds_max_mdsize};
4117 if (it->opc & ( IT_OPEN | IT_GETATTR | IT_LOOKUP | IT_CHDIR )) {
4118 if (req->rq_export->exp_mds_data.med_remote) {
4119 repsize[reply_buffers++] =
4120 sizeof(struct mds_remote_perm);
4122 repsize[reply_buffers++] = sizeof(int);
4123 repsize[reply_buffers++] =
4124 xattr_acl_size(LL_ACL_MAX_ENTRIES);
4126 /*FIXME: ugly here, should be optimize for there
4127 * is no crypto key*/
4128 repsize[reply_buffers++] = sizeof(int);
4129 repsize[reply_buffers++] = sizeof(struct crypto_key);
4132 rc = lustre_pack_reply(req, reply_buffers, repsize, NULL);
4137 static int mds_intent_policy(struct ldlm_namespace *ns,
4138 struct ldlm_lock **lockp, void *req_cookie,
4139 ldlm_mode_t mode, int flags, void *data)
4141 struct ptlrpc_request *req = req_cookie;
4142 struct ldlm_lock *lock = *lockp;
4143 struct ldlm_intent *it;
4144 struct ldlm_reply *rep;
4145 struct lustre_handle lockh[2] = {{0}, {0}};
4146 struct ldlm_lock *new_lock = NULL;
4147 int getattr_part = MDS_INODELOCK_UPDATE;
4150 int offset = MDS_REQ_INTENT_REC_OFF;
4153 LASSERT(req != NULL);
4154 MD_COUNTER_INCREMENT(req->rq_export->exp_obd, intent_lock);
4156 if (req->rq_reqmsg->bufcount <= MDS_REQ_INTENT_IT_OFF) {
4157 /* No intent was provided */
4158 int size = sizeof(struct ldlm_reply);
4159 rc = lustre_pack_reply(req, 1, &size, NULL);
4164 it = lustre_swab_reqbuf(req, MDS_REQ_INTENT_IT_OFF, sizeof(*it),
4165 lustre_swab_ldlm_intent);
4167 CERROR("Intent missing\n");
4168 RETURN(req->rq_status = -EFAULT);
4171 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
4173 rc = mds_intent_prepare_reply_buffers(req, it);
4176 RETURN(req->rq_status = rc);
4178 rep = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*rep));
4179 LASSERT(rep != NULL);
4181 intent_set_disposition(rep, DISP_IT_EXECD);
4183 /* execute policy */
4184 switch ((long)it->opc) {
4186 case IT_CREAT|IT_OPEN:
4187 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4189 /* XXX swab here to assert that an mds_open reint
4190 * packet is following */
4191 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4193 rep->lock_policy_res2 = mds_reint(req, offset, lockh);
4195 if (rep->lock_policy_res2) {
4197 * mds_open() returns ENOLCK where it should return
4198 * zero, but it has no lock to return.
4200 if (rep->lock_policy_res2 == ENOLCK)
4201 rep->lock_policy_res2 = 0;
4203 RETURN(ELDLM_LOCK_ABORTED);
4207 * IT_OPEN may return lock on cross-node dentry that we want to
4208 * hold during attr retrival -bzzz
4210 if (lockh[0].cookie == 0)
4211 RETURN(ELDLM_LOCK_ABORTED);
4215 getattr_part = MDS_INODELOCK_LOOKUP;
4218 getattr_part |= MDS_INODELOCK_LOOKUP;
4220 fixup_handle_for_resent_req(req, MDS_REQ_INTENT_LOCKREQ_OFF,
4221 lock, &new_lock, lockh);
4222 rep->lock_policy_res2 = mds_getattr_lock(req, offset, lockh,
4224 /* FIXME: LDLM can set req->rq_status. MDS sets
4225 policy_res{1,2} with disposition and status.
4226 - replay: returns 0 & req->status is old status
4227 - otherwise: returns req->status */
4228 if (intent_disposition(rep, DISP_LOOKUP_NEG))
4229 rep->lock_policy_res2 = 0;
4230 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
4231 rep->lock_policy_res2)
4232 RETURN(ELDLM_LOCK_ABORTED);
4233 if (req->rq_status != 0) {
4235 rep->lock_policy_res2 = req->rq_status;
4236 RETURN(ELDLM_LOCK_ABORTED);
4240 rc = mds_lock_and_check_slave(offset, req, lockh);
4241 if ((rep->lock_policy_res2 = rc)) {
4243 rep->lock_policy_res2 = 0;
4244 RETURN(ELDLM_LOCK_ABORTED);
4248 CERROR("Unhandled intent "LPD64"\n", it->opc);
4252 /* By this point, whatever function we called above must have either
4253 * filled in 'lockh', been an intent replay, or returned an error. We
4254 * want to allow replayed RPCs to not get a lock, since we would just
4255 * drop it below anyways because lock replay is done separately by the
4256 * client afterwards. For regular RPCs we want to give the new lock to
4257 * the client instead of whatever lock it was about to get. */
4258 if (new_lock == NULL)
4259 new_lock = ldlm_handle2lock(&lockh[0]);
4260 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
4263 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
4264 it->opc, lockh[0].cookie);
4266 /* If we've already given this lock to a client once, then we should
4267 * have no readers or writers. Otherwise, we should have one reader
4268 * _or_ writer ref (which will be zeroed below) before returning the
4269 * lock to a client. */
4270 if (new_lock->l_export == req->rq_export) {
4271 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
4273 LASSERT(new_lock->l_export == NULL);
4274 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
4279 if (new_lock->l_export == req->rq_export) {
4280 /* Already gave this to the client, which means that we
4281 * reconstructed a reply. */
4282 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
4284 RETURN(ELDLM_LOCK_REPLACED);
4287 /* Fixup the lock to be given to the client */
4288 lock_res_and_lock(new_lock);
4289 new_lock->l_readers = 0;
4290 new_lock->l_writers = 0;
4292 new_lock->l_export = class_export_get(req->rq_export);
4294 spin_lock(&new_lock->l_export->exp_ldlm_data.led_lock);
4295 list_add(&new_lock->l_export_chain,
4296 &new_lock->l_export->exp_ldlm_data.led_held_locks);
4297 spin_unlock(&new_lock->l_export->exp_ldlm_data.led_lock);
4299 new_lock->l_blocking_ast = lock->l_blocking_ast;
4300 new_lock->l_completion_ast = lock->l_completion_ast;
4302 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
4303 sizeof(lock->l_remote_handle));
4305 new_lock->l_flags &= ~LDLM_FL_LOCAL;
4307 unlock_res_and_lock(new_lock);
4308 LDLM_LOCK_PUT(new_lock);
4310 RETURN(ELDLM_LOCK_REPLACED);
4313 int mds_attach(struct obd_device *dev, obd_count len, void *data)
4315 struct lprocfs_static_vars lvars;
4317 struct mds_obd *mds = &dev->u.mds;
4319 spin_lock_init(&mds->mds_denylist_lock);
4320 INIT_LIST_HEAD(&mds->mds_denylist);
4322 lprocfs_init_multi_vars(0, &lvars);
4324 rc = lprocfs_obd_attach(dev, lvars.obd_vars);
4328 return lprocfs_alloc_md_stats(dev, 0);
4331 int mds_detach(struct obd_device *dev)
4333 lprocfs_free_md_stats(dev);
4334 return lprocfs_obd_detach(dev);
4337 int mdt_attach(struct obd_device *dev, obd_count len, void *data)
4339 struct lprocfs_static_vars lvars;
4341 lprocfs_init_multi_vars(1, &lvars);
4342 return lprocfs_obd_attach(dev, lvars.obd_vars);
4345 int mdt_detach(struct obd_device *dev)
4347 return lprocfs_obd_detach(dev);
4350 static int mdt_setup(struct obd_device *obd, obd_count len, void *buf)
4352 struct mds_obd *mds = &obd->u.mds;
4357 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4358 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL,
4359 MDS_SERVICE_WATCHDOG_TIMEOUT,
4360 mds_handle, "mds", obd->obd_proc_entry);
4362 if (!mds->mds_service) {
4363 CERROR("failed to start service\n");
4367 rc = ptlrpc_start_n_threads(obd, mds->mds_service, MDT_NUM_THREADS,
4370 GOTO(err_thread, rc);
4372 mds->mds_setattr_service =
4373 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4374 MDS_SETATTR_PORTAL, MDC_REPLY_PORTAL,
4375 MDS_SERVICE_WATCHDOG_TIMEOUT,
4376 mds_handle, "mds_setattr",
4377 obd->obd_proc_entry);
4378 if (!mds->mds_setattr_service) {
4379 CERROR("failed to start getattr service\n");
4380 GOTO(err_thread, rc = -ENOMEM);
4383 rc = ptlrpc_start_n_threads(obd, mds->mds_setattr_service,
4384 MDT_NUM_THREADS, "ll_mdt_attr");
4386 GOTO(err_thread2, rc);
4388 mds->mds_readpage_service =
4389 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4390 MDS_READPAGE_PORTAL, MDC_REPLY_PORTAL,
4391 MDS_SERVICE_WATCHDOG_TIMEOUT,
4392 mds_handle, "mds_readpage",
4393 obd->obd_proc_entry);
4394 if (!mds->mds_readpage_service) {
4395 CERROR("failed to start readpage service\n");
4396 GOTO(err_thread2, rc = -ENOMEM);
4399 rc = ptlrpc_start_n_threads(obd, mds->mds_readpage_service,
4400 MDT_NUM_THREADS, "ll_mdt_rdpg");
4403 GOTO(err_thread3, rc);
4405 mds->mds_close_service =
4406 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
4407 MDS_CLOSE_PORTAL, MDC_REPLY_PORTAL,
4408 MDS_SERVICE_WATCHDOG_TIMEOUT,
4409 mds_handle, "mds_close",
4410 obd->obd_proc_entry);
4411 if (!mds->mds_close_service) {
4412 CERROR("failed to start close service\n");
4413 GOTO(err_thread3, rc = -ENOMEM);
4416 rc = ptlrpc_start_n_threads(obd, mds->mds_close_service,
4417 MDT_NUM_THREADS, "ll_mdt_clos");
4420 GOTO(err_thread4, rc);
4424 ptlrpc_unregister_service(mds->mds_close_service);
4426 ptlrpc_unregister_service(mds->mds_readpage_service);
4428 ptlrpc_unregister_service(mds->mds_setattr_service);
4430 ptlrpc_unregister_service(mds->mds_service);
4434 static int mdt_cleanup(struct obd_device *obd, int flags)
4436 struct mds_obd *mds = &obd->u.mds;
4439 ptlrpc_stop_all_threads(mds->mds_close_service);
4440 ptlrpc_unregister_service(mds->mds_close_service);
4442 ptlrpc_stop_all_threads(mds->mds_readpage_service);
4443 ptlrpc_unregister_service(mds->mds_readpage_service);
4445 ptlrpc_stop_all_threads(mds->mds_setattr_service);
4446 ptlrpc_unregister_service(mds->mds_setattr_service);
4448 ptlrpc_stop_all_threads(mds->mds_service);
4449 ptlrpc_unregister_service(mds->mds_service);
4454 static struct dentry *mds_lvfs_id2dentry(__u64 ino, __u32 gen,
4455 __u64 gr, void *data)
4457 struct lustre_id id;
4458 struct obd_device *obd = data;
4462 return mds_id2dentry(obd, &id, NULL);
4465 static int mds_get_info(struct obd_export *exp, __u32 keylen,
4466 void *key, __u32 *valsize, void *val)
4468 struct obd_device *obd;
4469 struct mds_obd *mds;
4473 obd = class_exp2obd(exp);
4477 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
4478 exp->exp_handle.h_cookie);
4482 if (keylen >= strlen("reint_log") && memcmp(key, "reint_log", 9) == 0) {
4483 /* get log_context handle. */
4484 struct llog_ctxt *ctxt;
4485 unsigned long *llh_handle = val;
4486 *valsize = sizeof(unsigned long);
4487 ctxt = llog_get_context(&obd->obd_llogs, LLOG_REINT_ORIG_CTXT);
4489 CERROR("Cannot get REINT llog context\n");
4492 *llh_handle = (unsigned long)ctxt;
4495 if (keylen >= strlen("cache_sb") && memcmp(key, "cache_sb", 8) == 0) {
4496 /* get log_context handle. */
4497 unsigned long *sb = val;
4498 *valsize = sizeof(unsigned long);
4499 *sb = (unsigned long)obd->u.mds.mds_sb;
4503 if (keylen >= strlen("mdsize") && memcmp(key, "mdsize", keylen) == 0) {
4504 __u32 *mdsize = val;
4505 *valsize = sizeof(*mdsize);
4506 *mdsize = mds->mds_max_mdsize;
4510 if (keylen >= strlen("mdsnum") && strcmp(key, "mdsnum") == 0) {
4511 __u32 *mdsnum = val;
4512 *valsize = sizeof(*mdsnum);
4513 *mdsnum = mds->mds_num;
4517 if (keylen >= strlen("rootid") && strcmp(key, "rootid") == 0) {
4518 struct lustre_id *rootid = val;
4519 *valsize = sizeof(*rootid);
4520 *rootid = mds->mds_rootid;
4524 if (keylen >= strlen("lovdesc") && strcmp(key, "lovdesc") == 0) {
4525 struct lov_desc *desc = val;
4526 *valsize = sizeof(*desc);
4527 *desc = mds->mds_dt_desc;
4531 if (keylen >= strlen("getext") && strcmp(key, "getext") == 0) {
4532 struct fid_extent *ext = val;
4533 *valsize = sizeof(*ext);
4535 spin_lock(&mds->mds_fidext_lock);
4536 ext->fe_width = MDS_FIDEXT_SIZE;
4537 ext->fe_start = mds->mds_fidext_thumb + 1;
4538 mds->mds_fidext_thumb += MDS_FIDEXT_SIZE;
4539 spin_unlock(&mds->mds_fidext_lock);
4544 rc = fsfilt_get_info(obd, mds->mds_sb, NULL, keylen, key, valsize, val);
4546 CDEBUG(D_IOCTL, "invalid key\n");
4551 struct lvfs_callback_ops mds_lvfs_ops = {
4552 l_id2dentry: mds_lvfs_id2dentry,
4555 int mds_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
4556 int objcount, struct obd_ioobj *obj,
4557 int niocount, struct niobuf_remote *nb,
4558 struct niobuf_local *res,
4559 struct obd_trans_info *oti);
4561 int mds_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
4562 int objcount, struct obd_ioobj *obj, int niocount,
4563 struct niobuf_local *res, struct obd_trans_info *oti,
4566 /* use obd ops to offer management infrastructure */
4567 static struct obd_ops mds_obd_ops = {
4568 .o_owner = THIS_MODULE,
4569 .o_attach = mds_attach,
4570 .o_detach = mds_detach,
4571 .o_connect = mds_connect,
4572 .o_connect_post = mds_connect_post,
4573 .o_init_export = mds_init_export,
4574 .o_destroy_export = mds_destroy_export,
4575 .o_disconnect = mds_disconnect,
4576 .o_setup = mds_setup,
4577 .o_precleanup = mds_precleanup,
4578 .o_cleanup = mds_cleanup,
4579 .o_process_config = mds_process_config,
4580 .o_postrecov = mds_postrecov,
4581 .o_statfs = mds_obd_statfs,
4582 .o_iocontrol = mds_iocontrol,
4583 .o_create = mds_obd_create,
4584 .o_destroy = mds_obd_destroy,
4585 .o_llog_init = mds_llog_init,
4586 .o_llog_finish = mds_llog_finish,
4587 .o_notify = mds_notify,
4588 .o_get_info = mds_get_info,
4589 .o_set_info = mds_set_info,
4590 .o_preprw = mds_preprw,
4591 .o_commitrw = mds_commitrw,
4594 static struct obd_ops mdt_obd_ops = {
4595 .o_owner = THIS_MODULE,
4596 .o_attach = mdt_attach,
4597 .o_detach = mdt_detach,
4598 .o_setup = mdt_setup,
4599 .o_cleanup = mdt_cleanup,
4602 static int __init mds_init(void)
4604 struct lprocfs_static_vars lvars;
4606 mds_init_lsd_cache();
4607 mds_init_rmtacl_upcall_cache();
4609 lprocfs_init_multi_vars(0, &lvars);
4610 class_register_type(&mds_obd_ops, NULL, lvars.module_vars,
4611 OBD_MDS_DEVICENAME);
4612 lprocfs_init_multi_vars(1, &lvars);
4613 class_register_type(&mdt_obd_ops, NULL, lvars.module_vars,
4614 OBD_MDT_DEVICENAME);
4619 static void /*__exit*/ mds_exit(void)
4621 mds_cleanup_rmtacl_upcall_cache();
4622 mds_cleanup_lsd_cache();
4624 class_unregister_type(OBD_MDS_DEVICENAME);
4625 class_unregister_type(OBD_MDT_DEVICENAME);
4628 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
4629 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
4630 MODULE_LICENSE("GPL");
4632 module_init(mds_init);
4633 module_exit(mds_exit);