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 #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>
53 #include <linux/lustre_acl.h>
54 #include <obd_class.h>
55 #include <lustre_dlm.h>
57 #include <lustre_fsfilt.h>
58 #include <lprocfs_status.h>
59 #include <lustre_commit_confd.h>
60 #include <lustre_quota.h>
61 #include <lustre_disk.h>
62 #include <lustre_param.h>
63 #include <lustre_ver.h>
65 #include "mds_internal.h"
68 CFS_MODULE_PARM(mds_num_threads, "i", int, 0444,
69 "number of MDS service threads to start");
71 static int mds_intent_policy(struct ldlm_namespace *ns,
72 struct ldlm_lock **lockp, void *req_cookie,
73 ldlm_mode_t mode, int flags, void *data);
74 static int mds_postsetup(struct obd_device *obd);
75 static int mds_cleanup(struct obd_device *obd);
77 /* Assumes caller has already pushed into the kernel filesystem context */
78 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
79 loff_t offset, int count)
81 struct ptlrpc_bulk_desc *desc;
82 struct l_wait_info lwi;
84 int rc = 0, npages, i, tmpcount, tmpsize = 0;
87 LASSERT((offset & (PAGE_SIZE - 1)) == 0); /* I'm dubious about this */
89 npages = (count + PAGE_SIZE - 1) >> PAGE_SHIFT;
90 OBD_ALLOC(pages, sizeof(*pages) * npages);
92 GOTO(out, rc = -ENOMEM);
94 desc = ptlrpc_prep_bulk_exp(req, npages, BULK_PUT_SOURCE,
97 GOTO(out_free, rc = -ENOMEM);
99 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
100 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
102 pages[i] = alloc_pages(GFP_KERNEL, 0);
103 if (pages[i] == NULL)
104 GOTO(cleanup_buf, rc = -ENOMEM);
106 ptlrpc_prep_bulk_page(desc, pages[i], 0, tmpsize);
109 for (i = 0, tmpcount = count; i < npages; i++, tmpcount -= tmpsize) {
110 tmpsize = tmpcount > PAGE_SIZE ? PAGE_SIZE : tmpcount;
111 CDEBUG(D_EXT2, "reading %u@%llu from dir %lu (size %llu)\n",
112 tmpsize, offset, file->f_dentry->d_inode->i_ino,
113 file->f_dentry->d_inode->i_size);
115 rc = fsfilt_readpage(req->rq_export->exp_obd, file,
116 kmap(pages[i]), tmpsize, &offset);
120 GOTO(cleanup_buf, rc = -EIO);
123 LASSERT(desc->bd_nob == count);
125 rc = ptlrpc_start_bulk_transfer(desc);
127 GOTO(cleanup_buf, rc);
129 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
130 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
131 OBD_FAIL_MDS_SENDPAGE, rc);
132 GOTO(abort_bulk, rc);
135 lwi = LWI_TIMEOUT(obd_timeout * HZ / 4, NULL, NULL);
136 rc = l_wait_event(desc->bd_waitq, !ptlrpc_bulk_active(desc), &lwi);
137 LASSERT (rc == 0 || rc == -ETIMEDOUT);
140 if (desc->bd_success &&
141 desc->bd_nob_transferred == count)
142 GOTO(cleanup_buf, rc);
144 rc = -ETIMEDOUT; /* XXX should this be a different errno? */
147 DEBUG_REQ(D_ERROR, req, "bulk failed: %s %d(%d), evicting %s@%s\n",
148 (rc == -ETIMEDOUT) ? "timeout" : "network error",
149 desc->bd_nob_transferred, count,
150 req->rq_export->exp_client_uuid.uuid,
151 req->rq_export->exp_connection->c_remote_uuid.uuid);
153 class_fail_export(req->rq_export);
157 ptlrpc_abort_bulk (desc);
159 for (i = 0; i < npages; i++)
161 __free_pages(pages[i], 0);
163 ptlrpc_free_bulk(desc);
165 OBD_FREE(pages, sizeof(*pages) * npages);
170 /* only valid locked dentries or errors should be returned */
171 struct dentry *mds_fid2locked_dentry(struct obd_device *obd, struct ll_fid *fid,
172 struct vfsmount **mnt, int lock_mode,
173 struct lustre_handle *lockh,
176 struct mds_obd *mds = &obd->u.mds;
177 struct dentry *de = mds_fid2dentry(mds, fid, mnt), *retval = de;
178 struct ldlm_res_id res_id = { .name = {0} };
179 int flags = LDLM_FL_ATOMIC_CB, rc;
180 ldlm_policy_data_t policy = { .l_inodebits = { lockpart} };
186 res_id.name[0] = de->d_inode->i_ino;
187 res_id.name[1] = de->d_inode->i_generation;
188 rc = ldlm_cli_enqueue_local(obd->obd_namespace, res_id,
189 LDLM_IBITS, &policy, lock_mode, &flags,
190 ldlm_blocking_ast, ldlm_completion_ast,
191 NULL, NULL, 0, NULL, lockh);
192 if (rc != ELDLM_OK) {
194 retval = ERR_PTR(-EIO); /* XXX translate ldlm code */
200 /* Look up an entry by inode number. */
201 /* this function ONLY returns valid dget'd dentries with an initialized inode
203 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
204 struct vfsmount **mnt)
207 unsigned long ino = fid->id;
208 __u32 generation = fid->generation;
210 struct dentry *result;
213 RETURN(ERR_PTR(-ESTALE));
215 snprintf(fid_name, sizeof(fid_name), "0x%lx", ino);
217 CDEBUG(D_DENTRY, "--> mds_fid2dentry: ino/gen %lu/%u, sb %p\n",
218 ino, generation, mds->mds_obt.obt_sb);
220 /* under ext3 this is neither supposed to return bad inodes
222 result = ll_lookup_one_len(fid_name, mds->mds_fid_de, strlen(fid_name));
226 inode = result->d_inode;
228 RETURN(ERR_PTR(-ENOENT));
230 if (inode->i_generation == 0 || inode->i_nlink == 0) {
231 LCONSOLE_WARN("Found inode with zero generation or link -- this"
232 " may indicate disk corruption (inode: %lu/%u, "
233 "link %lu, count %d)\n", inode->i_ino,
234 inode->i_generation,(unsigned long)inode->i_nlink,
235 atomic_read(&inode->i_count));
237 RETURN(ERR_PTR(-ENOENT));
240 if (generation && inode->i_generation != generation) {
241 /* we didn't find the right inode.. */
242 CDEBUG(D_INODE, "found wrong generation: inode %lu, link: %lu, "
243 "count: %d, generation %u/%u\n", inode->i_ino,
244 (unsigned long)inode->i_nlink,
245 atomic_read(&inode->i_count), inode->i_generation,
248 RETURN(ERR_PTR(-ENOENT));
252 *mnt = mds->mds_vfsmnt;
259 static int mds_connect_internal(struct obd_export *exp,
260 struct obd_connect_data *data)
262 struct obd_device *obd = exp->exp_obd;
264 data->ocd_connect_flags &= MDT_CONNECT_SUPPORTED;
265 data->ocd_ibits_known &= MDS_INODELOCK_FULL;
267 /* If no known bits (which should not happen, probably,
268 as everybody should support LOOKUP and UPDATE bits at least)
269 revert to compat mode with plain locks. */
270 if (!data->ocd_ibits_known &&
271 data->ocd_connect_flags & OBD_CONNECT_IBITS)
272 data->ocd_connect_flags &= ~OBD_CONNECT_IBITS;
274 if (!obd->u.mds.mds_fl_acl)
275 data->ocd_connect_flags &= ~OBD_CONNECT_ACL;
277 if (!obd->u.mds.mds_fl_user_xattr)
278 data->ocd_connect_flags &= ~OBD_CONNECT_XATTR;
280 exp->exp_connect_flags = data->ocd_connect_flags;
281 data->ocd_version = LUSTRE_VERSION_CODE;
282 exp->exp_mds_data.med_ibits_known = data->ocd_ibits_known;
285 if (obd->u.mds.mds_fl_acl &&
286 ((exp->exp_connect_flags & OBD_CONNECT_ACL) == 0)) {
287 CWARN("%s: MDS requires ACL support but client does not\n",
294 static int mds_reconnect(struct obd_export *exp, struct obd_device *obd,
295 struct obd_uuid *cluuid,
296 struct obd_connect_data *data)
301 if (exp == NULL || obd == NULL || cluuid == NULL)
304 rc = mds_connect_internal(exp, data);
309 /* Establish a connection to the MDS.
311 * This will set up an export structure for the client to hold state data
312 * about that client, like open files, the last operation number it did
313 * on the server, etc.
315 static int mds_connect(const struct lu_env *env,
316 struct lustre_handle *conn, struct obd_device *obd,
317 struct obd_uuid *cluuid, struct obd_connect_data *data)
319 struct obd_export *exp;
320 struct mds_export_data *med;
321 struct mds_client_data *mcd = NULL;
322 int rc, abort_recovery;
325 if (!conn || !obd || !cluuid)
328 /* Check for aborted recovery. */
329 spin_lock_bh(&obd->obd_processing_task_lock);
330 abort_recovery = obd->obd_abort_recovery;
331 spin_unlock_bh(&obd->obd_processing_task_lock);
333 target_abort_recovery(obd);
335 /* XXX There is a small race between checking the list and adding a
336 * new connection for the same UUID, but the real threat (list
337 * corruption when multiple different clients connect) is solved.
339 * There is a second race between adding the export to the list,
340 * and filling in the client data below. Hence skipping the case
341 * of NULL mcd above. We should already be controlling multiple
342 * connects at the client, and we can't hold the spinlock over
343 * memory allocations without risk of deadlocking.
345 rc = class_connect(conn, obd, cluuid);
348 exp = class_conn2export(conn);
350 med = &exp->exp_mds_data;
352 rc = mds_connect_internal(exp, data);
356 OBD_ALLOC(mcd, sizeof(*mcd));
358 GOTO(out, rc = -ENOMEM);
360 memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
363 rc = mds_client_add(obd, &obd->u.mds, med, -1);
369 OBD_FREE(mcd, sizeof(*mcd));
372 class_disconnect(exp);
374 class_export_put(exp);
380 int mds_init_export(struct obd_export *exp)
382 struct mds_export_data *med = &exp->exp_mds_data;
384 INIT_LIST_HEAD(&med->med_open_head);
385 spin_lock_init(&med->med_open_lock);
386 exp->exp_connecting = 1;
390 static int mds_destroy_export(struct obd_export *export)
392 struct mds_export_data *med;
393 struct obd_device *obd = export->exp_obd;
394 struct lvfs_run_ctxt saved;
398 med = &export->exp_mds_data;
399 target_destroy_export(export);
401 if (obd_uuid_equals(&export->exp_client_uuid, &obd->obd_uuid))
404 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
405 /* Close any open files (which may also cause orphan unlinking). */
406 spin_lock(&med->med_open_lock);
407 while (!list_empty(&med->med_open_head)) {
408 struct list_head *tmp = med->med_open_head.next;
409 struct mds_file_data *mfd =
410 list_entry(tmp, struct mds_file_data, mfd_list);
411 struct dentry *dentry = mfd->mfd_dentry;
413 /* Remove mfd handle so it can't be found again.
414 * We are consuming the mfd_list reference here. */
415 mds_mfd_unlink(mfd, 0);
416 spin_unlock(&med->med_open_lock);
418 /* If you change this message, be sure to update
419 * replay_single:test_46 */
420 CDEBUG(D_INODE|D_IOCTL, "%s: force closing file handle for "
421 "%.*s (ino %lu)\n", obd->obd_name, dentry->d_name.len,
422 dentry->d_name.name, dentry->d_inode->i_ino);
423 /* child orphan sem protects orphan_dec_test and
424 * is_orphan race, mds_mfd_close drops it */
425 MDS_DOWN_WRITE_ORPHAN_SEM(dentry->d_inode);
426 rc = mds_mfd_close(NULL, REQ_REC_OFF, obd, mfd,
427 !(export->exp_flags & OBD_OPT_FAILOVER));
430 CDEBUG(D_INODE|D_IOCTL, "Error closing file: %d\n", rc);
431 spin_lock(&med->med_open_lock);
433 spin_unlock(&med->med_open_lock);
434 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
435 mds_client_free(export);
440 static int mds_disconnect(struct obd_export *exp)
446 class_export_get(exp);
448 /* Disconnect early so that clients can't keep using export */
449 rc = class_disconnect(exp);
450 if (exp->exp_obd->obd_namespace != NULL)
451 ldlm_cancel_locks_for_export(exp);
453 /* complete all outstanding replies */
454 spin_lock(&exp->exp_lock);
455 while (!list_empty(&exp->exp_outstanding_replies)) {
456 struct ptlrpc_reply_state *rs =
457 list_entry(exp->exp_outstanding_replies.next,
458 struct ptlrpc_reply_state, rs_exp_list);
459 struct ptlrpc_service *svc = rs->rs_service;
461 spin_lock(&svc->srv_lock);
462 list_del_init(&rs->rs_exp_list);
463 ptlrpc_schedule_difficult_reply(rs);
464 spin_unlock(&svc->srv_lock);
466 spin_unlock(&exp->exp_lock);
468 class_export_put(exp);
472 static int mds_getstatus(struct ptlrpc_request *req)
474 struct mds_obd *mds = mds_req2mds(req);
475 struct mds_body *body;
476 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
479 rc = lustre_pack_reply(req, 2, size, NULL);
480 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
481 CERROR("mds: out of memory for message\n");
482 req->rq_status = -ENOMEM; /* superfluous? */
486 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
487 memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
489 /* the last_committed and last_xid fields are filled in for all
490 * replies already - no need to do so here also.
495 /* get the LOV EA from @inode and store it into @md. It can be at most
496 * @size bytes, and @size is updated with the actual EA size.
497 * The EA size is also returned on success, and -ve errno on failure.
498 * If there is no EA then 0 is returned. */
499 int mds_get_md(struct obd_device *obd, struct inode *inode, void *md,
506 LOCK_INODE_MUTEX(inode);
507 rc = fsfilt_get_md(obd, inode, md, *size, "lov");
510 CERROR("Error %d reading eadata for ino %lu\n",
514 rc = mds_convert_lov_ea(obd, inode, md, lmm_size);
526 UNLOCK_INODE_MUTEX(inode);
532 /* Call with lock=1 if you want mds_pack_md to take the i_mutex.
533 * Call with lock=0 if the caller has already taken the i_mutex. */
534 int mds_pack_md(struct obd_device *obd, struct lustre_msg *msg, int offset,
535 struct mds_body *body, struct inode *inode, int lock)
537 struct mds_obd *mds = &obd->u.mds;
543 lmm = lustre_msg_buf(msg, offset, 0);
545 /* Some problem with getting eadata when I sized the reply
547 CDEBUG(D_INFO, "no space reserved for inode %lu MD\n",
551 lmm_size = lustre_msg_buflen(msg, offset);
553 /* I don't really like this, but it is a sanity check on the client
554 * MD request. However, if the client doesn't know how much space
555 * to reserve for the MD, it shouldn't be bad to have too much space.
557 if (lmm_size > mds->mds_max_mdsize) {
558 CWARN("Reading MD for inode %lu of %d bytes > max %d\n",
559 inode->i_ino, lmm_size, mds->mds_max_mdsize);
563 rc = mds_get_md(obd, inode, lmm, &lmm_size, lock);
565 if (S_ISDIR(inode->i_mode))
566 body->valid |= OBD_MD_FLDIREA;
568 body->valid |= OBD_MD_FLEASIZE;
569 body->eadatasize = lmm_size;
576 #ifdef CONFIG_FS_POSIX_ACL
578 int mds_pack_posix_acl(struct inode *inode, struct lustre_msg *repmsg,
579 struct mds_body *repbody, int repoff)
581 struct dentry de = { .d_inode = inode };
585 LASSERT(repbody->aclsize == 0);
586 LASSERT(lustre_msg_bufcount(repmsg) > repoff);
588 buflen = lustre_msg_buflen(repmsg, repoff);
592 if (!inode->i_op || !inode->i_op->getxattr)
596 rc = inode->i_op->getxattr(&de, MDS_XATTR_NAME_ACL_ACCESS,
597 lustre_msg_buf(repmsg, repoff, buflen),
602 repbody->aclsize = rc;
603 else if (rc != -ENODATA) {
604 CERROR("buflen %d, get acl: %d\n", buflen, rc);
609 repbody->valid |= OBD_MD_FLACL;
613 #define mds_pack_posix_acl(inode, repmsg, repbody, repoff) 0
616 int mds_pack_acl(struct mds_export_data *med, struct inode *inode,
617 struct lustre_msg *repmsg, struct mds_body *repbody,
620 return mds_pack_posix_acl(inode, repmsg, repbody, repoff);
623 static int mds_getattr_internal(struct obd_device *obd, struct dentry *dentry,
624 struct ptlrpc_request *req,
625 struct mds_body *reqbody, int reply_off)
627 struct mds_body *body;
628 struct inode *inode = dentry->d_inode;
635 body = lustre_msg_buf(req->rq_repmsg, reply_off, sizeof(*body));
636 LASSERT(body != NULL); /* caller prepped reply */
638 mds_pack_inode2fid(&body->fid1, inode);
639 body->flags = reqbody->flags; /* copy MDS_BFLAG_EXT_FLAGS if present */
640 mds_pack_inode2body(body, inode);
643 if ((S_ISREG(inode->i_mode) && (reqbody->valid & OBD_MD_FLEASIZE)) ||
644 (S_ISDIR(inode->i_mode) && (reqbody->valid & OBD_MD_FLDIREA))) {
645 rc = mds_pack_md(obd, req->rq_repmsg, reply_off, body,
648 /* If we have LOV EA data, the OST holds size, atime, mtime */
649 if (!(body->valid & OBD_MD_FLEASIZE) &&
650 !(body->valid & OBD_MD_FLDIREA))
651 body->valid |= (OBD_MD_FLSIZE | OBD_MD_FLBLOCKS |
652 OBD_MD_FLATIME | OBD_MD_FLMTIME);
654 lustre_shrink_reply(req, reply_off, body->eadatasize, 0);
655 if (body->eadatasize)
657 } else if (S_ISLNK(inode->i_mode) &&
658 (reqbody->valid & OBD_MD_LINKNAME) != 0) {
659 char *symname = lustre_msg_buf(req->rq_repmsg, reply_off, 0);
662 LASSERT (symname != NULL); /* caller prepped reply */
663 len = lustre_msg_buflen(req->rq_repmsg, reply_off);
665 rc = inode->i_op->readlink(dentry, symname, len);
667 CERROR("readlink failed: %d\n", rc);
668 } else if (rc != len - 1) {
669 CERROR ("Unexpected readlink rc %d: expecting %d\n",
673 CDEBUG(D_INODE, "read symlink dest %s\n", symname);
674 body->valid |= OBD_MD_LINKNAME;
675 body->eadatasize = rc + 1;
676 symname[rc] = 0; /* NULL terminate */
680 } else if (reqbody->valid == OBD_MD_FLFLAGS &&
681 reqbody->flags & MDS_BFLAG_EXT_FLAGS) {
684 /* We only return the full set of flags on ioctl, otherwise we
685 * get enough flags from the inode in mds_pack_inode2body(). */
686 rc = fsfilt_iocontrol(obd, inode, NULL, EXT3_IOC_GETFLAGS,
689 body->flags = flags | MDS_BFLAG_EXT_FLAGS;
692 if (reqbody->valid & OBD_MD_FLMODEASIZE) {
693 struct mds_obd *mds = mds_req2mds(req);
694 body->max_cookiesize = mds->mds_max_cookiesize;
695 body->max_mdsize = mds->mds_max_mdsize;
696 body->valid |= OBD_MD_FLMODEASIZE;
702 #ifdef CONFIG_FS_POSIX_ACL
703 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
704 (reqbody->valid & OBD_MD_FLACL)) {
705 rc = mds_pack_acl(&req->rq_export->exp_mds_data,
706 inode, req->rq_repmsg,
709 lustre_shrink_reply(req, reply_off, body->aclsize, 0);
718 static int mds_getattr_pack_msg(struct ptlrpc_request *req, struct inode *inode,
721 struct mds_obd *mds = mds_req2mds(req);
722 struct mds_body *body;
723 int rc, bufcount = 2;
724 int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) };
727 LASSERT(offset == REQ_REC_OFF); /* non-intent */
729 body = lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*body));
730 LASSERT(body != NULL); /* checked by caller */
731 LASSERT_REQSWABBED(req, offset); /* swabbed by caller */
733 if ((S_ISREG(inode->i_mode) && (body->valid & OBD_MD_FLEASIZE)) ||
734 (S_ISDIR(inode->i_mode) && (body->valid & OBD_MD_FLDIREA))) {
735 LOCK_INODE_MUTEX(inode);
736 rc = fsfilt_get_md(req->rq_export->exp_obd, inode, NULL, 0,
738 UNLOCK_INODE_MUTEX(inode);
739 CDEBUG(D_INODE, "got %d bytes MD data for inode %lu\n",
742 if (rc != -ENODATA) {
743 CERROR("error getting inode %lu MD: rc = %d\n",
748 } else if (rc > mds->mds_max_mdsize) {
750 CERROR("MD size %d larger than maximum possible %u\n",
751 rc, mds->mds_max_mdsize);
756 } else if (S_ISLNK(inode->i_mode) && (body->valid & OBD_MD_LINKNAME)) {
757 if (inode->i_size + 1 != body->eadatasize)
758 CERROR("symlink size: %Lu, reply space: %d\n",
759 inode->i_size + 1, body->eadatasize);
760 size[bufcount] = min_t(int, inode->i_size+1, body->eadatasize);
762 CDEBUG(D_INODE, "symlink size: %Lu, reply space: %d\n",
763 inode->i_size + 1, body->eadatasize);
766 #ifdef CONFIG_FS_POSIX_ACL
767 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
768 (body->valid & OBD_MD_FLACL)) {
769 struct dentry de = { .d_inode = inode };
772 if (inode->i_op && inode->i_op->getxattr) {
774 rc = inode->i_op->getxattr(&de, MDS_XATTR_NAME_ACL_ACCESS,
779 if (rc != -ENODATA) {
780 CERROR("got acl size: %d\n", rc);
790 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
791 CERROR("failed MDS_GETATTR_PACK test\n");
792 req->rq_status = -ENOMEM;
796 rc = lustre_pack_reply(req, bufcount, size, NULL);
798 CERROR("lustre_pack_reply failed: rc %d\n", rc);
806 static int mds_getattr_lock(struct ptlrpc_request *req, int offset,
807 int child_part, struct lustre_handle *child_lockh)
809 struct obd_device *obd = req->rq_export->exp_obd;
810 struct mds_obd *mds = &obd->u.mds;
811 struct ldlm_reply *rep = NULL;
812 struct lvfs_run_ctxt saved;
813 struct mds_body *body;
814 struct dentry *dparent = NULL, *dchild = NULL;
815 struct lvfs_ucred uc = {0,};
816 struct lustre_handle parent_lockh;
818 int rc = 0, cleanup_phase = 0, resent_req = 0;
822 LASSERT(!strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME));
824 /* Swab now, before anyone looks inside the request */
825 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
826 lustre_swab_mds_body);
828 CERROR("Can't swab mds_body\n");
832 LASSERT_REQSWAB(req, offset + 1);
833 name = lustre_msg_string(req->rq_reqmsg, offset + 1, 0);
835 CERROR("Can't unpack name\n");
838 namesize = lustre_msg_buflen(req->rq_reqmsg, offset + 1);
839 /* namesize less than 2 means we have empty name, probably came from
840 revalidate by cfid, so no point in having name to be set */
844 rc = mds_init_ucred(&uc, req, offset);
848 LASSERT(offset == REQ_REC_OFF || offset == DLM_INTENT_REC_OFF);
849 /* if requests were at offset 2, the getattr reply goes back at 1 */
850 if (offset == DLM_INTENT_REC_OFF) {
851 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF,
853 offset = DLM_REPLY_REC_OFF;
856 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
857 cleanup_phase = 1; /* kernel context */
858 intent_set_disposition(rep, DISP_LOOKUP_EXECD);
860 /* FIXME: handle raw lookup */
862 if (body->valid == OBD_MD_FLID) {
863 struct mds_body *mds_reply;
864 int size = sizeof(*mds_reply);
866 // The user requested ONLY the inode number, so do a raw lookup
867 rc = lustre_pack_reply(req, 1, &size, NULL);
869 CERROR("out of memory\n");
873 rc = dir->i_op->lookup_raw(dir, name, namesize - 1, &inum);
875 mds_reply = lustre_msg_buf(req->rq_repmsg, offset,
877 mds_reply->fid1.id = inum;
878 mds_reply->valid = OBD_MD_FLID;
883 if (lustre_handle_is_used(child_lockh)) {
884 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT);
888 if (resent_req == 0) {
890 rc = mds_get_parent_child_locked(obd, &obd->u.mds,
894 MDS_INODELOCK_UPDATE,
896 child_lockh, &dchild,
899 /* For revalidate by fid we always take UPDATE lock */
900 dchild = mds_fid2locked_dentry(obd, &body->fid2, NULL,
905 rc = PTR_ERR(dchild);
910 struct ldlm_lock *granted_lock;
911 struct ll_fid child_fid;
912 struct ldlm_resource *res;
913 DEBUG_REQ(D_DLMTRACE, req, "resent, not enqueuing new locks");
914 granted_lock = ldlm_handle2lock(child_lockh);
915 LASSERTF(granted_lock != NULL, LPU64"/%u lockh "LPX64"\n",
916 body->fid1.id, body->fid1.generation,
917 child_lockh->cookie);
920 res = granted_lock->l_resource;
921 child_fid.id = res->lr_name.name[0];
922 child_fid.generation = res->lr_name.name[1];
923 dchild = mds_fid2dentry(&obd->u.mds, &child_fid, NULL);
924 LASSERT(!IS_ERR(dchild));
925 LDLM_LOCK_PUT(granted_lock);
928 cleanup_phase = 2; /* dchild, dparent, locks */
930 if (dchild->d_inode == NULL) {
931 intent_set_disposition(rep, DISP_LOOKUP_NEG);
932 /* in the intent case, the policy clears this error:
933 the disposition is enough */
934 GOTO(cleanup, rc = -ENOENT);
936 intent_set_disposition(rep, DISP_LOOKUP_POS);
939 if (req->rq_repmsg == NULL) {
940 rc = mds_getattr_pack_msg(req, dchild->d_inode, offset);
942 CERROR ("mds_getattr_pack_msg: %d\n", rc);
947 rc = mds_getattr_internal(obd, dchild, req, body, offset);
948 GOTO(cleanup, rc); /* returns the lock to the client */
951 switch (cleanup_phase) {
953 if (resent_req == 0) {
954 if (rc && dchild->d_inode)
955 ldlm_lock_decref(child_lockh, LCK_CR);
957 ldlm_lock_decref(&parent_lockh, LCK_CR);
963 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
965 mds_exit_ucred(&uc, mds);
966 if (req->rq_reply_state == NULL) {
968 lustre_pack_reply(req, 1, NULL, NULL);
974 static int mds_getattr(struct ptlrpc_request *req, int offset)
976 struct mds_obd *mds = mds_req2mds(req);
977 struct obd_device *obd = req->rq_export->exp_obd;
978 struct lvfs_run_ctxt saved;
980 struct mds_body *body;
981 struct lvfs_ucred uc = {0,};
985 OBD_COUNTER_INCREMENT(obd, getattr);
987 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
988 lustre_swab_mds_body);
992 rc = mds_init_ucred(&uc, req, offset);
996 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
997 de = mds_fid2dentry(mds, &body->fid1, NULL);
999 rc = req->rq_status = PTR_ERR(de);
1003 rc = mds_getattr_pack_msg(req, de->d_inode, offset);
1005 CERROR("mds_getattr_pack_msg: %d\n", rc);
1009 req->rq_status = mds_getattr_internal(obd, de, req, body,
1015 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1017 if (req->rq_reply_state == NULL) {
1018 req->rq_status = rc;
1019 lustre_pack_reply(req, 1, NULL, NULL);
1021 mds_exit_ucred(&uc, mds);
1025 static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1030 spin_lock(&obd->obd_osfs_lock);
1031 rc = fsfilt_statfs(obd, obd->u.obt.obt_sb, max_age);
1033 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1034 spin_unlock(&obd->obd_osfs_lock);
1039 static int mds_statfs(struct ptlrpc_request *req)
1041 struct obd_device *obd = req->rq_export->exp_obd;
1042 int rc, size[2] = { sizeof(struct ptlrpc_body),
1043 sizeof(struct obd_statfs) };
1046 /* This will trigger a watchdog timeout */
1047 OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,
1048 (MDS_SERVICE_WATCHDOG_TIMEOUT / 1000) + 1);
1049 OBD_COUNTER_INCREMENT(obd, statfs);
1051 rc = lustre_pack_reply(req, 2, size, NULL);
1052 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
1053 CERROR("mds: statfs lustre_pack_reply failed: rc = %d\n", rc);
1057 /* We call this so that we can cache a bit - 1 jiffie worth */
1058 rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1059 size[REPLY_REC_OFF]),
1060 cfs_time_current_64() - HZ);
1062 CERROR("mds_obd_statfs failed: rc %d\n", rc);
1068 req->rq_status = rc;
1072 static int mds_sync(struct ptlrpc_request *req, int offset)
1074 struct obd_device *obd = req->rq_export->exp_obd;
1075 struct mds_obd *mds = &obd->u.mds;
1076 struct mds_body *body;
1077 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
1080 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1081 lustre_swab_mds_body);
1083 GOTO(out, rc = -EFAULT);
1085 rc = lustre_pack_reply(req, 2, size, NULL);
1086 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK)) {
1087 CERROR("fsync lustre_pack_reply failed: rc = %d\n", rc);
1091 if (body->fid1.id == 0) {
1092 /* a fid of zero is taken to mean "sync whole filesystem" */
1093 rc = fsfilt_sync(obd, obd->u.obt.obt_sb);
1098 de = mds_fid2dentry(mds, &body->fid1, NULL);
1100 GOTO(out, rc = PTR_ERR(de));
1102 /* The file parameter isn't used for anything */
1103 if (de->d_inode->i_fop && de->d_inode->i_fop->fsync)
1104 rc = de->d_inode->i_fop->fsync(NULL, de, 1);
1106 body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1108 mds_pack_inode2fid(&body->fid1, de->d_inode);
1109 mds_pack_inode2body(body, de->d_inode);
1116 req->rq_status = rc;
1120 /* mds_readpage does not take a DLM lock on the inode, because the client must
1121 * already have a PR lock.
1123 * If we were to take another one here, a deadlock will result, if another
1124 * thread is already waiting for a PW lock. */
1125 static int mds_readpage(struct ptlrpc_request *req, int offset)
1127 struct obd_device *obd = req->rq_export->exp_obd;
1128 struct mds_obd *mds = &obd->u.mds;
1129 struct vfsmount *mnt;
1132 struct mds_body *body, *repbody;
1133 struct lvfs_run_ctxt saved;
1134 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };
1135 struct lvfs_ucred uc = {0,};
1138 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK))
1141 rc = lustre_pack_reply(req, 2, size, NULL);
1143 CERROR("error packing readpage reply: rc %d\n", rc);
1147 body = lustre_swab_reqbuf(req, offset, sizeof(*body),
1148 lustre_swab_mds_body);
1150 GOTO (out, rc = -EFAULT);
1152 rc = mds_init_ucred(&uc, req, offset);
1156 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1157 de = mds_fid2dentry(&obd->u.mds, &body->fid1, &mnt);
1159 GOTO(out_pop, rc = PTR_ERR(de));
1161 CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);
1163 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
1164 /* note: in case of an error, dentry_open puts dentry */
1166 GOTO(out_pop, rc = PTR_ERR(file));
1168 /* body->size is actually the offset -eeb */
1169 if ((body->size & (de->d_inode->i_blksize - 1)) != 0) {
1170 CERROR("offset "LPU64" not on a block boundary of %lu\n",
1171 body->size, de->d_inode->i_blksize);
1172 GOTO(out_file, rc = -EFAULT);
1175 /* body->nlink is actually the #bytes to read -eeb */
1176 if (body->nlink & (de->d_inode->i_blksize - 1)) {
1177 CERROR("size %u is not multiple of blocksize %lu\n",
1178 body->nlink, de->d_inode->i_blksize);
1179 GOTO(out_file, rc = -EFAULT);
1182 repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
1184 repbody->size = file->f_dentry->d_inode->i_size;
1185 repbody->valid = OBD_MD_FLSIZE;
1187 /* to make this asynchronous make sure that the handling function
1188 doesn't send a reply when this function completes. Instead a
1189 callback function would send the reply */
1190 /* body->size is actually the offset -eeb */
1191 rc = mds_sendpage(req, file, body->size, body->nlink);
1194 filp_close(file, 0);
1196 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
1198 mds_exit_ucred(&uc, mds);
1199 req->rq_status = rc;
1203 int mds_reint(struct ptlrpc_request *req, int offset,
1204 struct lustre_handle *lockh)
1206 struct mds_update_record *rec; /* 116 bytes on the stack? no sir! */
1209 OBD_ALLOC(rec, sizeof(*rec));
1213 rc = mds_update_unpack(req, offset, rec);
1214 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
1215 CERROR("invalid record\n");
1216 GOTO(out, req->rq_status = -EINVAL);
1219 /* rc will be used to interrupt a for loop over multiple records */
1220 rc = mds_reint_rec(rec, offset, req, lockh);
1222 OBD_FREE(rec, sizeof(*rec));
1226 int mds_filter_recovery_request(struct ptlrpc_request *req,
1227 struct obd_device *obd, int *process)
1229 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1230 case MDS_CONNECT: /* This will never get here, but for completeness. */
1231 case OST_CONNECT: /* This will never get here, but for completeness. */
1232 case MDS_DISCONNECT:
1233 case OST_DISCONNECT:
1238 case MDS_SYNC: /* used in unmounting */
1244 *process = target_queue_recovery_request(req, obd);
1248 DEBUG_REQ(D_ERROR, req, "not permitted during recovery");
1250 /* XXX what should we set rq_status to here? */
1251 req->rq_status = -EAGAIN;
1252 RETURN(ptlrpc_error(req));
1255 EXPORT_SYMBOL(mds_filter_recovery_request);
1257 static char *reint_names[] = {
1258 [REINT_SETATTR] "setattr",
1259 [REINT_CREATE] "create",
1260 [REINT_LINK] "link",
1261 [REINT_UNLINK] "unlink",
1262 [REINT_RENAME] "rename",
1263 [REINT_OPEN] "open",
1266 static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req)
1273 key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);
1275 DEBUG_REQ(D_HA, req, "no set_info key");
1278 keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);
1280 val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, sizeof(*val));
1282 DEBUG_REQ(D_HA, req, "no set_info val");
1286 rc = lustre_pack_reply(req, 1, NULL, NULL);
1289 lustre_msg_set_status(req->rq_repmsg, 0);
1291 if (keylen < strlen("read-only") ||
1292 memcmp(key, "read-only", keylen) != 0)
1296 exp->exp_connect_flags |= OBD_CONNECT_RDONLY;
1298 exp->exp_connect_flags &= ~OBD_CONNECT_RDONLY;
1303 static int mds_handle_quotacheck(struct ptlrpc_request *req)
1305 struct obd_quotactl *oqctl;
1309 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1310 lustre_swab_obd_quotactl);
1314 rc = lustre_pack_reply(req, 1, NULL, NULL);
1316 CERROR("mds: out of memory while packing quotacheck reply\n");
1320 req->rq_status = obd_quotacheck(req->rq_export, oqctl);
1324 static int mds_handle_quotactl(struct ptlrpc_request *req)
1326 struct obd_quotactl *oqctl, *repoqc;
1327 int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };
1330 oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),
1331 lustre_swab_obd_quotactl);
1335 rc = lustre_pack_reply(req, 2, size, NULL);
1339 repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));
1341 req->rq_status = obd_quotactl(req->rq_export, oqctl);
1346 int mds_msg_check_version(struct lustre_msg *msg)
1350 switch (lustre_msg_get_opc(msg)) {
1352 case MDS_DISCONNECT:
1355 case SEC_CTX_INIT_CONT:
1357 rc = lustre_msg_check_version(msg, LUSTRE_OBD_VERSION);
1359 CERROR("bad opc %u version %08x, expecting %08x\n",
1360 lustre_msg_get_opc(msg),
1361 lustre_msg_get_version(msg),
1362 LUSTRE_OBD_VERSION);
1366 case MDS_GETATTR_NAME:
1373 case MDS_DONE_WRITING:
1379 case MDS_QUOTACHECK:
1385 rc = lustre_msg_check_version(msg, LUSTRE_MDS_VERSION);
1387 CERROR("bad opc %u version %08x, expecting %08x\n",
1388 lustre_msg_get_opc(msg),
1389 lustre_msg_get_version(msg),
1390 LUSTRE_MDS_VERSION);
1394 case LDLM_BL_CALLBACK:
1395 case LDLM_CP_CALLBACK:
1396 rc = lustre_msg_check_version(msg, LUSTRE_DLM_VERSION);
1398 CERROR("bad opc %u version %08x, expecting %08x\n",
1399 lustre_msg_get_opc(msg),
1400 lustre_msg_get_version(msg),
1401 LUSTRE_DLM_VERSION);
1403 case OBD_LOG_CANCEL:
1404 case LLOG_ORIGIN_HANDLE_CREATE:
1405 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1406 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1407 case LLOG_ORIGIN_HANDLE_CLOSE:
1408 case LLOG_ORIGIN_HANDLE_DESTROY:
1409 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1411 rc = lustre_msg_check_version(msg, LUSTRE_LOG_VERSION);
1413 CERROR("bad opc %u version %08x, expecting %08x\n",
1414 lustre_msg_get_opc(msg),
1415 lustre_msg_get_version(msg),
1416 LUSTRE_LOG_VERSION);
1419 CERROR("MDS unknown opcode %d\n", lustre_msg_get_opc(msg));
1424 EXPORT_SYMBOL(mds_msg_check_version);
1426 int mds_handle(struct ptlrpc_request *req)
1428 int should_process, fail = OBD_FAIL_MDS_ALL_REPLY_NET;
1430 struct mds_obd *mds = NULL; /* quell gcc overwarning */
1431 struct obd_device *obd = NULL;
1434 OBD_FAIL_RETURN(OBD_FAIL_MDS_ALL_REQUEST_NET | OBD_FAIL_ONCE, 0);
1436 LASSERT(current->journal_info == NULL);
1438 rc = mds_msg_check_version(req->rq_reqmsg);
1440 CERROR("MDS drop mal-formed request\n");
1444 /* XXX identical to OST */
1445 if (lustre_msg_get_opc(req->rq_reqmsg) != MDS_CONNECT) {
1446 struct mds_export_data *med;
1447 int recovering, abort_recovery;
1449 if (req->rq_export == NULL) {
1450 CERROR("operation %d on unconnected MDS from %s\n",
1451 lustre_msg_get_opc(req->rq_reqmsg),
1452 libcfs_id2str(req->rq_peer));
1453 req->rq_status = -ENOTCONN;
1454 GOTO(out, rc = -ENOTCONN);
1457 med = &req->rq_export->exp_mds_data;
1458 obd = req->rq_export->exp_obd;
1459 mds = mds_req2mds(req);
1461 /* sanity check: if the xid matches, the request must
1462 * be marked as a resent or replayed */
1463 if (req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_xid) ||
1464 req->rq_xid == le64_to_cpu(med->med_mcd->mcd_last_close_xid))
1465 if (!(lustre_msg_get_flags(req->rq_reqmsg) &
1466 (MSG_RESENT | MSG_REPLAY))) {
1467 CERROR("rq_xid "LPU64" matches last_xid, "
1468 "expected RESENT flag\n",
1470 req->rq_status = -ENOTCONN;
1471 GOTO(out, rc = -EFAULT);
1473 /* else: note the opposite is not always true; a
1474 * RESENT req after a failover will usually not match
1475 * the last_xid, since it was likely never
1476 * committed. A REPLAYed request will almost never
1477 * match the last xid, however it could for a
1478 * committed, but still retained, open. */
1480 /* Check for aborted recovery. */
1481 spin_lock_bh(&obd->obd_processing_task_lock);
1482 abort_recovery = obd->obd_abort_recovery;
1483 recovering = obd->obd_recovering;
1484 spin_unlock_bh(&obd->obd_processing_task_lock);
1485 if (abort_recovery) {
1486 target_abort_recovery(obd);
1487 } else if (recovering) {
1488 rc = mds_filter_recovery_request(req, obd,
1490 if (rc || !should_process)
1495 switch (lustre_msg_get_opc(req->rq_reqmsg)) {
1497 DEBUG_REQ(D_INODE, req, "connect");
1498 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
1499 rc = target_handle_connect(req, mds_handle);
1501 /* Now that we have an export, set mds. */
1503 * XXX nikita: these assignments are useless: mds is
1504 * never used below, and obd is only used for
1505 * MSG_LAST_REPLAY case, which never happens for
1508 obd = req->rq_export->exp_obd;
1509 mds = mds_req2mds(req);
1513 case MDS_DISCONNECT:
1514 DEBUG_REQ(D_INODE, req, "disconnect");
1515 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
1516 rc = target_handle_disconnect(req);
1517 req->rq_status = rc; /* superfluous? */
1521 DEBUG_REQ(D_INODE, req, "getstatus");
1522 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
1523 rc = mds_getstatus(req);
1527 DEBUG_REQ(D_INODE, req, "getattr");
1528 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
1529 rc = mds_getattr(req, REQ_REC_OFF);
1533 DEBUG_REQ(D_INODE, req, "setxattr");
1534 OBD_FAIL_RETURN(OBD_FAIL_MDS_SETXATTR_NET, 0);
1535 rc = mds_setxattr(req);
1539 DEBUG_REQ(D_INODE, req, "getxattr");
1540 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETXATTR_NET, 0);
1541 rc = mds_getxattr(req);
1544 case MDS_GETATTR_NAME: {
1545 struct lustre_handle lockh = { 0 };
1546 DEBUG_REQ(D_INODE, req, "getattr_name");
1547 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NAME_NET, 0);
1549 /* If this request gets a reconstructed reply, we won't be
1550 * acquiring any new locks in mds_getattr_lock, so we don't
1553 rc = mds_getattr_lock(req, REQ_REC_OFF, MDS_INODELOCK_UPDATE,
1555 /* this non-intent call (from an ioctl) is special */
1556 req->rq_status = rc;
1557 if (rc == 0 && lustre_handle_is_used(&lockh))
1558 ldlm_lock_decref(&lockh, LCK_CR);
1562 DEBUG_REQ(D_INODE, req, "statfs");
1563 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
1564 rc = mds_statfs(req);
1568 DEBUG_REQ(D_INODE, req, "readpage");
1569 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
1570 rc = mds_readpage(req, REQ_REC_OFF);
1572 if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_SENDPAGE)) {
1579 __u32 *opcp = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
1582 int size[4] = { sizeof(struct ptlrpc_body),
1583 sizeof(struct mds_body),
1584 mds->mds_max_mdsize,
1585 mds->mds_max_cookiesize };
1588 /* NB only peek inside req now; mds_reint() will swab it */
1590 CERROR ("Can't inspect opcode\n");
1595 if (lustre_msg_swabbed(req->rq_reqmsg))
1598 DEBUG_REQ(D_INODE, req, "reint %d (%s)", opc,
1599 (opc < sizeof(reint_names) / sizeof(reint_names[0]) ||
1600 reint_names[opc] == NULL) ? reint_names[opc] :
1603 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
1605 if (opc == REINT_UNLINK || opc == REINT_RENAME)
1607 else if (opc == REINT_OPEN)
1612 rc = lustre_pack_reply(req, bufcount, size, NULL);
1616 rc = mds_reint(req, REQ_REC_OFF, NULL);
1617 fail = OBD_FAIL_MDS_REINT_NET_REP;
1622 DEBUG_REQ(D_INODE, req, "close");
1623 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
1624 rc = mds_close(req, REQ_REC_OFF);
1627 case MDS_DONE_WRITING:
1628 DEBUG_REQ(D_INODE, req, "done_writing");
1629 OBD_FAIL_RETURN(OBD_FAIL_MDS_DONE_WRITING_NET, 0);
1630 rc = mds_done_writing(req, REQ_REC_OFF);
1634 DEBUG_REQ(D_INODE, req, "pin");
1635 OBD_FAIL_RETURN(OBD_FAIL_MDS_PIN_NET, 0);
1636 rc = mds_pin(req, REQ_REC_OFF);
1640 DEBUG_REQ(D_INODE, req, "sync");
1641 OBD_FAIL_RETURN(OBD_FAIL_MDS_SYNC_NET, 0);
1642 rc = mds_sync(req, REQ_REC_OFF);
1646 DEBUG_REQ(D_INODE, req, "set_info");
1647 rc = mds_set_info_rpc(req->rq_export, req);
1650 case MDS_QUOTACHECK:
1651 DEBUG_REQ(D_INODE, req, "quotacheck");
1652 OBD_FAIL_RETURN(OBD_FAIL_MDS_QUOTACHECK_NET, 0);
1653 rc = mds_handle_quotacheck(req);
1657 DEBUG_REQ(D_INODE, req, "quotactl");
1658 OBD_FAIL_RETURN(OBD_FAIL_MDS_QUOTACTL_NET, 0);
1659 rc = mds_handle_quotactl(req);
1663 DEBUG_REQ(D_INODE, req, "ping");
1664 rc = target_handle_ping(req);
1667 case OBD_LOG_CANCEL:
1668 CDEBUG(D_INODE, "log cancel\n");
1669 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOG_CANCEL_NET, 0);
1670 rc = -ENOTSUPP; /* la la la */
1674 DEBUG_REQ(D_INODE, req, "enqueue");
1675 OBD_FAIL_RETURN(OBD_FAIL_LDLM_ENQUEUE, 0);
1676 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
1677 ldlm_server_blocking_ast, NULL);
1678 fail = OBD_FAIL_LDLM_REPLY;
1681 DEBUG_REQ(D_INODE, req, "convert");
1682 OBD_FAIL_RETURN(OBD_FAIL_LDLM_CONVERT, 0);
1683 rc = ldlm_handle_convert(req);
1685 case LDLM_BL_CALLBACK:
1686 case LDLM_CP_CALLBACK:
1687 DEBUG_REQ(D_INODE, req, "callback");
1688 CERROR("callbacks should not happen on MDS\n");
1690 OBD_FAIL_RETURN(OBD_FAIL_LDLM_BL_CALLBACK, 0);
1692 case LLOG_ORIGIN_HANDLE_CREATE:
1693 DEBUG_REQ(D_INODE, req, "llog_init");
1694 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1695 rc = llog_origin_handle_create(req);
1697 case LLOG_ORIGIN_HANDLE_DESTROY:
1698 DEBUG_REQ(D_INODE, req, "llog_init");
1699 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1700 rc = llog_origin_handle_destroy(req);
1702 case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
1703 DEBUG_REQ(D_INODE, req, "llog next block");
1704 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1705 rc = llog_origin_handle_next_block(req);
1707 case LLOG_ORIGIN_HANDLE_PREV_BLOCK:
1708 DEBUG_REQ(D_INODE, req, "llog prev block");
1709 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1710 rc = llog_origin_handle_prev_block(req);
1712 case LLOG_ORIGIN_HANDLE_READ_HEADER:
1713 DEBUG_REQ(D_INODE, req, "llog read header");
1714 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1715 rc = llog_origin_handle_read_header(req);
1717 case LLOG_ORIGIN_HANDLE_CLOSE:
1718 DEBUG_REQ(D_INODE, req, "llog close");
1719 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1720 rc = llog_origin_handle_close(req);
1723 DEBUG_REQ(D_INODE, req, "llog catinfo");
1724 OBD_FAIL_RETURN(OBD_FAIL_OBD_LOGD_NET, 0);
1725 rc = llog_catinfo(req);
1728 req->rq_status = -ENOTSUPP;
1729 rc = ptlrpc_error(req);
1733 LASSERT(current->journal_info == NULL);
1735 /* If we're DISCONNECTing, the mds_export_data is already freed */
1736 if (!rc && lustre_msg_get_opc(req->rq_reqmsg) != MDS_DISCONNECT) {
1737 struct mds_export_data *med = &req->rq_export->exp_mds_data;
1739 /* I don't think last_xid is used for anyway, so I'm not sure
1740 if we need to care about last_close_xid here.*/
1741 lustre_msg_set_last_xid(req->rq_repmsg,
1742 le64_to_cpu(med->med_mcd->mcd_last_xid));
1744 target_committed_to_req(req);
1750 if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_LAST_REPLAY) {
1751 if (obd && obd->obd_recovering) {
1752 DEBUG_REQ(D_HA, req, "LAST_REPLAY, queuing reply");
1753 return target_queue_final_reply(req, rc);
1755 /* Lost a race with recovery; let the error path DTRT. */
1756 rc = req->rq_status = -ENOTCONN;
1759 target_send_reply(req, rc, fail);
1763 /* Update the server data on disk. This stores the new mount_count and
1764 * also the last_rcvd value to disk. If we don't have a clean shutdown,
1765 * then the server last_rcvd value may be less than that of the clients.
1766 * This will alert us that we may need to do client recovery.
1768 * Also assumes for mds_last_transno that we are not modifying it (no locking).
1770 int mds_update_server_data(struct obd_device *obd, int force_sync)
1772 struct mds_obd *mds = &obd->u.mds;
1773 struct lr_server_data *lsd = mds->mds_server_data;
1774 struct file *filp = mds->mds_rcvd_filp;
1775 struct lvfs_run_ctxt saved;
1780 CDEBUG(D_SUPER, "MDS mount_count is "LPU64", last_transno is "LPU64"\n",
1781 mds->mds_mount_count, mds->mds_last_transno);
1783 lsd->lsd_last_transno = cpu_to_le64(mds->mds_last_transno);
1785 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1786 rc = fsfilt_write_record(obd, filp, lsd, sizeof(*lsd), &off,force_sync);
1787 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
1789 CERROR("error writing MDS server data: rc = %d\n", rc);
1793 static void fsoptions_to_mds_flags(struct mds_obd *mds, char *options)
1803 while (*p && *p != ',')
1807 if (len == sizeof("user_xattr") - 1 &&
1808 memcmp(options, "user_xattr", len) == 0) {
1809 mds->mds_fl_user_xattr = 1;
1810 LCONSOLE_INFO("Enabling user_xattr\n");
1811 } else if (len == sizeof("nouser_xattr") - 1 &&
1812 memcmp(options, "nouser_xattr", len) == 0) {
1813 mds->mds_fl_user_xattr = 0;
1814 LCONSOLE_INFO("Disabling user_xattr\n");
1815 } else if (len == sizeof("acl") - 1 &&
1816 memcmp(options, "acl", len) == 0) {
1817 #ifdef CONFIG_FS_POSIX_ACL
1818 mds->mds_fl_acl = 1;
1819 LCONSOLE_INFO("Enabling ACL\n");
1821 CWARN("ignoring unsupported acl mount option\n");
1823 } else if (len == sizeof("noacl") - 1 &&
1824 memcmp(options, "noacl", len) == 0) {
1825 #ifdef CONFIG_FS_POSIX_ACL
1826 mds->mds_fl_acl = 0;
1827 LCONSOLE_INFO("Disabling ACL\n");
1834 static int mds_lov_presetup (struct mds_obd *mds, struct lustre_cfg *lcfg)
1839 rc = llog_start_commit_thread();
1843 if (lcfg->lcfg_bufcount >= 4 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
1846 generate_random_uuid(uuid);
1847 class_uuid_unparse(uuid, &mds->mds_lov_uuid);
1849 OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
1850 if (mds->mds_profile == NULL)
1853 strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
1854 LUSTRE_CFG_BUFLEN(lcfg, 3));
1859 /* mount the file system (secretly). lustre_cfg parameters are:
1865 static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
1867 struct lprocfs_static_vars lvars;
1868 struct mds_obd *mds = &obd->u.mds;
1869 struct lustre_mount_info *lmi;
1870 struct vfsmount *mnt;
1871 struct obd_uuid uuid;
1873 char *options, *str, *label;
1879 /* setup 1:/dev/loop/0 2:ext3 3:mdsA 4:errors=remount-ro,iopen_nopriv */
1881 CLASSERT(offsetof(struct obd_device, u.obt) ==
1882 offsetof(struct obd_device, u.mds.mds_obt));
1884 if (lcfg->lcfg_bufcount < 3)
1885 RETURN(rc = -EINVAL);
1887 if (LUSTRE_CFG_BUFLEN(lcfg, 1) == 0 || LUSTRE_CFG_BUFLEN(lcfg, 2) == 0)
1888 RETURN(rc = -EINVAL);
1890 lmi = server_get_mount(obd->obd_name);
1892 /* We already mounted in lustre_fill_super.
1893 lcfg bufs 1, 2, 4 (device, fstype, mount opts) are ignored.*/
1894 struct lustre_sb_info *lsi = s2lsi(lmi->lmi_sb);
1895 fsoptions_to_mds_flags(mds, lsi->lsi_ldd->ldd_mount_opts);
1896 fsoptions_to_mds_flags(mds, lsi->lsi_lmd->lmd_opts);
1898 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
1900 /* old path - used by lctl */
1901 CERROR("Using old MDS mount method\n");
1902 page = __get_free_page(GFP_KERNEL);
1906 options = (char *)page;
1907 memset(options, 0, PAGE_SIZE);
1909 /* here we use "iopen_nopriv" hardcoded, because it affects
1910 * MDS utility and the rest of options are passed by mount
1911 * options. Probably this should be moved to somewhere else
1912 * like startup scripts or lconf. */
1913 strcpy(options, "iopen_nopriv");
1915 if (LUSTRE_CFG_BUFLEN(lcfg, 4) > 0 && lustre_cfg_buf(lcfg, 4)) {
1916 sprintf(options + strlen(options), ",%s",
1917 lustre_cfg_string(lcfg, 4));
1918 fsoptions_to_mds_flags(mds, options);
1921 mnt = do_kern_mount(lustre_cfg_string(lcfg, 2), 0,
1922 lustre_cfg_string(lcfg, 1),
1927 LCONSOLE_ERROR("Can't mount disk %s (%d)\n",
1928 lustre_cfg_string(lcfg, 1), rc);
1932 obd->obd_fsops = fsfilt_get_ops(lustre_cfg_string(lcfg, 2));
1934 if (IS_ERR(obd->obd_fsops))
1935 GOTO(err_put, rc = PTR_ERR(obd->obd_fsops));
1937 CDEBUG(D_SUPER, "%s: mnt = %p\n", lustre_cfg_string(lcfg, 1), mnt);
1939 LASSERT(!lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb)));
1941 sema_init(&mds->mds_epoch_sem, 1);
1942 spin_lock_init(&mds->mds_transno_lock);
1943 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
1944 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
1945 mds->mds_atime_diff = MAX_ATIME_DIFF;
1947 sprintf(ns_name, "mds-%s", obd->obd_uuid.uuid);
1948 obd->obd_namespace = ldlm_namespace_new(ns_name, LDLM_NAMESPACE_SERVER);
1949 if (obd->obd_namespace == NULL) {
1951 GOTO(err_ops, rc = -ENOMEM);
1953 ldlm_register_intent(obd->obd_namespace, mds_intent_policy);
1955 rc = mds_fs_setup(obd, mnt);
1957 CERROR("%s: MDS filesystem method init failed: rc = %d\n",
1962 rc = mds_lov_presetup(mds, lcfg);
1966 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
1967 "mds_ldlm_client", &obd->obd_ldlm_client);
1968 obd->obd_replayable = 1;
1970 rc = lquota_setup(quota_interface, obd, lcfg);
1975 mds->mds_group_hash = upcall_cache_init(obd->obd_name);
1976 if (IS_ERR(mds->mds_group_hash)) {
1977 rc = PTR_ERR(mds->mds_group_hash);
1978 mds->mds_group_hash = NULL;
1979 GOTO(err_qctxt, rc);
1983 /* Don't wait for mds_postrecov trying to clear orphans */
1984 obd->obd_async_recov = 1;
1985 rc = mds_postsetup(obd);
1986 obd->obd_async_recov = 0;
1988 GOTO(err_qctxt, rc);
1990 lprocfs_init_vars(mds, &lvars);
1991 if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0 &&
1992 lprocfs_alloc_obd_stats(obd, LPROC_MDS_LAST) == 0) {
1993 /* Init private stats here */
1994 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_OPEN,
1995 /*LPROCFS_CNTR_AVGMINMAX*/0,
1997 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_CLOSE,
1998 0, "close", "reqs");
1999 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_MKNOD,
2000 0, "mknod", "reqs");
2001 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_LINK,
2003 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_UNLINK,
2004 0, "unlink", "reqs");
2005 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_MKDIR,
2006 0, "mkdir", "reqs");
2007 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_RMDIR,
2008 0, "rmdir", "reqs");
2009 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_RENAME,
2010 0, "rename", "reqs");
2011 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_GETXATTR,
2012 0, "getxattr", "reqs");
2013 lprocfs_counter_init(obd->obd_stats, LPROC_MDS_SETXATTR,
2014 0, "setxattr", "reqs");
2017 uuid_ptr = fsfilt_uuid(obd, obd->u.obt.obt_sb);
2018 if (uuid_ptr != NULL) {
2019 class_uuid_unparse(uuid_ptr, &uuid);
2025 label = fsfilt_get_label(obd, obd->u.obt.obt_sb);
2026 if (obd->obd_recovering) {
2027 LCONSOLE_WARN("MDT %s now serving %s (%s%s%s), but will be in "
2028 "recovery until %d %s reconnect, or if no clients"
2029 " reconnect for %d:%.02d; during that time new "
2030 "clients will not be allowed to connect. "
2031 "Recovery progress can be monitored by watching "
2032 "/proc/fs/lustre/mds/%s/recovery_status.\n",
2033 obd->obd_name, lustre_cfg_string(lcfg, 1),
2034 label ?: "", label ? "/" : "", str,
2035 obd->obd_recoverable_clients,
2036 (obd->obd_recoverable_clients == 1) ?
2037 "client" : "clients",
2038 (int)(OBD_RECOVERY_TIMEOUT) / 60,
2039 (int)(OBD_RECOVERY_TIMEOUT) % 60,
2042 LCONSOLE_INFO("MDT %s now serving %s (%s%s%s) with recovery "
2043 "%s\n", obd->obd_name, lustre_cfg_string(lcfg, 1),
2044 label ?: "", label ? "/" : "", str,
2045 obd->obd_replayable ? "enabled" : "disabled");
2053 lquota_cleanup(quota_interface, obd);
2055 /* No extra cleanup needed for llog_init_commit_thread() */
2056 mds_fs_cleanup(obd);
2058 upcall_cache_cleanup(mds->mds_group_hash);
2059 mds->mds_group_hash = NULL;
2062 ldlm_namespace_free(obd->obd_namespace, 0);
2063 obd->obd_namespace = NULL;
2065 fsfilt_put_ops(obd->obd_fsops);
2068 server_put_mount(obd->obd_name, mds->mds_vfsmnt);
2072 mntput(mds->mds_vfsmnt);
2075 obd->u.obt.obt_sb = NULL;
2079 static int mds_lov_clean(struct obd_device *obd)
2081 struct mds_obd *mds = &obd->u.mds;
2082 struct obd_device *osc = mds->mds_osc_obd;
2085 if (mds->mds_profile) {
2086 class_del_profile(mds->mds_profile);
2087 OBD_FREE(mds->mds_profile, strlen(mds->mds_profile) + 1);
2088 mds->mds_profile = NULL;
2091 /* There better be a lov */
2095 RETURN(PTR_ERR(osc));
2097 obd_register_observer(osc, NULL);
2099 /* Give lov our same shutdown flags */
2100 osc->obd_force = obd->obd_force;
2101 osc->obd_fail = obd->obd_fail;
2103 /* Cleanup the lov */
2104 obd_disconnect(mds->mds_osc_exp);
2105 class_manual_cleanup(osc);
2106 mds->mds_osc_exp = NULL;
2111 static int mds_postsetup(struct obd_device *obd)
2113 struct mds_obd *mds = &obd->u.mds;
2117 rc = llog_setup(obd, NULL, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL,
2122 rc = llog_setup(obd, NULL, LLOG_LOVEA_ORIG_CTXT, obd, 0, NULL,
2127 if (mds->mds_profile) {
2128 struct lustre_profile *lprof;
2129 /* The profile defines which osc and mdc to connect to, for a
2130 client. We reuse that here to figure out the name of the
2131 lov to use (and ignore lprof->lp_md).
2132 The profile was set in the config log with
2133 LCFG_MOUNTOPT profilenm oscnm mdcnm */
2134 lprof = class_get_profile(mds->mds_profile);
2135 if (lprof == NULL) {
2136 CERROR("No profile found: %s\n", mds->mds_profile);
2137 GOTO(err_cleanup, rc = -ENOENT);
2139 rc = mds_lov_connect(obd, lprof->lp_dt);
2141 GOTO(err_cleanup, rc);
2148 llog_cleanup(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT));
2149 llog_cleanup(llog_get_context(obd, LLOG_LOVEA_ORIG_CTXT));
2153 int mds_postrecov(struct obd_device *obd)
2161 LASSERT(!obd->obd_recovering);
2162 LASSERT(llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT) != NULL);
2164 /* FIXME why not put this in the synchronize? */
2165 /* set nextid first, so we are sure it happens */
2166 rc = mds_lov_set_nextid(obd);
2168 CERROR("%s: mds_lov_set_nextid failed %d\n",
2173 /* clean PENDING dir */
2174 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2175 rc = mds_cleanup_pending(obd);
2179 /* FIXME Does target_finish_recovery really need this to block? */
2180 /* Notify the LOV, which will in turn call mds_notify for each tgt */
2181 /* This means that we have to hack obd_notify to think we're obd_set_up
2182 during mds_lov_connect. */
2183 obd_notify(obd->u.mds.mds_osc_obd, NULL,
2184 obd->obd_async_recov ? OBD_NOTIFY_SYNC_NONBLOCK :
2185 OBD_NOTIFY_SYNC, NULL);
2187 /* quota recovery */
2188 lquota_recovery(quota_interface, obd);
2194 /* We need to be able to stop an mds_lov_synchronize */
2195 static int mds_lov_early_clean(struct obd_device *obd)
2197 struct mds_obd *mds = &obd->u.mds;
2198 struct obd_device *osc = mds->mds_osc_obd;
2200 if (!osc || (!obd->obd_force && !obd->obd_fail))
2203 CDEBUG(D_HA, "abort inflight\n");
2204 return (obd_precleanup(osc, OBD_CLEANUP_EARLY));
2207 static int mds_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2213 case OBD_CLEANUP_EARLY:
2215 case OBD_CLEANUP_EXPORTS:
2216 /*XXX Use this for mdd mds cleanup, so comment out
2217 *this target_cleanup_recovery for this tmp MDD MDS
2219 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2220 target_cleanup_recovery(obd);
2221 mds_lov_early_clean(obd);
2223 case OBD_CLEANUP_SELF_EXP:
2224 mds_lov_disconnect(obd);
2226 llog_cleanup(llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT));
2227 llog_cleanup(llog_get_context(obd, LLOG_LOVEA_ORIG_CTXT));
2228 rc = obd_llog_finish(obd, 0);
2230 case OBD_CLEANUP_OBD:
2236 static int mds_cleanup(struct obd_device *obd)
2238 struct mds_obd *mds = &obd->u.mds;
2239 lvfs_sbdev_type save_dev;
2241 int must_relock = 0;
2244 if (obd->u.obt.obt_sb == NULL)
2246 save_dev = lvfs_sbdev(obd->u.obt.obt_sb);
2248 if (mds->mds_osc_exp)
2249 /* lov export was disconnected by mds_lov_clean;
2250 we just need to drop our ref */
2251 class_export_put(mds->mds_osc_exp);
2253 lprocfs_free_obd_stats(obd);
2254 lprocfs_obd_cleanup(obd);
2256 lquota_cleanup(quota_interface, obd);
2258 mds_update_server_data(obd, 1);
2259 if (mds->mds_lov_objids != NULL)
2260 OBD_FREE(mds->mds_lov_objids, mds->mds_lov_objids_size);
2261 mds_fs_cleanup(obd);
2264 upcall_cache_cleanup(mds->mds_group_hash);
2265 mds->mds_group_hash = NULL;
2268 must_put = server_put_mount(obd->obd_name, mds->mds_vfsmnt);
2269 /* must_put is for old method (l_p_m returns non-0 on err) */
2271 /* We can only unlock kernel if we are in the context of sys_ioctl,
2272 otherwise we never called lock_kernel */
2273 if (ll_kernel_locked()) {
2279 /* In case we didn't mount with lustre_get_mount -- old method*/
2280 mntput(mds->mds_vfsmnt);
2281 lvfs_clear_rdonly(save_dev);
2283 obd->u.obt.obt_sb = NULL;
2285 ldlm_namespace_free(obd->obd_namespace, obd->obd_force);
2287 spin_lock_bh(&obd->obd_processing_task_lock);
2288 if (obd->obd_recovering) {
2289 target_cancel_recovery_timer(obd);
2290 obd->obd_recovering = 0;
2292 spin_unlock_bh(&obd->obd_processing_task_lock);
2297 fsfilt_put_ops(obd->obd_fsops);
2299 LCONSOLE_INFO("MDT %s has stopped.\n", obd->obd_name);
2304 static void fixup_handle_for_resent_req(struct ptlrpc_request *req, int offset,
2305 struct ldlm_lock *new_lock,
2306 struct ldlm_lock **old_lock,
2307 struct lustre_handle *lockh)
2309 struct obd_export *exp = req->rq_export;
2310 struct obd_device *obd = exp->exp_obd;
2311 struct ldlm_request *dlmreq =
2312 lustre_msg_buf(req->rq_reqmsg, offset, sizeof(*dlmreq));
2313 struct lustre_handle remote_hdl = dlmreq->lock_handle1;
2314 struct list_head *iter;
2316 if (!(lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
2319 spin_lock(&obd->obd_namespace->ns_hash_lock);
2320 list_for_each(iter, &exp->exp_ldlm_data.led_held_locks) {
2321 struct ldlm_lock *lock;
2322 lock = list_entry(iter, struct ldlm_lock, l_export_chain);
2323 if (lock == new_lock)
2325 if (lock->l_remote_handle.cookie == remote_hdl.cookie) {
2326 lockh->cookie = lock->l_handle.h_cookie;
2327 LDLM_DEBUG(lock, "restoring lock cookie");
2328 DEBUG_REQ(D_HA, req, "restoring lock cookie "LPX64,
2331 *old_lock = LDLM_LOCK_GET(lock);
2332 spin_unlock(&obd->obd_namespace->ns_hash_lock);
2336 spin_unlock(&obd->obd_namespace->ns_hash_lock);
2338 /* If the xid matches, then we know this is a resent request,
2339 * and allow it. (It's probably an OPEN, for which we don't
2342 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_xid))
2346 le64_to_cpu(exp->exp_mds_data.med_mcd->mcd_last_close_xid))
2349 /* This remote handle isn't enqueued, so we never received or
2350 * processed this request. Clear MSG_RESENT, because it can
2351 * be handled like any normal request now. */
2353 lustre_msg_clear_flags(req->rq_reqmsg, MSG_RESENT);
2355 DEBUG_REQ(D_HA, req, "no existing lock with rhandle "LPX64,
2359 int intent_disposition(struct ldlm_reply *rep, int flag)
2363 return (rep->lock_policy_res1 & flag);
2366 void intent_set_disposition(struct ldlm_reply *rep, int flag)
2370 rep->lock_policy_res1 |= flag;
2373 static int mds_intent_policy(struct ldlm_namespace *ns,
2374 struct ldlm_lock **lockp, void *req_cookie,
2375 ldlm_mode_t mode, int flags, void *data)
2377 struct ptlrpc_request *req = req_cookie;
2378 struct ldlm_lock *lock = *lockp;
2379 struct ldlm_intent *it;
2380 struct mds_obd *mds = &req->rq_export->exp_obd->u.mds;
2381 struct ldlm_reply *rep;
2382 struct lustre_handle lockh = { 0 };
2383 struct ldlm_lock *new_lock = NULL;
2384 int getattr_part = MDS_INODELOCK_UPDATE;
2385 int repsize[5] = { [MSG_PTLRPC_BODY_OFF] = sizeof(struct ptlrpc_body),
2386 [DLM_LOCKREPLY_OFF] = sizeof(struct ldlm_reply),
2387 [DLM_REPLY_REC_OFF] = sizeof(struct mds_body),
2388 [DLM_REPLY_REC_OFF+1] = mds->mds_max_mdsize };
2389 int repbufcnt = 4, rc;
2392 LASSERT(req != NULL);
2394 if (lustre_msg_bufcount(req->rq_reqmsg) <= DLM_INTENT_IT_OFF) {
2395 /* No intent was provided */
2396 rc = lustre_pack_reply(req, 2, repsize, NULL);
2401 it = lustre_swab_reqbuf(req, DLM_INTENT_IT_OFF, sizeof(*it),
2402 lustre_swab_ldlm_intent);
2404 CERROR("Intent missing\n");
2405 RETURN(req->rq_status = -EFAULT);
2408 LDLM_DEBUG(lock, "intent policy, opc: %s", ldlm_it2str(it->opc));
2410 if ((req->rq_export->exp_connect_flags & OBD_CONNECT_ACL) &&
2411 (it->opc & (IT_OPEN | IT_GETATTR | IT_LOOKUP)))
2412 /* we should never allow OBD_CONNECT_ACL if not configured */
2413 repsize[repbufcnt++] = LUSTRE_POSIX_ACL_MAX_SIZE;
2414 else if (it->opc & IT_UNLINK)
2415 repsize[repbufcnt++] = mds->mds_max_cookiesize;
2417 rc = lustre_pack_reply(req, repbufcnt, repsize, NULL);
2419 RETURN(req->rq_status = rc);
2421 rep = lustre_msg_buf(req->rq_repmsg, DLM_LOCKREPLY_OFF, sizeof(*rep));
2422 intent_set_disposition(rep, DISP_IT_EXECD);
2425 /* execute policy */
2426 switch ((long)it->opc) {
2428 case IT_CREAT|IT_OPEN:
2429 lprocfs_counter_incr(req->rq_export->exp_obd->obd_stats,
2431 fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock, NULL,
2433 /* XXX swab here to assert that an mds_open reint
2434 * packet is following */
2435 rep->lock_policy_res2 = mds_reint(req, DLM_INTENT_REC_OFF,
2438 /* We abort the lock if the lookup was negative and
2439 * we did not make it to the OPEN portion */
2440 if (!intent_disposition(rep, DISP_LOOKUP_EXECD))
2441 RETURN(ELDLM_LOCK_ABORTED);
2442 if (intent_disposition(rep, DISP_LOOKUP_NEG) &&
2443 !intent_disposition(rep, DISP_OPEN_OPEN))
2445 if (rep->lock_policy_res2) {
2446 /* mds_open returns ENOLCK where it should return zero,
2447 but it has no lock to return */
2448 if (rep->lock_policy_res2 == ENOLCK)
2449 rep->lock_policy_res2 = 0;
2450 RETURN(ELDLM_LOCK_ABORTED);
2454 getattr_part = MDS_INODELOCK_LOOKUP;
2456 getattr_part |= MDS_INODELOCK_LOOKUP;
2457 OBD_COUNTER_INCREMENT(req->rq_export->exp_obd, getattr);
2459 fixup_handle_for_resent_req(req, DLM_LOCKREQ_OFF, lock,
2462 /* INODEBITS_INTEROP: if this lock was converted from a
2463 * plain lock (client does not support inodebits), then
2464 * child lock must be taken with both lookup and update
2465 * bits set for all operations.
2467 if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_IBITS))
2468 getattr_part = MDS_INODELOCK_LOOKUP |
2469 MDS_INODELOCK_UPDATE;
2471 rep->lock_policy_res2 = mds_getattr_lock(req,DLM_INTENT_REC_OFF,
2472 getattr_part, &lockh);
2473 /* FIXME: LDLM can set req->rq_status. MDS sets
2474 policy_res{1,2} with disposition and status.
2475 - replay: returns 0 & req->status is old status
2476 - otherwise: returns req->status */
2477 if (intent_disposition(rep, DISP_LOOKUP_NEG))
2478 rep->lock_policy_res2 = 0;
2479 if (!intent_disposition(rep, DISP_LOOKUP_POS) ||
2480 rep->lock_policy_res2)
2481 RETURN(ELDLM_LOCK_ABORTED);
2482 if (req->rq_status != 0) {
2484 rep->lock_policy_res2 = req->rq_status;
2485 RETURN(ELDLM_LOCK_ABORTED);
2489 CERROR("Unhandled intent "LPD64"\n", it->opc);
2493 /* By this point, whatever function we called above must have either
2494 * filled in 'lockh', been an intent replay, or returned an error. We
2495 * want to allow replayed RPCs to not get a lock, since we would just
2496 * drop it below anyways because lock replay is done separately by the
2497 * client afterwards. For regular RPCs we want to give the new lock to
2498 * the client instead of whatever lock it was about to get. */
2499 if (new_lock == NULL)
2500 new_lock = ldlm_handle2lock(&lockh);
2501 if (new_lock == NULL && (flags & LDLM_FL_INTENT_ONLY))
2504 LASSERTF(new_lock != NULL, "op "LPX64" lockh "LPX64"\n",
2505 it->opc, lockh.cookie);
2507 /* If we've already given this lock to a client once, then we should
2508 * have no readers or writers. Otherwise, we should have one reader
2509 * _or_ writer ref (which will be zeroed below) before returning the
2510 * lock to a client. */
2511 if (new_lock->l_export == req->rq_export) {
2512 LASSERT(new_lock->l_readers + new_lock->l_writers == 0);
2514 LASSERT(new_lock->l_export == NULL);
2515 LASSERT(new_lock->l_readers + new_lock->l_writers == 1);
2520 if (new_lock->l_export == req->rq_export) {
2521 /* Already gave this to the client, which means that we
2522 * reconstructed a reply. */
2523 LASSERT(lustre_msg_get_flags(req->rq_reqmsg) &
2525 RETURN(ELDLM_LOCK_REPLACED);
2528 /* Fixup the lock to be given to the client */
2529 lock_res_and_lock(new_lock);
2530 new_lock->l_readers = 0;
2531 new_lock->l_writers = 0;
2533 new_lock->l_export = class_export_get(req->rq_export);
2534 list_add(&new_lock->l_export_chain,
2535 &new_lock->l_export->exp_ldlm_data.led_held_locks);
2537 new_lock->l_blocking_ast = lock->l_blocking_ast;
2538 new_lock->l_completion_ast = lock->l_completion_ast;
2540 memcpy(&new_lock->l_remote_handle, &lock->l_remote_handle,
2541 sizeof(lock->l_remote_handle));
2543 new_lock->l_flags &= ~LDLM_FL_LOCAL;
2545 unlock_res_and_lock(new_lock);
2546 LDLM_LOCK_PUT(new_lock);
2548 RETURN(ELDLM_LOCK_REPLACED);
2551 static int mdt_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
2553 struct mds_obd *mds = &obd->u.mds;
2554 struct lprocfs_static_vars lvars;
2558 lprocfs_init_vars(mdt, &lvars);
2559 lprocfs_obd_setup(obd, lvars.obd_vars);
2561 sema_init(&mds->mds_health_sem, 1);
2563 if (mds_num_threads < 2)
2564 mds_num_threads = MDT_NUM_THREADS;
2565 if (mds_num_threads > MDT_MAX_THREADS)
2566 mds_num_threads = MDT_MAX_THREADS;
2569 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2570 MDS_MAXREPSIZE, MDS_REQUEST_PORTAL,
2571 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2572 mds_handle, LUSTRE_MDS_NAME,
2573 obd->obd_proc_entry, NULL, mds_num_threads, 0);
2575 if (!mds->mds_service) {
2576 CERROR("failed to start service\n");
2577 GOTO(err_lprocfs, rc = -ENOMEM);
2580 rc = ptlrpc_start_threads(obd, mds->mds_service, "ll_mdt");
2582 GOTO(err_thread, rc);
2584 mds->mds_setattr_service =
2585 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2586 MDS_MAXREPSIZE, MDS_SETATTR_PORTAL,
2587 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2588 mds_handle, "mds_setattr",
2589 obd->obd_proc_entry, NULL, mds_num_threads, 0);
2590 if (!mds->mds_setattr_service) {
2591 CERROR("failed to start getattr service\n");
2592 GOTO(err_thread, rc = -ENOMEM);
2595 rc = ptlrpc_start_threads(obd, mds->mds_setattr_service,
2598 GOTO(err_thread2, rc);
2600 mds->mds_readpage_service =
2601 ptlrpc_init_svc(MDS_NBUFS, MDS_BUFSIZE, MDS_MAXREQSIZE,
2602 MDS_MAXREPSIZE, MDS_READPAGE_PORTAL,
2603 MDC_REPLY_PORTAL, MDS_SERVICE_WATCHDOG_TIMEOUT,
2604 mds_handle, "mds_readpage",
2605 obd->obd_proc_entry, NULL, mds_num_threads, 0);
2606 if (!mds->mds_readpage_service) {
2607 CERROR("failed to start readpage service\n");
2608 GOTO(err_thread2, rc = -ENOMEM);
2611 rc = ptlrpc_start_threads(obd, mds->mds_readpage_service,
2615 GOTO(err_thread3, rc);
2617 ping_evictor_start();
2621 ptlrpc_unregister_service(mds->mds_readpage_service);
2622 mds->mds_readpage_service = NULL;
2624 ptlrpc_unregister_service(mds->mds_setattr_service);
2625 mds->mds_setattr_service = NULL;
2627 ptlrpc_unregister_service(mds->mds_service);
2628 mds->mds_service = NULL;
2630 lprocfs_obd_cleanup(obd);
2634 static int mdt_cleanup(struct obd_device *obd)
2636 struct mds_obd *mds = &obd->u.mds;
2639 ping_evictor_stop();
2641 down(&mds->mds_health_sem);
2642 ptlrpc_unregister_service(mds->mds_readpage_service);
2643 ptlrpc_unregister_service(mds->mds_setattr_service);
2644 ptlrpc_unregister_service(mds->mds_service);
2645 mds->mds_readpage_service = NULL;
2646 mds->mds_setattr_service = NULL;
2647 mds->mds_service = NULL;
2648 up(&mds->mds_health_sem);
2650 lprocfs_obd_cleanup(obd);
2655 static int mdt_health_check(struct obd_device *obd)
2657 struct mds_obd *mds = &obd->u.mds;
2660 down(&mds->mds_health_sem);
2661 rc |= ptlrpc_service_health_check(mds->mds_readpage_service);
2662 rc |= ptlrpc_service_health_check(mds->mds_setattr_service);
2663 rc |= ptlrpc_service_health_check(mds->mds_service);
2664 up(&mds->mds_health_sem);
2667 * health_check to return 0 on healthy
2668 * and 1 on unhealthy.
2676 static struct dentry *mds_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
2679 struct obd_device *obd = data;
2682 fid.generation = gen;
2683 return mds_fid2dentry(&obd->u.mds, &fid, NULL);
2686 static int mds_health_check(struct obd_device *obd)
2688 struct obd_device_target *odt = &obd->u.obt;
2689 struct mds_obd *mds = &obd->u.mds;
2692 if (odt->obt_sb->s_flags & MS_RDONLY)
2695 LASSERT(mds->mds_health_check_filp != NULL);
2696 rc |= !!lvfs_check_io_health(obd, mds->mds_health_check_filp);
2701 static int mds_process_config(struct obd_device *obd, obd_count len, void *buf)
2703 struct lustre_cfg *lcfg = buf;
2704 struct lprocfs_static_vars lvars;
2707 lprocfs_init_vars(mds, &lvars);
2709 rc = class_process_proc_param(PARAM_MDT, lvars.obd_vars, lcfg, obd);
2713 struct lvfs_callback_ops mds_lvfs_ops = {
2714 l_fid2dentry: mds_lvfs_fid2dentry,
2717 /* use obd ops to offer management infrastructure */
2718 static struct obd_ops mds_obd_ops = {
2719 .o_owner = THIS_MODULE,
2720 .o_connect = mds_connect,
2721 .o_reconnect = mds_reconnect,
2722 .o_init_export = mds_init_export,
2723 .o_destroy_export = mds_destroy_export,
2724 .o_disconnect = mds_disconnect,
2725 .o_setup = mds_setup,
2726 .o_precleanup = mds_precleanup,
2727 .o_cleanup = mds_cleanup,
2728 .o_postrecov = mds_postrecov,
2729 .o_statfs = mds_obd_statfs,
2730 .o_iocontrol = mds_iocontrol,
2731 .o_create = mds_obd_create,
2732 .o_destroy = mds_obd_destroy,
2733 .o_llog_init = mds_llog_init,
2734 .o_llog_finish = mds_llog_finish,
2735 .o_notify = mds_notify,
2736 .o_health_check = mds_health_check,
2737 .o_process_config = mds_process_config,
2740 static struct obd_ops mdt_obd_ops = {
2741 .o_owner = THIS_MODULE,
2742 .o_setup = mdt_setup,
2743 .o_cleanup = mdt_cleanup,
2744 .o_health_check = mdt_health_check,
2747 quota_interface_t *quota_interface;
2748 quota_interface_t mds_quota_interface;
2750 static __attribute__((unused)) int __init mds_init(void)
2753 struct lprocfs_static_vars lvars;
2755 request_module("lquota");
2756 quota_interface = PORTAL_SYMBOL_GET(mds_quota_interface);
2757 rc = lquota_init(quota_interface);
2759 if (quota_interface)
2760 PORTAL_SYMBOL_PUT(mds_quota_interface);
2763 init_obd_quota_ops(quota_interface, &mds_obd_ops);
2765 lprocfs_init_vars(mds, &lvars);
2766 class_register_type(&mds_obd_ops, NULL,
2767 lvars.module_vars, LUSTRE_MDS_NAME, NULL);
2768 lprocfs_init_vars(mdt, &lvars);
2769 mdt_obd_ops = mdt_obd_ops; //make compiler happy
2770 // class_register_type(&mdt_obd_ops, NULL,
2771 // lvars.module_vars, LUSTRE_MDT_NAME, NULL);
2776 static __attribute__((unused)) void /*__exit*/ mds_exit(void)
2778 lquota_exit(quota_interface);
2779 if (quota_interface)
2780 PORTAL_SYMBOL_PUT(mds_quota_interface);
2782 class_unregister_type(LUSTRE_MDS_NAME);
2783 // class_unregister_type(LUSTRE_MDT_NAME);
2785 /*mds still need lov setup here*/
2786 static int mds_cmd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
2788 struct mds_obd *mds = &obd->u.mds;
2789 struct lvfs_run_ctxt saved;
2791 struct vfsmount *mnt;
2792 struct lustre_sb_info *lsi;
2793 struct lustre_mount_info *lmi;
2794 struct dentry *dentry;
2799 CDEBUG(D_INFO, "obd %s setup \n", obd->obd_name);
2800 if (strncmp(obd->obd_name, MDD_OBD_NAME, strlen(MDD_OBD_NAME)))
2803 if (lcfg->lcfg_bufcount < 5) {
2804 CERROR("invalid arg for setup %s\n", MDD_OBD_NAME);
2807 dev = lustre_cfg_string(lcfg, 4);
2808 lmi = server_get_mount(dev);
2809 LASSERT(lmi != NULL);
2811 lsi = s2lsi(lmi->lmi_sb);
2813 /* FIXME: MDD LOV initialize objects.
2814 * we need only lmi here but not get mount
2815 * OSD did mount already, so put mount back
2817 atomic_dec(&lsi->lsi_mounts);
2820 obd->obd_fsops = fsfilt_get_ops(MT_STR(lsi->lsi_ldd));
2821 mds_init_ctxt(obd, mnt);
2823 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2824 dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
2825 if (IS_ERR(dentry)) {
2826 rc = PTR_ERR(dentry);
2827 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
2828 GOTO(err_putfs, rc);
2830 mds->mds_objects_dir = dentry;
2832 dentry = lookup_one_len("__iopen__", current->fs->pwd,
2833 strlen("__iopen__"));
2834 if (IS_ERR(dentry)) {
2835 rc = PTR_ERR(dentry);
2836 CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
2837 GOTO(err_objects, rc);
2840 mds->mds_fid_de = dentry;
2841 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
2843 CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
2847 /* open and test the lov objd file */
2848 file = filp_open(LOV_OBJID, O_RDWR | O_CREAT, 0644);
2851 CERROR("cannot open/create %s file: rc = %d\n", LOV_OBJID, rc);
2852 GOTO(err_fid, rc = PTR_ERR(file));
2854 mds->mds_lov_objid_filp = file;
2855 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
2856 CERROR("%s is not a regular file!: mode = %o\n", LOV_OBJID,
2857 file->f_dentry->d_inode->i_mode);
2858 GOTO(err_lov_objid, rc = -ENOENT);
2861 rc = mds_lov_presetup(mds, lcfg);
2863 GOTO(err_objects, rc);
2865 /* Don't wait for mds_postrecov trying to clear orphans */
2866 obd->obd_async_recov = 1;
2867 rc = mds_postsetup(obd);
2868 obd->obd_async_recov = 0;
2871 GOTO(err_objects, rc);
2873 mds->mds_max_mdsize = sizeof(struct lov_mds_md);
2874 mds->mds_max_cookiesize = sizeof(struct llog_cookie);
2877 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2880 if (mds->mds_lov_objid_filp &&
2881 filp_close((struct file *)mds->mds_lov_objid_filp, 0))
2882 CERROR("can't close %s after error\n", LOV_OBJID);
2884 dput(mds->mds_fid_de);
2886 dput(mds->mds_objects_dir);
2888 fsfilt_put_ops(obd->obd_fsops);
2892 static int mds_cmd_cleanup(struct obd_device *obd)
2894 struct mds_obd *mds = &obd->u.mds;
2895 struct lvfs_run_ctxt saved;
2900 LCONSOLE_WARN("%s: shutting down for failover; client state "
2901 "will be preserved.\n", obd->obd_name);
2903 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2904 if (mds->mds_lov_objid_filp) {
2905 rc = filp_close((struct file *)mds->mds_lov_objid_filp, 0);
2906 mds->mds_lov_objid_filp = NULL;
2908 CERROR("%s file won't close, rc=%d\n", LOV_OBJID, rc);
2910 if (mds->mds_objects_dir != NULL) {
2911 l_dput(mds->mds_objects_dir);
2912 mds->mds_objects_dir = NULL;
2915 if (mds->mds_lov_objids != NULL)
2916 OBD_FREE(mds->mds_lov_objids, mds->mds_lov_objids_size);
2918 shrink_dcache_parent(mds->mds_fid_de);
2919 dput(mds->mds_fid_de);
2920 LL_DQUOT_OFF(obd->u.obt.obt_sb);
2921 fsfilt_put_ops(obd->obd_fsops);
2923 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
2928 static int mds_cmd_health_check(struct obd_device *obd)
2933 static struct obd_ops mds_cmd_obd_ops = {
2934 .o_owner = THIS_MODULE,
2935 .o_setup = mds_cmd_setup,
2936 .o_cleanup = mds_cmd_cleanup,
2937 .o_precleanup = mds_precleanup,
2938 .o_create = mds_obd_create,
2939 .o_destroy = mds_obd_destroy,
2940 .o_llog_init = mds_llog_init,
2941 .o_llog_finish = mds_llog_finish,
2942 .o_notify = mds_notify,
2943 .o_postrecov = mds_postrecov,
2944 // .o_health_check = mds_cmd_health_check,
2947 static int __init mds_cmd_init(void)
2949 struct lprocfs_static_vars lvars;
2951 lprocfs_init_vars(mds, &lvars);
2952 class_register_type(&mds_cmd_obd_ops, NULL, lvars.module_vars,
2953 LUSTRE_MDS_NAME, NULL);
2958 static void /*__exit*/ mds_cmd_exit(void)
2960 class_unregister_type(LUSTRE_MDS_NAME);
2963 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
2964 MODULE_DESCRIPTION("Lustre Metadata Server (MDS)");
2965 MODULE_LICENSE("GPL");
2967 module_init(mds_cmd_init);
2968 module_exit(mds_cmd_exit);