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-2005 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 the Lustre file system, http://www.lustre.org
14 * Lustre is a trademark of Cluster File Systems, Inc.
16 * You may have signed or agreed to another license before downloading
17 * this software. If so, you are bound by the terms and conditions
18 * of that agreement, and the following does not apply to you. See the
19 * LICENSE file included with this distribution for more information.
21 * If you did not agree to a different license, then this copy of Lustre
22 * is open source software; you can redistribute it and/or modify it
23 * under the terms of version 2 of the GNU General Public License as
24 * published by the Free Software Foundation.
26 * In either case, Lustre is distributed in the hope that it will be
27 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
28 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * license text for more details.
33 # define EXPORT_SYMTAB
35 #define DEBUG_SUBSYSTEM S_MDS
37 #include <lustre_mds.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/random.h>
42 #include <linux/jbd.h>
43 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
44 # include <linux/smp_lock.h>
45 # include <linux/buffer_head.h>
46 # include <linux/workqueue.h>
47 # include <linux/mount.h>
49 # include <linux/locks.h>
52 #include <linux/lustre_acl.h>
53 #include <obd_class.h>
54 #include <lustre_dlm.h>
56 #include <lustre_fsfilt.h>
57 #include <lprocfs_status.h>
58 #include <lustre_commit_confd.h>
59 #include <lustre_quota.h>
60 #include <lustre_disk.h>
61 #include <lustre_param.h>
63 #include "mds_internal.h"
66 CFS_MODULE_PARM(mds_num_threads, "i", int, 0444,
67 "number of MDS service threads to start");
69 static int mds_intent_policy(struct ldlm_namespace *ns,
70 struct ldlm_lock **lockp, void *req_cookie,
71 ldlm_mode_t mode, int flags, void *data);
72 static int mds_postsetup(struct obd_device *obd);
73 static int mds_cleanup(struct obd_device *obd);
75 /* Assumes caller has already pushed into the kernel filesystem context */
76 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
77 loff_t offset, int count)
79 struct ptlrpc_bulk_desc *desc;
80 struct l_wait_info lwi;
82 int rc = 0, npages, i, tmpcount, tmpsize = 0;
85 LASSERT((offset & ~CFS_PAGE_MASK) == 0); /* I'm dubious about this */
87 npages = (count + CFS_PAGE_SIZE - 1) >> CFS_PAGE_SHIFT;
88 OBD_ALLOC(pages, sizeof(*pages) * npages);
90 GOTO(out, rc = -ENOMEM);
92 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
95 GOTO(out_free, rc = -ENOMEM);
97 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
98 tmpsize = tmpcount > CFS_PAGE_SIZE ? CFS_PAGE_SIZE : tmpcount;
100 pages[i] = cfs_alloc_page(CFS_ALLOC_STD);
101 if (pages[i] == NULL)
102 GOTO(cleanup_buf, rc = -ENOMEM);
104 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
107 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
108 tmpsize = tmpcount > CFS_PAGE_SIZE ? CFS_PAGE_SIZE : tmpcount;
109 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
110 tmpsize, offset, file->f_dentry->d_inode->i_ino,
111 file->f_dentry->d_inode->i_size);
113 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
114 kmap(pages[i]), tmpsize, &offset);
118 GOTO(cleanup_buf, rc = -EIO);
121 LASSERT(desc->bd_nob == count);
123 rc = ptlrpc_start_bulk_transfer(desc);
125 GOTO(cleanup_buf, rc);
127 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
128 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
129 OBD_FAIL_MDS_SENDPAGE, rc);
130 GOTO(abort_bulk, rc);
133 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
134 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
135 LASSERT (rc == 0 || rc == -ETIMEDOUT);
138 if (desc->bd_success &&
139 desc->bd_nob_transferred == count)
140 GOTO(cleanup_buf, rc);
142 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
145 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s",
146 (rc == -ETIMEDOUT) ? "timeout" : "network error",
147 desc->bd_nob_transferred, count,
148 req->rq_export->exp_client_uuid.uuid,
149 req->rq_export->exp_connection->c_remote_uuid.uuid);
151 class_fail_export(req->rq_export);
155 ptlrpc_abort_bulk (desc);
157 for (i = 0; i < npages; i++)
159 __cfs_free_page(pages[i]);
161 ptlrpc_free_bulk(desc);
163 OBD_FREE(pages, sizeof(*pages) * npages);
168 /* only valid locked dentries or errors should be returned */
169 struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
170 struct vfsmount **mnt, int lock_mode,
171 struct lustre_handle *lockh,
174 struct mds_obd *mds = &obd->u.mds;
175 struct dentry *de = mds_fid2dentry(mds, fid, mnt), *retval = de;
176 struct ldlm_res_id res_id = { .name = {0} };
177 int flags = LDLM_FL_ATOMIC_CB, rc;
178 ldlm_policy_data_t policy = { .l_inodebits = { lockpart} };
184 res_id.name[0] = de->d_inode->i_ino;
185 res_id.name[1] = de->d_inode->i_generation;
186 rc = ldlm_cli_enqueue_local(obd->obd_namespace, &res_id,
187 LDLM_IBITS, &policy, lock_mode, &flags,
188 ldlm_blocking_ast, ldlm_completion_ast,
189 NULL, NULL, 0, NULL, lockh);
190 if (rc != ELDLM_OK) {
192 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
198 /* Look up an entry by inode number. */
199 /* this function ONLY returns valid dget'd dentries with an initialized inode
201 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
202 struct vfsmount **mnt)
205 unsigned long ino = fid->id;
206 __u32 generation = fid->generation;
208 struct dentry *result;
211 RETURN(ERR_PTR(-ESTALE));
213 snprintf(fid_name, sizeof(fid_name), "0x%lx", ino);
215 CDEBUG(D_DENTRY, "--> mds_fid2dentry: ino/gen %lu/%u, sb %p\n",
216 ino, generation, mds->mds_obt.obt_sb);
218 /* under ext3 this is neither supposed to return bad inodes
220 result = ll_lookup_one_len(fid_name, mds->mds_fid_de, strlen(fid_name));
224 inode = result->d_inode;
226 RETURN(ERR_PTR(-ENOENT));
228 if (inode->i_generation == 0 || inode->i_nlink == 0) {
229 LCONSOLE_WARN("Found inode with zero generation or link -- this"
230 " may indicate disk corruption (inode: %lu/%u, "
231 "link %lu, count %d)\n", inode->i_ino,
232 inode->i_generation,(unsigned long)inode->i_nlink,
233 atomic_read(&inode->i_count));
235 RETURN(ERR_PTR(-ENOENT));
238 if (generation && inode->i_generation != generation) {
239 /* we didn't find the right inode.. */
240 CDEBUG(D_INODE, "found wrong generation: inode %lu, link: %lu, "
241 "count: %d, generation %u/%u\n", inode->i_ino,
242 (unsigned long)inode->i_nlink,
243 atomic_read(&inode->i_count), inode->i_generation,
246 RETURN(ERR_PTR(-ENOENT));
250 *mnt = mds->mds_vfsmnt;
257 static int mds_connect_internal(struct obd_export *exp,
258 struct obd_connect_data *data)
260 struct obd_device *obd = exp->exp_obd;
262 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
263 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
265 /* If no known bits (which should not happen, probably,
266 as everybody should support LOOKUP and UPDATE bits at least)
267 revert to compat mode with plain locks. */
268 if (!data->ocd_ibits_known &&
269 data->ocd_connect_flags & OBD_CONNECT_IBITS)
270 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
272 if (!obd->u.mds.mds_fl_acl)
273 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
275 if (!obd->u.mds.mds_fl_user_xattr)
276 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
278 exp->exp_connect_flags = data->ocd_connect_flags;
279 data->ocd_version = LUSTRE_VERSION_CODE;
280 exp->exp_mds_data.med_ibits_known = data->ocd_ibits_known;
283 if (obd->u.mds.mds_fl_acl &&
284 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
285 CWARN("%s: MDS requires ACL support but client does not\n",
292 static int mds_reconnect(struct obd_export *exp, struct obd_device *obd,
293 struct obd_uuid *cluuid,
294 struct obd_connect_data *data)
299 if (exp == NULL || obd == NULL || cluuid == NULL)
302 rc = mds_connect_internal(exp, data);
307 /* Establish a connection to the MDS.
309 * This will set up an export structure for the client to hold state data
310 * about that client, like open files, the last operation number it did
311 * on the server, etc.
313 static int mds_connect(const struct lu_env *env,
314 struct lustre_handle *conn, struct obd_device *obd,
315 struct obd_uuid *cluuid, struct obd_connect_data *data)
317 struct obd_export *exp;
318 struct mds_export_data *med;
319 struct mds_client_data *mcd = NULL;
323 if (!conn || !obd || !cluuid)
326 /* XXX There is a small race between checking the list and adding a
327 * new connection for the same UUID, but the real threat (list
328 * corruption when multiple different clients connect) is solved.
330 * There is a second race between adding the export to the list,
331 * and filling in the client data below. Hence skipping the case
332 * of NULL mcd above. We should already be controlling multiple
333 * connects at the client, and we can't hold the spinlock over
334 * memory allocations without risk of deadlocking.
336 rc = class_connect(conn, obd, cluuid);
339 exp = class_conn2export(conn);
341 med = &exp->exp_mds_data;
343 rc = mds_connect_internal(exp, data);
347 OBD_ALLOC(mcd, sizeof(*mcd));
349 GOTO(out, rc = -ENOMEM);
351 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
354 rc = mds_client_add(obd, exp, -1);
360 OBD_FREE(mcd, sizeof(*mcd));
363 class_disconnect(exp);
365 class_export_put(exp);
371 int mds_init_export(struct obd_export *exp)
373 struct mds_export_data *med = &exp->exp_mds_data;
375 INIT_LIST_HEAD(&med->med_open_head);
376 spin_lock_init(&med->med_open_lock);
378 spin_lock(&exp->exp_lock);
379 exp->exp_connecting = 1;
380 spin_unlock(&exp->exp_lock);
385 static int mds_destroy_export(struct obd_export *export)
387 struct mds_export_data *med;
388 struct obd_device *obd = export->exp_obd;
389 struct mds_obd *mds = &obd->u.mds;
390 struct lvfs_run_ctxt saved;
391 struct lov_mds_md *lmm;
392 struct llog_cookie *logcookies;
396 med = &export->exp_mds_data;
397 target_destroy_export(export);
399 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
402 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
403 /* Close any open files (which may also cause orphan unlinking). */
405 OBD_ALLOC(lmm, mds->mds_max_mdsize);
407 CWARN("%s: allocation failure during cleanup; can not force "
408 "close file handles on this service.\n", obd->obd_name);
409 GOTO(out, rc = -ENOMEM);
412 OBD_ALLOC(logcookies, mds->mds_max_cookiesize);
413 if (logcookies == NULL) {
414 CWARN("%s: allocation failure during cleanup; can not force "
415 "close file handles on this service.\n", obd->obd_name);
416 OBD_FREE(lmm, mds->mds_max_mdsize);
417 GOTO(out_lmm, rc = -ENOMEM);
420 spin_lock(&med->med_open_lock);
421 while (!list_empty(&med->med_open_head)) {
422 struct list_head *tmp = med->med_open_head.next;
423 struct mds_file_data *mfd =
424 list_entry(tmp, struct mds_file_data, mfd_list);
425 int lmm_size = mds->mds_max_mdsize;
426 umode_t mode = mfd->mfd_dentry->d_inode->i_mode;
429 /* Remove mfd handle so it can't be found again.
430 * We are consuming the mfd_list reference here. */
431 mds_mfd_unlink(mfd, 0);
432 spin_unlock(&med->med_open_lock);
434 /* If you change this message, be sure to update
435 * replay_single:test_46 */
436 CDEBUG(D_INODE|D_IOCTL, "%s: force closing file handle for "
437 "%.*s (ino %lu)\n", obd->obd_name,
438 mfd->mfd_dentry->d_name.len,mfd->mfd_dentry->d_name.name,
439 mfd->mfd_dentry->d_inode->i_ino);
441 rc = mds_get_md(obd, mfd->mfd_dentry->d_inode, lmm, &lmm_size, 1);
443 CWARN("mds_get_md failure, rc=%d\n", rc);
445 valid |= OBD_MD_FLEASIZE;
447 /* child orphan sem protects orphan_dec_test and
448 * is_orphan race, mds_mfd_close drops it */
449 MDS_DOWN_WRITE_ORPHAN_SEM(mfd->mfd_dentry->d_inode);
450 rc = mds_mfd_close(NULL, REQ_REC_OFF, obd, mfd,
451 !(export->exp_flags & OBD_OPT_FAILOVER),
452 lmm, lmm_size, logcookies,
453 mds->mds_max_cookiesize,
457 CDEBUG(D_INODE|D_IOCTL, "Error closing file: %d\n", rc);
459 if (valid & OBD_MD_FLCOOKIE) {
460 rc = mds_osc_destroy_orphan(obd, mode, lmm,
461 lmm_size, logcookies, 1);
463 CDEBUG(D_INODE, "%s: destroy of orphan failed,"
464 " rc = %d\n", obd->obd_name, rc);
467 valid &= ~OBD_MD_FLCOOKIE;
470 spin_lock(&med->med_open_lock);
472 spin_unlock(&med->med_open_lock);
474 OBD_FREE(logcookies, mds->mds_max_cookiesize);
476 OBD_FREE(lmm, mds->mds_max_mdsize);
478 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
479 mds_client_free(export);
483 static int mds_disconnect(struct obd_export *exp)
489 class_export_get(exp);
491 /* Disconnect early so that clients can't keep using export */
492 rc = class_disconnect(exp);
493 if (exp->exp_obd->obd_namespace != NULL)
494 ldlm_cancel_locks_for_export(exp);
496 /* complete all outstanding replies */
497 spin_lock(&exp->exp_lock);
498 while (!list_empty(&exp->exp_outstanding_replies)) {
499 struct ptlrpc_reply_state *rs =
500 list_entry(exp->exp_outstanding_replies.next,
501 struct ptlrpc_reply_state, rs_exp_list);
502 struct ptlrpc_service *svc = rs->rs_service;
504 spin_lock(&svc->srv_lock);
505 list_del_init(&rs->rs_exp_list);
506 ptlrpc_schedule_difficult_reply(rs);
507 spin_unlock(&svc->srv_lock);
509 spin_unlock(&exp->exp_lock);
511 class_export_put(exp);
515 static int mds_getstatus(struct ptlrpc_request *req)
517 struct mds_obd *mds = mds_req2mds(req);
518 struct mds_body *body;
519 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
522 rc = lustre_pack_reply(req, 2, size, NULL);
523 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
524 CERROR("mds: out of memory for message\n");
525 req->rq_status = -ENOMEM; /* superfluous? */
529 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
530 memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
532 /* the last_committed and last_xid fields are filled in for all
533 * replies already - no need to do so here also.
538 /* get the LOV EA from @inode and store it into @md. It can be at most
539 * @size bytes, and @size is updated with the actual EA size.
540 * The EA size is also returned on success, and -ve errno on failure.
541 * If there is no EA then 0 is returned. */
542 int mds_get_md(struct obd_device *obd, struct inode *inode, void *md,
549 LOCK_INODE_MUTEX(inode);
550 rc = fsfilt_get_md(obd, inode, md, *size, "lov");
553 CERROR("Error %d reading eadata for ino %lu\n",
557 rc = mds_convert_lov_ea(obd, inode, md, lmm_size);
569 UNLOCK_INODE_MUTEX(inode);
575 /* Call with lock=1 if you want mds_pack_md to take the i_mutex.
576 * Call with lock=0 if the caller has already taken the i_mutex. */
577 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
578 struct mds_body *body, struct inode *inode, int lock)
580 struct mds_obd *mds = &obd->u.mds;
586 lmm = lustre_msg_buf(msg, offset, 0);
588 /* Some problem with getting eadata when I sized the reply
590 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
594 lmm_size = lustre_msg_buflen(msg, offset);
596 /* I don't really like this, but it is a sanity check on the client
597 * MD request. However, if the client doesn't know how much space
598 * to reserve for the MD, it shouldn't be bad to have too much space.
600 if (lmm_size > mds->mds_max_mdsize) {
601 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
602 inode->i_ino, lmm_size, mds->mds_max_mdsize);
606 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock);
608 if (S_ISDIR(inode->i_mode))
609 body->valid |= OBD_MD_FLDIREA;
611 body->valid |= OBD_MD_FLEASIZE;
612 body->eadatasize = lmm_size;
619 #ifdef CONFIG_FS_POSIX_ACL
621 int mds_pack_posix_acl(struct inode *inode, struct lustre_msg *repmsg,
622 struct mds_body *repbody, int repoff)
624 struct dentry de = { .d_inode = inode };
628 LASSERT(repbody->aclsize == 0);
629 LASSERT(lustre_msg_bufcount(repmsg) > repoff);
631 buflen = lustre_msg_buflen(repmsg, repoff);
635 if (!inode->i_op || !inode->i_op->getxattr)
639 rc = inode->i_op->getxattr(&de, MDS_XATTR_NAME_ACL_ACCESS,
640 lustre_msg_buf(repmsg, repoff, buflen),
645 repbody->aclsize = rc;
646 else if (rc != -ENODATA) {
647 CERROR("buflen %d, get acl: %d\n", buflen, rc);
652 repbody->valid |= OBD_MD_FLACL;
656 #define mds_pack_posix_acl(inode, repmsg, repbody, repoff) 0
659 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
660 struct lustre_msg *repmsg, struct mds_body *repbody,
663 return mds_pack_posix_acl(inode, repmsg, repbody, repoff);
666 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
667 struct ptlrpc_request *req,
668 struct mds_body *reqbody, int reply_off)
670 struct mds_body *body;
671 struct inode *inode = dentry->d_inode;
678 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
679 LASSERT(body != NULL); /* caller prepped reply */
681 mds_pack_inode2fid(&body->fid1, inode);
682 body->flags = reqbody->flags; /* copy MDS_BFLAG_EXT_FLAGS if present */
683 mds_pack_inode2body(body, inode);
686 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
687 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
688 rc = mds_pack_md(obd, req->rq_repmsg, reply_off, body,
691 /* If we have LOV EA data, the OST holds size, atime, mtime */
692 if (!(body->valid & OBD_MD_FLEASIZE) &&
693 !(body->valid & OBD_MD_FLDIREA))
694 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
695 OBD_MD_FLATIME | OBD_MD_FLMTIME);
697 lustre_shrink_reply(req, reply_off, body->eadatasize, 0);
698 if (body->eadatasize)
700 } else if (S_ISLNK(inode->i_mode) &&
701 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
702 char *symname = lustre_msg_buf(req->rq_repmsg, reply_off, 0);
705 LASSERT (symname != NULL); /* caller prepped reply */
706 len = lustre_msg_buflen(req->rq_repmsg, reply_off);
708 rc = inode->i_op->readlink(dentry, symname, len);
710 CERROR("readlink failed: %d\n", rc);
711 } else if (rc != len - 1) {
712 CERROR ("Unexpected readlink rc %d: expecting %d\n",
716 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
717 body->valid |= OBD_MD_LINKNAME;
718 body->eadatasize = rc + 1;
719 symname[rc] = 0; /* NULL terminate */
723 } else if (reqbody->valid == OBD_MD_FLFLAGS &&
724 reqbody->flags & MDS_BFLAG_EXT_FLAGS) {
727 /* We only return the full set of flags on ioctl, otherwise we
728 * get enough flags from the inode in mds_pack_inode2body(). */
729 rc = fsfilt_iocontrol(obd, inode, NULL, EXT3_IOC_GETFLAGS,
732 body->flags = flags | MDS_BFLAG_EXT_FLAGS;
735 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
736 struct mds_obd *mds = mds_req2mds(req);
737 body->max_cookiesize = mds->mds_max_cookiesize;
738 body->max_mdsize = mds->mds_max_mdsize;
739 body->valid |= OBD_MD_FLMODEASIZE;
745 #ifdef CONFIG_FS_POSIX_ACL
746 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
747 (reqbody->valid & OBD_MD_FLACL)) {
748 rc = mds_pack_acl(&req->rq_export->exp_mds_data,
749 inode, req->rq_repmsg,
752 lustre_shrink_reply(req, reply_off, body->aclsize, 0);
761 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode,
764 struct mds_obd *mds = mds_req2mds(req);
765 struct mds_body *body;
766 int rc, bufcount = 2;
767 int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) };
770 LASSERT(offset == REQ_REC_OFF); /* non-intent */
772 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
773 LASSERT(body != NULL); /* checked by caller */
774 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
776 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
777 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
778 LOCK_INODE_MUTEX(inode);
779 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
781 UNLOCK_INODE_MUTEX(inode);
782 CDEBUG(D_INODE, "got %d bytes MD data for inode %lu\n",
785 if (rc != -ENODATA) {
786 CERROR("error getting inode %lu MD: rc = %d\n",
791 } else if (rc > mds->mds_max_mdsize) {
793 CERROR("MD size %d larger than maximum possible %u\n",
794 rc, mds->mds_max_mdsize);
799 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
800 if (inode->i_size + 1 != body->eadatasize)
801 CERROR("symlink size: %Lu, reply space: %d\n",
802 inode->i_size + 1, body->eadatasize);
803 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
805 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
806 inode->i_size + 1, body->eadatasize);
809 #ifdef CONFIG_FS_POSIX_ACL
810 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
811 (body->valid & OBD_MD_FLACL)) {
812 struct dentry de = { .d_inode = inode };
815 if (inode->i_op && inode->i_op->getxattr) {
817 rc = inode->i_op->getxattr(&de, MDS_XATTR_NAME_ACL_ACCESS,
822 if (rc != -ENODATA) {
823 CERROR("got acl size: %d\n", rc);
833 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
834 CERROR("failed MDS_GETATTR_PACK test\n");
835 req->rq_status = -ENOMEM;
839 rc = lustre_pack_reply(req, bufcount, size, NULL);
841 CERROR("lustre_pack_reply failed: rc %d\n", rc);
849 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
850 int child_part, struct lustre_handle *child_lockh)
852 struct obd_device *obd = req->rq_export->exp_obd;
853 struct mds_obd *mds = &obd->u.mds;
854 struct ldlm_reply *rep = NULL;
855 struct lvfs_run_ctxt saved;
856 struct mds_body *body;
857 struct dentry *dparent = NULL, *dchild = NULL;
858 struct lvfs_ucred uc = {0,};
859 struct lustre_handle parent_lockh;
861 int rc = 0, cleanup_phase = 0, resent_req = 0;
865 LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME));
867 /* Swab now, before anyone looks inside the request */
868 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
869 lustre_swab_mds_body);
871 CERROR("Can't swab mds_body\n");
875 LASSERT_REQSWAB(req, offset + 1);
876 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
878 CERROR("Can't unpack name\n");
881 namesize = lustre_msg_buflen(req->rq_reqmsg, offset + 1);
882 /* namesize less than 2 means we have empty name, probably came from
883 revalidate by cfid, so no point in having name to be set */
887 rc = mds_init_ucred(&uc, req, offset);
891 LASSERT(offset == REQ_REC_OFF || offset == DLM_INTENT_REC_OFF);
892 /* if requests were at offset 2, the getattr reply goes back at 1 */
893 if (offset == DLM_INTENT_REC_OFF) {
894 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF,
896 offset = DLM_REPLY_REC_OFF;
899 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
900 cleanup_phase = 1; /* kernel context */
901 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
903 /* FIXME: handle raw lookup */
905 if (body->valid == OBD_MD_FLID) {
906 struct mds_body *mds_reply;
907 int size = sizeof(*mds_reply);
909 // The user requested ONLY the inode number, so do a raw lookup
910 rc = lustre_pack_reply(req, 1, &size, NULL);
912 CERROR("out of memory\n");
916 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
918 mds_reply = lustre_msg_buf(req->rq_repmsg, offset,
920 mds_reply->fid1.id = inum;
921 mds_reply->valid = OBD_MD_FLID;
926 if (lustre_handle_is_used(child_lockh)) {
927 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
931 if (resent_req == 0) {
933 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RESEND, obd_timeout * 2);
934 rc = mds_get_parent_child_locked(obd, &obd->u.mds,
938 MDS_INODELOCK_UPDATE,
940 child_lockh, &dchild,
943 /* For revalidate by fid we always take UPDATE lock */
944 dchild = mds_fid2locked_dentry(obd, &body->fid2, NULL,
949 rc = PTR_ERR(dchild);
954 struct ldlm_lock *granted_lock;
955 struct ll_fid child_fid;
956 struct ldlm_resource *res;
957 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
958 granted_lock = ldlm_handle2lock(child_lockh);
959 LASSERTF(granted_lock != NULL, LPU64"/%u lockh "LPX64"\n",
960 body->fid1.id, body->fid1.generation,
961 child_lockh->cookie);
964 res = granted_lock->l_resource;
965 child_fid.id = res->lr_name.name[0];
966 child_fid.generation = res->lr_name.name[1];
967 dchild = mds_fid2dentry(&obd->u.mds, &child_fid, NULL);
968 LASSERT(!IS_ERR(dchild));
969 LDLM_LOCK_PUT(granted_lock);
972 cleanup_phase = 2; /* dchild, dparent, locks */
974 if (dchild->d_inode == NULL) {
975 intent_set_disposition(rep, DISP_LOOKUP_NEG);
976 /* in the intent case, the policy clears this error:
977 the disposition is enough */
978 GOTO(cleanup, rc = -ENOENT);
980 intent_set_disposition(rep, DISP_LOOKUP_POS);
983 if (req->rq_repmsg == NULL) {
984 rc = mds_getattr_pack_msg(req, dchild->d_inode, offset);
986 CERROR ("mds_getattr_pack_msg: %d\n", rc);
991 rc = mds_getattr_internal(obd, dchild, req, body, offset);
992 GOTO(cleanup, rc); /* returns the lock to the client */
995 switch (cleanup_phase) {
997 if (resent_req == 0) {
998 if (rc && dchild->d_inode)
999 ldlm_lock_decref(child_lockh, LCK_CR);
1001 ldlm_lock_decref(&parent_lockh, LCK_CR);
1007 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1009 mds_exit_ucred(&uc, mds);
1010 if (req->rq_reply_state == NULL) {
1011 req->rq_status = rc;
1012 lustre_pack_reply(req, 1, NULL, NULL);
1018 static int mds_getattr(struct ptlrpc_request *req, int offset)
1020 struct mds_obd *mds = mds_req2mds(req);
1021 struct obd_device *obd = req->rq_export->exp_obd;
1022 struct lvfs_run_ctxt saved;
1024 struct mds_body *body;
1025 struct lvfs_ucred uc = {0,};
1029 OBD_COUNTER_INCREMENT(obd, getattr);
1031 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1032 lustre_swab_mds_body);
1036 rc = mds_init_ucred(&uc, req, offset);
1038 GOTO(out_ucred, rc);
1040 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1041 de = mds_fid2dentry(mds, &body->fid1, NULL);
1043 rc = req->rq_status = PTR_ERR(de);
1047 rc = mds_getattr_pack_msg(req, de->d_inode, offset);
1049 CERROR("mds_getattr_pack_msg: %d\n", rc);
1053 req->rq_status = mds_getattr_internal(obd, de, req, body,
1059 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1061 if (req->rq_reply_state == NULL) {
1062 req->rq_status = rc;
1063 lustre_pack_reply(req, 1, NULL, NULL);
1065 mds_exit_ucred(&uc, mds);
1069 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1074 spin_lock(&obd->obd_osfs_lock);
1075 rc = fsfilt_statfs(obd, obd->u.obt.obt_sb, max_age);
1077 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1078 spin_unlock(&obd->obd_osfs_lock);
1083 static int mds_statfs(struct ptlrpc_request *req)
1085 struct obd_device *obd = req->rq_export->exp_obd;
1086 int rc, size[2] = { sizeof(struct ptlrpc_body),
1087 sizeof(struct obd_statfs) };
1090 /* This will trigger a watchdog timeout */
1091 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1092 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1093 OBD_COUNTER_INCREMENT(obd, statfs);
1095 rc = lustre_pack_reply(req, 2, size, NULL);
1096 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1097 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1101 /* We call this so that we can cache a bit - 1 jiffie worth */
1102 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1103 size[REPLY_REC_OFF]),
1104 cfs_time_current_64() - HZ);
1106 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1112 req->rq_status = rc;
1116 static int mds_sync(struct ptlrpc_request *req, int offset)
1118 struct obd_device *obd = req->rq_export->exp_obd;
1119 struct mds_obd *mds = &obd->u.mds;
1120 struct mds_body *body;
1121 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1124 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1125 lustre_swab_mds_body);
1127 GOTO(out, rc = -EFAULT);
1129 rc = lustre_pack_reply(req, 2, size, NULL);
1130 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1131 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1135 if (body->fid1.id == 0) {
1136 /* a fid of zero is taken to mean "sync whole filesystem" */
1137 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
1142 de = mds_fid2dentry(mds, &body->fid1, NULL);
1144 GOTO(out, rc = PTR_ERR(de));
1146 /* The file parameter isn't used for anything */
1147 if (de->d_inode->i_fop && de->d_inode->i_fop->fsync)
1148 rc = de->d_inode->i_fop->fsync(NULL, de, 1);
1150 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1152 mds_pack_inode2fid(&body->fid1, de->d_inode);
1153 mds_pack_inode2body(body, de->d_inode);
1160 req->rq_status = rc;
1164 /* mds_readpage does not take a DLM lock on the inode, because the client must
1165 * already have a PR lock.
1167 * If we were to take another one here, a deadlock will result, if another
1168 * thread is already waiting for a PW lock. */
1169 static int mds_readpage(struct ptlrpc_request *req, int offset)
1171 struct obd_device *obd = req->rq_export->exp_obd;
1172 struct mds_obd *mds = &obd->u.mds;
1173 struct vfsmount *mnt;
1176 struct mds_body *body, *repbody;
1177 struct lvfs_run_ctxt saved;
1178 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
1179 struct lvfs_ucred uc = {0,};
1182 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1185 rc = lustre_pack_reply(req, 2, size, NULL);
1187 CERROR("error packing readpage reply: rc %d\n", rc);
1191 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1192 lustre_swab_mds_body);
1194 GOTO (out, rc = -EFAULT);
1196 rc = mds_init_ucred(&uc, req, offset);
1200 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1201 de = mds_fid2dentry(&obd->u.mds, &body->fid1, &mnt);
1203 GOTO(out_pop, rc = PTR_ERR(de));
1205 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1207 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1208 /* note: in case of an error, dentry_open puts dentry */
1210 GOTO(out_pop, rc = PTR_ERR(file));
1212 /* body->size is actually the offset -eeb */
1213 if ((body->size & (de->d_inode->i_sb->s_blocksize - 1)) != 0) {
1214 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1215 body->size, de->d_inode->i_sb->s_blocksize);
1216 GOTO(out_file, rc = -EFAULT);
1219 /* body->nlink is actually the #bytes to read -eeb */
1220 if (body->nlink & (de->d_inode->i_sb->s_blocksize - 1)) {
1221 CERROR("size %u is not multiple of blocksize %lu\n",
1222 body->nlink, de->d_inode->i_sb->s_blocksize);
1223 GOTO(out_file, rc = -EFAULT);
1226 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1228 repbody->size = file->f_dentry->d_inode->i_size;
1229 repbody->valid = OBD_MD_FLSIZE;
1231 /* to make this asynchronous make sure that the handling function
1232 doesn't send a reply when this function completes. Instead a
1233 callback function would send the reply */
1234 /* body->size is actually the offset -eeb */
1235 rc = mds_sendpage(req, file, body->size, body->nlink);
1238 filp_close(file, 0);
1240 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1242 mds_exit_ucred(&uc, mds);
1243 req->rq_status = rc;
1247 int mds_reint(struct ptlrpc_request *req, int offset,
1248 struct lustre_handle *lockh)
1250 struct mds_update_record *rec; /* 116 bytes on the stack? no sir! */
1253 OBD_ALLOC(rec, sizeof(*rec));
1257 rc = mds_update_unpack(req, offset, rec);
1258 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1259 CERROR("invalid record\n");
1260 GOTO(out, req->rq_status = -EINVAL);
1263 /* rc will be used to interrupt a for loop over multiple records */
1264 rc = mds_reint_rec(rec, offset, req, lockh);
1266 OBD_FREE(rec, sizeof(*rec));
1270 int mds_filter_recovery_request(struct ptlrpc_request *req,
1271 struct obd_device *obd, int *process)
1273 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1274 case MDS_CONNECT: /* This will never get here, but for completeness. */
1275 case OST_CONNECT: /* This will never get here, but for completeness. */
1276 case MDS_DISCONNECT:
1277 case OST_DISCONNECT:
1282 case MDS_DONE_WRITING:
1283 case MDS_SYNC: /* used in unmounting */
1289 *process = target_queue_recovery_request(req, obd);
1293 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1298 EXPORT_SYMBOL(mds_filter_recovery_request);
1300 static char *reint_names[] = {
1301 [REINT_SETATTR] "setattr",
1302 [REINT_CREATE] "create",
1303 [REINT_LINK] "link",
1304 [REINT_UNLINK] "unlink",
1305 [REINT_RENAME] "rename",
1306 [REINT_OPEN] "open",
1309 static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req)
1316 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1318 DEBUG_REQ(D_HA, req, "no set_info key");
1321 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1323 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*val));
1325 DEBUG_REQ(D_HA, req, "no set_info val");
1329 rc = lustre_pack_reply(req, 1, NULL, NULL);
1332 lustre_msg_set_status(req->rq_repmsg, 0);
1334 if (keylen < strlen("read-only") ||
1335 memcmp(key, "read-only", keylen) != 0)
1339 exp->exp_connect_flags |= OBD_CONNECT_RDONLY;
1341 exp->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1346 static int mds_handle_quotacheck(struct ptlrpc_request *req)
1348 struct obd_quotactl *oqctl;
1352 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1353 lustre_swab_obd_quotactl);
1357 rc = lustre_pack_reply(req, 1, NULL, NULL);
1359 CERROR("mds: out of memory while packing quotacheck reply\n");
1363 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1367 static int mds_handle_quotactl(struct ptlrpc_request *req)
1369 struct obd_quotactl *oqctl, *repoqc;
1370 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1373 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1374 lustre_swab_obd_quotactl);
1378 rc = lustre_pack_reply(req, 2, size, NULL);
1382 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1384 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1389 int mds_msg_check_version(struct lustre_msg *msg)
1393 switch (lustre_msg_get_opc(msg)) {
1395 case MDS_DISCONNECT:
1398 case SEC_CTX_INIT_CONT:
1400 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1402 CERROR("bad opc %u version %08x, expecting %08x\n",
1403 lustre_msg_get_opc(msg),
1404 lustre_msg_get_version(msg),
1405 LUSTRE_OBD_VERSION);
1409 case MDS_GETATTR_NAME:
1416 case MDS_DONE_WRITING:
1422 case MDS_QUOTACHECK:
1428 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
1430 CERROR("bad opc %u version %08x, expecting %08x\n",
1431 lustre_msg_get_opc(msg),
1432 lustre_msg_get_version(msg),
1433 LUSTRE_MDS_VERSION);
1437 case LDLM_BL_CALLBACK:
1438 case LDLM_CP_CALLBACK:
1439 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1441 CERROR("bad opc %u version %08x, expecting %08x\n",
1442 lustre_msg_get_opc(msg),
1443 lustre_msg_get_version(msg),
1444 LUSTRE_DLM_VERSION);
1446 case OBD_LOG_CANCEL:
1447 case LLOG_ORIGIN_HANDLE_CREATE:
1448 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1449 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1450 case LLOG_ORIGIN_HANDLE_CLOSE:
1451 case LLOG_ORIGIN_HANDLE_DESTROY:
1452 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1454 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1456 CERROR("bad opc %u version %08x, expecting %08x\n",
1457 lustre_msg_get_opc(msg),
1458 lustre_msg_get_version(msg),
1459 LUSTRE_LOG_VERSION);
1462 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
1467 EXPORT_SYMBOL(mds_msg_check_version);
1469 int mds_handle(struct ptlrpc_request *req)
1471 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
1473 struct mds_obd *mds = NULL; /* quell gcc overwarning */
1474 struct obd_device *obd = NULL;
1477 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
1479 LASSERT(current->journal_info == NULL);
1481 rc = mds_msg_check_version(req->rq_reqmsg);
1483 CERROR("MDS drop mal-formed request\n");
1487 /* XXX identical to OST */
1488 if (lustre_msg_get_opc(req->rq_reqmsg) != MDS_CONNECT) {
1489 struct mds_export_data *med;
1492 if (req->rq_export == NULL) {
1493 CERROR("operation %d on unconnected MDS from %s\n",
1494 lustre_msg_get_opc(req->rq_reqmsg),
1495 libcfs_id2str(req->rq_peer));
1496 req->rq_status = -ENOTCONN;
1497 GOTO(out, rc = -ENOTCONN);
1500 med = &req->rq_export->exp_mds_data;
1501 obd = req->rq_export->exp_obd;
1502 mds = mds_req2mds(req);
1504 /* sanity check: if the xid matches, the request must
1505 * be marked as a resent or replayed */
1506 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
1507 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid))
1508 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
1509 (MSG_RESENT | MSG_REPLAY))) {
1510 CERROR("rq_xid "LPU64" matches last_xid, "
1511 "expected RESENT flag\n",
1513 req->rq_status = -ENOTCONN;
1514 GOTO(out, rc = -EFAULT);
1516 /* else: note the opposite is not always true; a
1517 * RESENT req after a failover will usually not match
1518 * the last_xid, since it was likely never
1519 * committed. A REPLAYed request will almost never
1520 * match the last xid, however it could for a
1521 * committed, but still retained, open. */
1523 /* Check for aborted recovery. */
1524 spin_lock_bh(&obd->obd_processing_task_lock);
1525 recovering = obd->obd_recovering;
1526 spin_unlock_bh(&obd->obd_processing_task_lock);
1528 rc = mds_filter_recovery_request(req, obd,
1530 if (rc || !should_process)
1532 else if (should_process < 0) {
1533 req->rq_status = should_process;
1534 rc = ptlrpc_error(req);
1540 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1542 DEBUG_REQ(D_INODE, req, "connect");
1543 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
1544 rc = target_handle_connect(req);
1546 /* Now that we have an export, set mds. */
1548 * XXX nikita: these assignments are useless: mds is
1549 * never used below, and obd is only used for
1550 * MSG_LAST_REPLAY case, which never happens for
1553 obd = req->rq_export->exp_obd;
1554 mds = mds_req2mds(req);
1558 case MDS_DISCONNECT:
1559 DEBUG_REQ(D_INODE, req, "disconnect");
1560 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
1561 rc = target_handle_disconnect(req);
1562 req->rq_status = rc; /* superfluous? */
1566 DEBUG_REQ(D_INODE, req, "getstatus");
1567 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
1568 rc = mds_getstatus(req);
1572 DEBUG_REQ(D_INODE, req, "getattr");
1573 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
1574 rc = mds_getattr(req, REQ_REC_OFF);
1578 DEBUG_REQ(D_INODE, req, "setxattr");
1579 OBD_FAIL_RETURN(OBD_FAIL_MDS_SETXATTR_NET, 0);
1580 rc = mds_setxattr(req);
1584 DEBUG_REQ(D_INODE, req, "getxattr");
1585 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETXATTR_NET, 0);
1586 rc = mds_getxattr(req);
1589 case MDS_GETATTR_NAME: {
1590 struct lustre_handle lockh = { 0 };
1591 DEBUG_REQ(D_INODE, req, "getattr_name");
1592 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NAME_NET, 0);
1594 /* If this request gets a reconstructed reply, we won't be
1595 * acquiring any new locks in mds_getattr_lock, so we don't
1598 rc = mds_getattr_lock(req, REQ_REC_OFF, MDS_INODELOCK_UPDATE,
1600 /* this non-intent call (from an ioctl) is special */
1601 req->rq_status = rc;
1602 if (rc == 0 && lustre_handle_is_used(&lockh))
1603 ldlm_lock_decref(&lockh, LCK_CR);
1607 DEBUG_REQ(D_INODE, req, "statfs");
1608 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
1609 rc = mds_statfs(req);
1613 DEBUG_REQ(D_INODE, req, "readpage");
1614 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
1615 rc = mds_readpage(req, REQ_REC_OFF);
1617 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
1624 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
1627 int size[4] = { sizeof(struct ptlrpc_body),
1628 sizeof(struct mds_body),
1629 mds->mds_max_mdsize,
1630 mds->mds_max_cookiesize };
1633 /* NB only peek inside req now; mds_reint() will swab it */
1635 CERROR ("Can't inspect opcode\n");
1640 if (lustre_msg_swabbed(req->rq_reqmsg))
1643 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
1644 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
1645 reint_names[opc] == NULL) ? reint_names[opc] :
1648 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
1650 if (opc == REINT_UNLINK || opc == REINT_RENAME)
1652 else if (opc == REINT_OPEN)
1657 rc = lustre_pack_reply(req, bufcount, size, NULL);
1661 rc = mds_reint(req, REQ_REC_OFF, NULL);
1662 fail = OBD_FAIL_MDS_REINT_NET_REP;
1667 DEBUG_REQ(D_INODE, req, "close");
1668 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
1669 rc = mds_close(req, REQ_REC_OFF);
1672 case MDS_DONE_WRITING:
1673 DEBUG_REQ(D_INODE, req, "done_writing");
1674 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
1675 rc = mds_done_writing(req, REQ_REC_OFF);
1679 DEBUG_REQ(D_INODE, req, "pin");
1680 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
1681 rc = mds_pin(req, REQ_REC_OFF);
1685 DEBUG_REQ(D_INODE, req, "sync");
1686 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
1687 rc = mds_sync(req, REQ_REC_OFF);
1691 DEBUG_REQ(D_INODE, req, "set_info");
1692 rc = mds_set_info_rpc(req->rq_export, req);
1695 case MDS_QUOTACHECK:
1696 DEBUG_REQ(D_INODE, req, "quotacheck");
1697 OBD_FAIL_RETURN(OBD_FAIL_MDS_QUOTACHECK_NET, 0);
1698 rc = mds_handle_quotacheck(req);
1702 DEBUG_REQ(D_INODE, req, "quotactl");
1703 OBD_FAIL_RETURN(OBD_FAIL_MDS_QUOTACTL_NET, 0);
1704 rc = mds_handle_quotactl(req);
1708 DEBUG_REQ(D_INODE, req, "ping");
1709 rc = target_handle_ping(req);
1712 case OBD_LOG_CANCEL:
1713 CDEBUG(D_INODE, "log cancel\n");
1714 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1715 rc = -ENOTSUPP; /* la la la */
1719 DEBUG_REQ(D_INODE, req, "enqueue");
1720 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1721 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1722 ldlm_server_blocking_ast, NULL);
1723 fail = OBD_FAIL_LDLM_REPLY;
1726 DEBUG_REQ(D_INODE, req, "convert");
1727 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1728 rc = ldlm_handle_convert(req);
1730 case LDLM_BL_CALLBACK:
1731 case LDLM_CP_CALLBACK:
1732 DEBUG_REQ(D_INODE, req, "callback");
1733 CERROR("callbacks should not happen on MDS\n");
1735 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
1737 case LLOG_ORIGIN_HANDLE_CREATE:
1738 DEBUG_REQ(D_INODE, req, "llog_init");
1739 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1740 rc = llog_origin_handle_create(req);
1742 case LLOG_ORIGIN_HANDLE_DESTROY:
1743 DEBUG_REQ(D_INODE, req, "llog_init");
1744 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1745 rc = llog_origin_handle_destroy(req);
1747 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1748 DEBUG_REQ(D_INODE, req, "llog next block");
1749 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1750 rc = llog_origin_handle_next_block(req);
1752 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1753 DEBUG_REQ(D_INODE, req, "llog prev block");
1754 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1755 rc = llog_origin_handle_prev_block(req);
1757 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1758 DEBUG_REQ(D_INODE, req, "llog read header");
1759 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1760 rc = llog_origin_handle_read_header(req);
1762 case LLOG_ORIGIN_HANDLE_CLOSE:
1763 DEBUG_REQ(D_INODE, req, "llog close");
1764 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1765 rc = llog_origin_handle_close(req);
1768 DEBUG_REQ(D_INODE, req, "llog catinfo");
1769 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1770 rc = llog_catinfo(req);
1773 req->rq_status = -ENOTSUPP;
1774 rc = ptlrpc_error(req);
1778 LASSERT(current->journal_info == NULL);
1780 /* If we're DISCONNECTing, the mds_export_data is already freed */
1781 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != MDS_DISCONNECT) {
1782 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1784 /* I don't think last_xid is used for anyway, so I'm not sure
1785 if we need to care about last_close_xid here.*/
1786 lustre_msg_set_last_xid(req->rq_repmsg,
1787 le64_to_cpu(med->med_mcd->mcd_last_xid));
1789 target_committed_to_req(req);
1795 target_send_reply(req, rc, fail);
1799 /* Update the server data on disk. This stores the new mount_count and
1800 * also the last_rcvd value to disk. If we don't have a clean shutdown,
1801 * then the server last_rcvd value may be less than that of the clients.
1802 * This will alert us that we may need to do client recovery.
1804 * Also assumes for mds_last_transno that we are not modifying it (no locking).
1806 int mds_update_server_data(struct obd_device *obd, int force_sync)
1808 struct mds_obd *mds = &obd->u.mds;
1809 struct lr_server_data *lsd = mds->mds_server_data;
1810 struct file *filp = mds->mds_rcvd_filp;
1811 struct lvfs_run_ctxt saved;
1816 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
1817 mds->mds_mount_count, mds->mds_last_transno);
1819 spin_lock(&mds->mds_transno_lock);
1820 lsd->lsd_last_transno = cpu_to_le64(mds->mds_last_transno);
1821 spin_unlock(&mds->mds_transno_lock);
1823 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1824 rc = fsfilt_write_record(obd, filp, lsd, sizeof(*lsd), &off,force_sync);
1825 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1827 CERROR("error writing MDS server data: rc = %d\n", rc);
1831 static void fsoptions_to_mds_flags(struct mds_obd *mds, char *options)
1841 while (*p && *p != ',')
1845 if (len == sizeof("user_xattr") - 1 &&
1846 memcmp(options, "user_xattr", len) == 0) {
1847 mds->mds_fl_user_xattr = 1;
1848 LCONSOLE_INFO("Enabling user_xattr\n");
1849 } else if (len == sizeof("nouser_xattr") - 1 &&
1850 memcmp(options, "nouser_xattr", len) == 0) {
1851 mds->mds_fl_user_xattr = 0;
1852 LCONSOLE_INFO("Disabling user_xattr\n");
1853 } else if (len == sizeof("acl") - 1 &&
1854 memcmp(options, "acl", len) == 0) {
1855 #ifdef CONFIG_FS_POSIX_ACL
1856 mds->mds_fl_acl = 1;
1857 LCONSOLE_INFO("Enabling ACL\n");
1859 CWARN("ignoring unsupported acl mount option\n");
1861 } else if (len == sizeof("noacl") - 1 &&
1862 memcmp(options, "noacl", len) == 0) {
1863 #ifdef CONFIG_FS_POSIX_ACL
1864 mds->mds_fl_acl = 0;
1865 LCONSOLE_INFO("Disabling ACL\n");
1872 static int mds_lov_presetup (struct mds_obd *mds, struct lustre_cfg *lcfg)
1877 rc = llog_start_commit_thread();
1881 if (lcfg->lcfg_bufcount >= 4 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
1884 ll_generate_random_uuid(uuid);
1885 class_uuid_unparse(uuid, &mds->mds_lov_uuid);
1887 OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
1888 if (mds->mds_profile == NULL)
1891 strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
1892 LUSTRE_CFG_BUFLEN(lcfg, 3));
1897 /* mount the file system (secretly). lustre_cfg parameters are:
1903 static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1905 struct lprocfs_static_vars lvars;
1906 struct mds_obd *mds = &obd->u.mds;
1907 struct lustre_mount_info *lmi;
1908 struct vfsmount *mnt;
1909 struct lustre_sb_info *lsi;
1910 struct obd_uuid uuid;
1917 /* setup 1:/dev/loop/0 2:ext3 3:mdsA 4:errors=remount-ro,iopen_nopriv */
1919 CLASSERT(offsetof(struct obd_device, u.obt) ==
1920 offsetof(struct obd_device, u.mds.mds_obt));
1922 if (lcfg->lcfg_bufcount < 3)
1925 if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0)
1928 lmi = server_get_mount(obd->obd_name);
1930 CERROR("Not mounted in lustre_fill_super?\n");
1934 /* We mounted in lustre_fill_super.
1935 lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
1937 lsi = s2lsi(lmi->lmi_sb);
1938 fsoptions_to_mds_flags(mds, lsi->lsi_ldd->ldd_mount_opts);
1939 fsoptions_to_mds_flags(mds, lsi->lsi_lmd->lmd_opts);
1941 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
1942 if (IS_ERR(obd->obd_fsops))
1943 GOTO(err_put, rc = PTR_ERR(obd->obd_fsops));
1945 CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt);
1947 LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
1949 sema_init(&mds->mds_epoch_sem, 1);
1950 spin_lock_init(&mds->mds_transno_lock);
1951 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
1952 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
1953 mds->mds_atime_diff = MAX_ATIME_DIFF;
1955 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
1956 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
1957 if (obd->obd_namespace == NULL) {
1959 GOTO(err_ops, rc = -ENOMEM);
1961 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
1963 lprocfs_init_vars(mds, &lvars);
1964 if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
1965 lprocfs_alloc_obd_stats(obd, LPROC_MDS_LAST) == 0) {
1966 /* Init private stats here */
1967 mds_stats_counter_init(obd->obd_stats);
1968 obd->obd_proc_exports = proc_mkdir("exports",
1969 obd->obd_proc_entry);
1972 rc = mds_fs_setup(obd, mnt);
1974 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
1979 rc = mds_lov_presetup(mds, lcfg);
1983 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1984 "mds_ldlm_client", &obd->obd_ldlm_client);
1985 obd->obd_replayable = 1;
1987 rc = lquota_setup(mds_quota_interface_ref, obd);
1992 mds->mds_group_hash = upcall_cache_init(obd->obd_name);
1993 if (IS_ERR(mds->mds_group_hash)) {
1994 rc = PTR_ERR(mds->mds_group_hash);
1995 mds->mds_group_hash = NULL;
1996 GOTO(err_qctxt, rc);
2000 /* Don't wait for mds_postrecov trying to clear orphans */
2001 obd->obd_async_recov = 1;
2002 rc = mds_postsetup(obd);
2003 /* Bug 11557 - allow async abort_recov start
2004 FIXME can remove most of this obd_async_recov plumbing
2005 obd->obd_async_recov = 0;
2008 GOTO(err_qctxt, rc);
2010 uuid_ptr = fsfilt_uuid(obd, obd->u.obt.obt_sb);
2011 if (uuid_ptr != NULL) {
2012 class_uuid_unparse(uuid_ptr, &uuid);
2018 label = fsfilt_get_label(obd, obd->u.obt.obt_sb);
2019 if (obd->obd_recovering) {
2020 LCONSOLE_WARN("MDT %s now serving %s (%s%s%s), but will be in "
2021 "recovery until %d %s reconnect, or if no clients"
2022 " reconnect for %d:%.02d; during that time new "
2023 "clients will not be allowed to connect. "
2024 "Recovery progress can be monitored by watching "
2025 "/proc/fs/lustre/mds/%s/recovery_status.\n",
2026 obd->obd_name, lustre_cfg_string(lcfg, 1),
2027 label ?: "", label ? "/" : "", str,
2028 obd->obd_max_recoverable_clients,
2029 (obd->obd_max_recoverable_clients == 1) ?
2030 "client" : "clients",
2031 (int)(OBD_RECOVERY_TIMEOUT) / 60,
2032 (int)(OBD_RECOVERY_TIMEOUT) % 60,
2035 LCONSOLE_INFO("MDT %s now serving %s (%s%s%s) with recovery "
2036 "%s\n", obd->obd_name, lustre_cfg_string(lcfg, 1),
2037 label ?: "", label ? "/" : "", str,
2038 obd->obd_replayable ? "enabled" : "disabled");
2041 if (ldlm_timeout == LDLM_TIMEOUT_DEFAULT)
2047 lquota_cleanup(mds_quota_interface_ref, obd);
2049 /* No extra cleanup needed for llog_init_commit_thread() */
2050 mds_fs_cleanup(obd);
2052 upcall_cache_cleanup(mds->mds_group_hash);
2053 mds->mds_group_hash = NULL;
2056 lprocfs_obd_cleanup(obd);
2057 lprocfs_free_obd_stats(obd);
2058 ldlm_namespace_free(obd->obd_namespace, 0);
2059 obd->obd_namespace = NULL;
2061 fsfilt_put_ops(obd->obd_fsops);
2063 server_put_mount(obd->obd_name, mnt);
2064 obd->u.obt.obt_sb = NULL;
2068 static int mds_lov_clean(struct obd_device *obd)
2070 struct mds_obd *mds = &obd->u.mds;
2071 struct obd_device *osc = mds->mds_osc_obd;
2074 if (mds->mds_profile) {
2075 class_del_profile(mds->mds_profile);
2076 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
2077 mds->mds_profile = NULL;
2080 /* There better be a lov */
2084 RETURN(PTR_ERR(osc));
2086 obd_register_observer(osc, NULL);
2088 /* Give lov our same shutdown flags */
2089 osc->obd_force = obd->obd_force;
2090 osc->obd_fail = obd->obd_fail;
2092 /* Cleanup the lov */
2093 obd_disconnect(mds->mds_osc_exp);
2094 class_manual_cleanup(osc);
2095 mds->mds_osc_exp = NULL;
2100 static int mds_postsetup(struct obd_device *obd)
2102 struct mds_obd *mds = &obd->u.mds;
2106 rc = llog_setup(obd, NULL, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL,
2111 rc = llog_setup(obd, NULL, LLOG_LOVEA_ORIG_CTXT, obd, 0, NULL,
2116 if (mds->mds_profile) {
2117 struct lustre_profile *lprof;
2118 /* The profile defines which osc and mdc to connect to, for a
2119 client. We reuse that here to figure out the name of the
2120 lov to use (and ignore lprof->lp_md).
2121 The profile was set in the config log with
2122 LCFG_MOUNTOPT profilenm oscnm mdcnm */
2123 lprof = class_get_profile(mds->mds_profile);
2124 if (lprof == NULL) {
2125 CERROR("No profile found: %s\n", mds->mds_profile);
2126 GOTO(err_cleanup, rc = -ENOENT);
2128 rc = mds_lov_connect(obd, lprof->lp_dt);
2130 GOTO(err_cleanup, rc);
2137 llog_cleanup(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT));
2138 llog_cleanup(llog_get_context(obd, LLOG_LOVEA_ORIG_CTXT));
2142 int mds_postrecov(struct obd_device *obd)
2150 LASSERT(!obd->obd_recovering);
2151 LASSERT(llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT) != NULL);
2153 /* FIXME why not put this in the synchronize? */
2154 /* set nextid first, so we are sure it happens */
2155 rc = mds_lov_set_nextid(obd);
2157 CERROR("%s: mds_lov_set_nextid failed %d\n",
2162 /* clean PENDING dir */
2163 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2164 rc = mds_cleanup_pending(obd);
2168 /* FIXME Does target_finish_recovery really need this to block? */
2169 /* Notify the LOV, which will in turn call mds_notify for each tgt */
2170 /* This means that we have to hack obd_notify to think we're obd_set_up
2171 during mds_lov_connect. */
2172 obd_notify(obd->u.mds.mds_osc_obd, NULL,
2173 obd->obd_async_recov ? OBD_NOTIFY_SYNC_NONBLOCK :
2174 OBD_NOTIFY_SYNC, NULL);
2176 /* quota recovery */
2177 lquota_recovery(mds_quota_interface_ref, obd);
2183 /* We need to be able to stop an mds_lov_synchronize */
2184 static int mds_lov_early_clean(struct obd_device *obd)
2186 struct mds_obd *mds = &obd->u.mds;
2187 struct obd_device *osc = mds->mds_osc_obd;
2189 if (!osc || (!obd->obd_force && !obd->obd_fail))
2192 CDEBUG(D_HA, "abort inflight\n");
2193 return (obd_precleanup(osc, OBD_CLEANUP_EARLY));
2196 static int mds_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2202 case OBD_CLEANUP_EARLY:
2204 case OBD_CLEANUP_EXPORTS:
2205 /*XXX Use this for mdd mds cleanup, so comment out
2206 *this target_cleanup_recovery for this tmp MDD MDS
2208 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2209 target_cleanup_recovery(obd);
2210 mds_lov_early_clean(obd);
2212 case OBD_CLEANUP_SELF_EXP:
2213 mds_lov_disconnect(obd);
2215 llog_cleanup(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT));
2216 llog_cleanup(llog_get_context(obd, LLOG_LOVEA_ORIG_CTXT));
2217 rc = obd_llog_finish(obd, 0);
2219 case OBD_CLEANUP_OBD:
2225 static int mds_cleanup(struct obd_device *obd)
2227 struct mds_obd *mds = &obd->u.mds;
2228 lvfs_sbdev_type save_dev;
2231 if (obd->u.obt.obt_sb == NULL)
2233 save_dev = lvfs_sbdev(obd->u.obt.obt_sb);
2235 if (mds->mds_osc_exp)
2236 /* lov export was disconnected by mds_lov_clean;
2237 we just need to drop our ref */
2238 class_export_put(mds->mds_osc_exp);
2240 lprocfs_obd_cleanup(obd);
2241 lprocfs_free_obd_stats(obd);
2243 lquota_cleanup(mds_quota_interface_ref, obd);
2245 mds_update_server_data(obd, 1);
2246 if (mds->mds_lov_objids != NULL)
2247 OBD_FREE(mds->mds_lov_objids, mds->mds_lov_objids_size);
2248 mds_fs_cleanup(obd);
2251 upcall_cache_cleanup(mds->mds_group_hash);
2252 mds->mds_group_hash = NULL;
2255 server_put_mount(obd->obd_name, mds->mds_vfsmnt);
2256 obd->u.obt.obt_sb = NULL;
2258 ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
2260 spin_lock_bh(&obd->obd_processing_task_lock);
2261 if (obd->obd_recovering) {
2262 target_cancel_recovery_timer(obd);
2263 obd->obd_recovering = 0;
2265 spin_unlock_bh(&obd->obd_processing_task_lock);
2267 fsfilt_put_ops(obd->obd_fsops);
2269 LCONSOLE_INFO("MDT %s has stopped.\n", obd->obd_name);
2274 static void fixup_handle_for_resent_req(struct ptlrpc_request *req, int offset,
2275 struct ldlm_lock *new_lock,
2276 struct ldlm_lock **old_lock,
2277 struct lustre_handle *lockh)
2279 struct obd_export *exp = req->rq_export;
2280 struct ldlm_request *dlmreq =
2281 lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*dlmreq));
2282 struct lustre_handle remote_hdl = dlmreq->lock_handle[0];
2283 struct list_head *iter;
2285 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2288 spin_lock(&exp->exp_ldlm_data.led_lock);
2289 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2290 struct ldlm_lock *lock;
2291 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2292 if (lock == new_lock)
2294 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2295 lockh->cookie = lock->l_handle.h_cookie;
2296 LDLM_DEBUG(lock, "restoring lock cookie");
2297 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
2300 *old_lock = LDLM_LOCK_GET(lock);
2301 spin_unlock(&exp->exp_ldlm_data.led_lock);
2305 spin_unlock(&exp->exp_ldlm_data.led_lock);
2307 /* If the xid matches, then we know this is a resent request,
2308 * and allow it. (It's probably an OPEN, for which we don't
2311 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
2315 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
2318 /* This remote handle isn't enqueued, so we never received or
2319 * processed this request. Clear MSG_RESENT, because it can
2320 * be handled like any normal request now. */
2322 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2324 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
2328 int intent_disposition(struct ldlm_reply *rep, int flag)
2332 return (rep->lock_policy_res1 & flag);
2335 void intent_set_disposition(struct ldlm_reply *rep, int flag)
2339 rep->lock_policy_res1 |= flag;
2342 static int mds_intent_policy(struct ldlm_namespace *ns,
2343 struct ldlm_lock **lockp, void *req_cookie,
2344 ldlm_mode_t mode, int flags, void *data)
2346 struct ptlrpc_request *req = req_cookie;
2347 struct ldlm_lock *lock = *lockp;
2348 struct ldlm_intent *it;
2349 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
2350 struct ldlm_reply *rep;
2351 struct lustre_handle lockh = { 0 };
2352 struct ldlm_lock *new_lock = NULL;
2353 int getattr_part = MDS_INODELOCK_UPDATE;
2354 int repsize[5] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
2355 [DLM_LOCKREPLY_OFF] = sizeof(struct ldlm_reply),
2356 [DLM_REPLY_REC_OFF] = sizeof(struct mds_body),
2357 [DLM_REPLY_REC_OFF+1] = mds->mds_max_mdsize };
2358 int repbufcnt = 4, rc;
2361 LASSERT(req != NULL);
2363 if (lustre_msg_bufcount(req->rq_reqmsg) <= DLM_INTENT_IT_OFF) {
2364 /* No intent was provided */
2365 rc = lustre_pack_reply(req, 2, repsize, NULL);
2370 it = lustre_swab_reqbuf(req, DLM_INTENT_IT_OFF, sizeof(*it),
2371 lustre_swab_ldlm_intent);
2373 CERROR("Intent missing\n");
2374 RETURN(req->rq_status = -EFAULT);
2377 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
2379 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
2380 (it->opc & (IT_OPEN | IT_GETATTR | IT_LOOKUP)))
2381 /* we should never allow OBD_CONNECT_ACL if not configured */
2382 repsize[repbufcnt++] = LUSTRE_POSIX_ACL_MAX_SIZE;
2383 else if (it->opc & IT_UNLINK)
2384 repsize[repbufcnt++] = mds->mds_max_cookiesize;
2386 rc = lustre_pack_reply(req, repbufcnt, repsize, NULL);
2388 RETURN(req->rq_status = rc);
2390 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep));
2391 intent_set_disposition(rep, DISP_IT_EXECD);
2394 /* execute policy */
2395 switch ((long)it->opc) {
2397 case IT_CREAT|IT_OPEN:
2398 mds_counter_incr(req->rq_export, LPROC_MDS_OPEN);
2399 fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock, NULL,
2401 /* XXX swab here to assert that an mds_open reint
2402 * packet is following */
2403 rep->lock_policy_res2 = mds_reint(req, DLM_INTENT_REC_OFF,
2406 /* We abort the lock if the lookup was negative and
2407 * we did not make it to the OPEN portion */
2408 if (!intent_disposition(rep, DISP_LOOKUP_EXECD))
2409 RETURN(ELDLM_LOCK_ABORTED);
2410 if (intent_disposition(rep, DISP_LOOKUP_NEG) &&
2411 !intent_disposition(rep, DISP_OPEN_OPEN))
2414 /* If there was an error of some sort or if we are not
2415 * returning any locks */
2416 if (rep->lock_policy_res2 ||
2417 !intent_disposition(rep, DISP_OPEN_LOCK))
2418 RETURN(ELDLM_LOCK_ABORTED);
2421 getattr_part = MDS_INODELOCK_LOOKUP;
2423 getattr_part |= MDS_INODELOCK_LOOKUP;
2424 OBD_COUNTER_INCREMENT(req->rq_export->exp_obd, getattr);
2426 fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock,
2429 /* INODEBITS_INTEROP: if this lock was converted from a
2430 * plain lock (client does not support inodebits), then
2431 * child lock must be taken with both lookup and update
2432 * bits set for all operations.
2434 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS))
2435 getattr_part = MDS_INODELOCK_LOOKUP |
2436 MDS_INODELOCK_UPDATE;
2438 rep->lock_policy_res2 = mds_getattr_lock(req,DLM_INTENT_REC_OFF,
2439 getattr_part, &lockh);
2440 /* FIXME: LDLM can set req->rq_status. MDS sets
2441 policy_res{1,2} with disposition and status.
2442 - replay: returns 0 & req->status is old status
2443 - otherwise: returns req->status */
2444 if (intent_disposition(rep, DISP_LOOKUP_NEG))
2445 rep->lock_policy_res2 = 0;
2446 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
2447 rep->lock_policy_res2)
2448 RETURN(ELDLM_LOCK_ABORTED);
2449 if (req->rq_status != 0) {
2451 rep->lock_policy_res2 = req->rq_status;
2452 RETURN(ELDLM_LOCK_ABORTED);
2456 CERROR("Unhandled intent "LPD64"\n", it->opc);
2460 /* By this point, whatever function we called above must have either
2461 * filled in 'lockh', been an intent replay, or returned an error. We
2462 * want to allow replayed RPCs to not get a lock, since we would just
2463 * drop it below anyways because lock replay is done separately by the
2464 * client afterwards. For regular RPCs we want to give the new lock to
2465 * the client instead of whatever lock it was about to get. */
2466 if (new_lock == NULL)
2467 new_lock = ldlm_handle2lock(&lockh);
2468 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
2471 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
2472 it->opc, lockh.cookie);
2474 /* If we've already given this lock to a client once, then we should
2475 * have no readers or writers. Otherwise, we should have one reader
2476 * _or_ writer ref (which will be zeroed below) before returning the
2477 * lock to a client. */
2478 if (new_lock->l_export == req->rq_export) {
2479 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2481 LASSERT(new_lock->l_export == NULL);
2482 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2487 if (new_lock->l_export == req->rq_export) {
2488 /* Already gave this to the client, which means that we
2489 * reconstructed a reply. */
2490 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2492 RETURN(ELDLM_LOCK_REPLACED);
2495 /* Fixup the lock to be given to the client */
2496 lock_res_and_lock(new_lock);
2497 new_lock->l_readers = 0;
2498 new_lock->l_writers = 0;
2500 new_lock->l_export = class_export_get(req->rq_export);
2501 spin_lock(&req->rq_export->exp_ldlm_data.led_lock);
2502 list_add(&new_lock->l_export_chain,
2503 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2504 spin_unlock(&req->rq_export->exp_ldlm_data.led_lock);
2506 new_lock->l_blocking_ast = lock->l_blocking_ast;
2507 new_lock->l_completion_ast = lock->l_completion_ast;
2509 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
2510 sizeof(lock->l_remote_handle));
2512 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2514 unlock_res_and_lock(new_lock);
2515 LDLM_LOCK_PUT(new_lock);
2517 RETURN(ELDLM_LOCK_REPLACED);
2520 static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
2522 struct mds_obd *mds = &obd->u.mds;
2523 struct lprocfs_static_vars lvars;
2524 int mds_min_threads;
2525 int mds_max_threads;
2529 lprocfs_init_vars(mdt, &lvars);
2530 lprocfs_obd_setup(obd, lvars.obd_vars);
2532 sema_init(&mds->mds_health_sem, 1);
2534 if (mds_num_threads) {
2535 /* If mds_num_threads is set, it is the min and the max. */
2536 if (mds_num_threads > MDS_THREADS_MAX)
2537 mds_num_threads = MDS_THREADS_MAX;
2538 if (mds_num_threads < MDS_THREADS_MIN)
2539 mds_num_threads = MDS_THREADS_MIN;
2540 mds_max_threads = mds_min_threads = mds_num_threads;
2542 /* Base min threads on memory and cpus */
2543 mds_min_threads = smp_num_cpus * num_physpages >>
2544 (27 - CFS_PAGE_SHIFT);
2545 if (mds_min_threads < MDS_THREADS_MIN)
2546 mds_min_threads = MDS_THREADS_MIN;
2547 /* Largest auto threads start value */
2548 if (mds_min_threads > 32)
2549 mds_min_threads = 32;
2550 mds_max_threads = min(MDS_THREADS_MAX, mds_min_threads * 4);
2554 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2555 MDS_MAXREPSIZE, MDS_REQUEST_PORTAL,
2556 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2557 mds_handle, LUSTRE_MDS_NAME,
2558 obd->obd_proc_entry, NULL,
2559 mds_min_threads, mds_max_threads, "ll_mdt", 0);
2561 if (!mds->mds_service) {
2562 CERROR("failed to start service\n");
2563 GOTO(err_lprocfs, rc = -ENOMEM);
2566 rc = ptlrpc_start_threads(obd, mds->mds_service);
2568 GOTO(err_thread, rc);
2570 mds->mds_setattr_service =
2571 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2572 MDS_MAXREPSIZE, MDS_SETATTR_PORTAL,
2573 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2574 mds_handle, "mds_setattr",
2575 obd->obd_proc_entry, NULL,
2576 mds_min_threads, mds_max_threads,
2578 if (!mds->mds_setattr_service) {
2579 CERROR("failed to start getattr service\n");
2580 GOTO(err_thread, rc = -ENOMEM);
2583 rc = ptlrpc_start_threads(obd, mds->mds_setattr_service);
2585 GOTO(err_thread2, rc);
2587 mds->mds_readpage_service =
2588 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2589 MDS_MAXREPSIZE, MDS_READPAGE_PORTAL,
2590 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2591 mds_handle, "mds_readpage",
2592 obd->obd_proc_entry, NULL,
2593 MDS_THREADS_MIN_READPAGE, mds_max_threads,
2595 if (!mds->mds_readpage_service) {
2596 CERROR("failed to start readpage service\n");
2597 GOTO(err_thread2, rc = -ENOMEM);
2600 rc = ptlrpc_start_threads(obd, mds->mds_readpage_service);
2603 GOTO(err_thread3, rc);
2605 ping_evictor_start();
2610 ptlrpc_unregister_service(mds->mds_readpage_service);
2611 mds->mds_readpage_service = NULL;
2613 ptlrpc_unregister_service(mds->mds_setattr_service);
2614 mds->mds_setattr_service = NULL;
2616 ptlrpc_unregister_service(mds->mds_service);
2617 mds->mds_service = NULL;
2619 lprocfs_obd_cleanup(obd);
2623 static int mdt_cleanup(struct obd_device *obd)
2625 struct mds_obd *mds = &obd->u.mds;
2628 ping_evictor_stop();
2630 down(&mds->mds_health_sem);
2631 ptlrpc_unregister_service(mds->mds_readpage_service);
2632 ptlrpc_unregister_service(mds->mds_setattr_service);
2633 ptlrpc_unregister_service(mds->mds_service);
2634 mds->mds_readpage_service = NULL;
2635 mds->mds_setattr_service = NULL;
2636 mds->mds_service = NULL;
2637 up(&mds->mds_health_sem);
2639 lprocfs_obd_cleanup(obd);
2644 static int mdt_health_check(struct obd_device *obd)
2646 struct mds_obd *mds = &obd->u.mds;
2649 down(&mds->mds_health_sem);
2650 rc |= ptlrpc_service_health_check(mds->mds_readpage_service);
2651 rc |= ptlrpc_service_health_check(mds->mds_setattr_service);
2652 rc |= ptlrpc_service_health_check(mds->mds_service);
2653 up(&mds->mds_health_sem);
2656 * health_check to return 0 on healthy
2657 * and 1 on unhealthy.
2665 static struct dentry *mds_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
2668 struct obd_device *obd = data;
2671 fid.generation = gen;
2672 return mds_fid2dentry(&obd->u.mds, &fid, NULL);
2675 static int mds_health_check(struct obd_device *obd)
2677 struct obd_device_target *odt = &obd->u.obt;
2678 #ifdef USE_HEALTH_CHECK_WRITE
2679 struct mds_obd *mds = &obd->u.mds;
2683 if (odt->obt_sb->s_flags & MS_RDONLY)
2686 #ifdef USE_HEALTH_CHECK_WRITE
2687 LASSERT(mds->mds_health_check_filp != NULL);
2688 rc |= !!lvfs_check_io_health(obd, mds->mds_health_check_filp);
2693 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
2695 struct lustre_cfg *lcfg = buf;
2696 struct lprocfs_static_vars lvars;
2699 lprocfs_init_vars(mds, &lvars);
2701 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, lcfg, obd);
2705 struct lvfs_callback_ops mds_lvfs_ops = {
2706 l_fid2dentry: mds_lvfs_fid2dentry,
2709 /* use obd ops to offer management infrastructure */
2710 static struct obd_ops mds_obd_ops = {
2711 .o_owner = THIS_MODULE,
2712 .o_connect = mds_connect,
2713 .o_reconnect = mds_reconnect,
2714 .o_init_export = mds_init_export,
2715 .o_destroy_export = mds_destroy_export,
2716 .o_disconnect = mds_disconnect,
2717 .o_setup = mds_setup,
2718 .o_precleanup = mds_precleanup,
2719 .o_cleanup = mds_cleanup,
2720 .o_postrecov = mds_postrecov,
2721 .o_statfs = mds_obd_statfs,
2722 .o_iocontrol = mds_iocontrol,
2723 .o_create = mds_obd_create,
2724 .o_destroy = mds_obd_destroy,
2725 .o_llog_init = mds_llog_init,
2726 .o_llog_finish = mds_llog_finish,
2727 .o_notify = mds_notify,
2728 .o_health_check = mds_health_check,
2729 .o_process_config = mds_process_config,
2732 static struct obd_ops mdt_obd_ops = {
2733 .o_owner = THIS_MODULE,
2734 .o_setup = mdt_setup,
2735 .o_cleanup = mdt_cleanup,
2736 .o_health_check = mdt_health_check,
2739 quota_interface_t *mds_quota_interface_ref;
2740 extern quota_interface_t mds_quota_interface;
2742 static __attribute__((unused)) int __init mds_init(void)
2745 struct lprocfs_static_vars lvars;
2747 request_module("lquota");
2748 mds_quota_interface_ref = PORTAL_SYMBOL_GET(mds_quota_interface);
2749 rc = lquota_init(mds_quota_interface_ref);
2751 if (mds_quota_interface_ref)
2752 PORTAL_SYMBOL_PUT(mds_quota_interface);
2755 init_obd_quota_ops(mds_quota_interface_ref, &mds_obd_ops);
2757 lprocfs_init_vars(mds, &lvars);
2758 class_register_type(&mds_obd_ops, NULL,
2759 lvars.module_vars, LUSTRE_MDS_NAME, NULL);
2760 lprocfs_init_vars(mdt, &lvars);
2761 mdt_obd_ops = mdt_obd_ops; //make compiler happy
2762 // class_register_type(&mdt_obd_ops, NULL,
2763 // lvars.module_vars, LUSTRE_MDT_NAME, NULL);
2768 static __attribute__((unused)) void /*__exit*/ mds_exit(void)
2770 lquota_exit(mds_quota_interface_ref);
2771 if (mds_quota_interface_ref)
2772 PORTAL_SYMBOL_PUT(mds_quota_interface);
2774 class_unregister_type(LUSTRE_MDS_NAME);
2775 // class_unregister_type(LUSTRE_MDT_NAME);
2777 /*mds still need lov setup here*/
2778 static int mds_cmd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
2780 struct mds_obd *mds = &obd->u.mds;
2781 struct lvfs_run_ctxt saved;
2783 struct vfsmount *mnt;
2784 struct lustre_sb_info *lsi;
2785 struct lustre_mount_info *lmi;
2786 struct dentry *dentry;
2791 CDEBUG(D_INFO, "obd %s setup \n", obd->obd_name);
2792 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2795 if (lcfg->lcfg_bufcount < 5) {
2796 CERROR("invalid arg for setup %s\n", MDD_OBD_NAME);
2799 dev = lustre_cfg_string(lcfg, 4);
2800 lmi = server_get_mount(dev);
2801 LASSERT(lmi != NULL);
2803 lsi = s2lsi(lmi->lmi_sb);
2805 /* FIXME: MDD LOV initialize objects.
2806 * we need only lmi here but not get mount
2807 * OSD did mount already, so put mount back
2809 atomic_dec(&lsi->lsi_mounts);
2812 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
2813 mds_init_ctxt(obd, mnt);
2815 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2816 dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
2817 if (IS_ERR(dentry)) {
2818 rc = PTR_ERR(dentry);
2819 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
2820 GOTO(err_putfs, rc);
2822 mds->mds_objects_dir = dentry;
2824 dentry = lookup_one_len("__iopen__", current->fs->pwd,
2825 strlen("__iopen__"));
2826 if (IS_ERR(dentry)) {
2827 rc = PTR_ERR(dentry);
2828 CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
2829 GOTO(err_objects, rc);
2832 mds->mds_fid_de = dentry;
2833 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
2835 CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
2839 /* open and test the lov objd file */
2840 file = filp_open(LOV_OBJID, O_RDWR | O_CREAT, 0644);
2843 CERROR("cannot open/create %s file: rc = %d\n", LOV_OBJID, rc);
2844 GOTO(err_fid, rc = PTR_ERR(file));
2846 mds->mds_lov_objid_filp = file;
2847 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
2848 CERROR("%s is not a regular file!: mode = %o\n", LOV_OBJID,
2849 file->f_dentry->d_inode->i_mode);
2850 GOTO(err_lov_objid, rc = -ENOENT);
2853 rc = mds_lov_presetup(mds, lcfg);
2855 GOTO(err_objects, rc);
2857 /* Don't wait for mds_postrecov trying to clear orphans */
2858 obd->obd_async_recov = 1;
2859 rc = mds_postsetup(obd);
2860 /* Bug 11557 - allow async abort_recov start
2861 FIXME can remove most of this obd_async_recov plumbing
2862 obd->obd_async_recov = 0;
2866 GOTO(err_objects, rc);
2868 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
2869 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
2872 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2875 if (mds->mds_lov_objid_filp &&
2876 filp_close((struct file *)mds->mds_lov_objid_filp, 0))
2877 CERROR("can't close %s after error\n", LOV_OBJID);
2879 dput(mds->mds_fid_de);
2881 dput(mds->mds_objects_dir);
2883 fsfilt_put_ops(obd->obd_fsops);
2887 static int mds_cmd_cleanup(struct obd_device *obd)
2889 struct mds_obd *mds = &obd->u.mds;
2890 struct lvfs_run_ctxt saved;
2895 LCONSOLE_WARN("%s: shutting down for failover; client state "
2896 "will be preserved.\n", obd->obd_name);
2898 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2899 if (mds->mds_lov_objid_filp) {
2900 rc = filp_close((struct file *)mds->mds_lov_objid_filp, 0);
2901 mds->mds_lov_objid_filp = NULL;
2903 CERROR("%s file won't close, rc=%d\n", LOV_OBJID, rc);
2905 if (mds->mds_objects_dir != NULL) {
2906 l_dput(mds->mds_objects_dir);
2907 mds->mds_objects_dir = NULL;
2910 if (mds->mds_lov_objids != NULL)
2911 OBD_FREE(mds->mds_lov_objids, mds->mds_lov_objids_size);
2913 shrink_dcache_parent(mds->mds_fid_de);
2914 dput(mds->mds_fid_de);
2915 LL_DQUOT_OFF(obd->u.obt.obt_sb);
2916 fsfilt_put_ops(obd->obd_fsops);
2918 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2923 static int mds_cmd_health_check(struct obd_device *obd)
2928 static struct obd_ops mds_cmd_obd_ops = {
2929 .o_owner = THIS_MODULE,
2930 .o_setup = mds_cmd_setup,
2931 .o_cleanup = mds_cmd_cleanup,
2932 .o_precleanup = mds_precleanup,
2933 .o_create = mds_obd_create,
2934 .o_destroy = mds_obd_destroy,
2935 .o_llog_init = mds_llog_init,
2936 .o_llog_finish = mds_llog_finish,
2937 .o_notify = mds_notify,
2938 .o_postrecov = mds_postrecov,
2939 // .o_health_check = mds_cmd_health_check,
2942 static int __init mds_cmd_init(void)
2944 struct lprocfs_static_vars lvars;
2946 lprocfs_init_vars(mds, &lvars);
2947 class_register_type(&mds_cmd_obd_ops, NULL, lvars.module_vars,
2948 LUSTRE_MDS_NAME, NULL);
2953 static void /*__exit*/ mds_cmd_exit(void)
2955 class_unregister_type(LUSTRE_MDS_NAME);
2958 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2959 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
2960 MODULE_LICENSE("GPL");
2962 module_init(mds_cmd_init);
2963 module_exit(mds_cmd_exit);