1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Lustre Metadata Server (mds) request handler
8 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
10 * This code is issued under the GNU General Public License.
11 * See the file COPYING in this distribution
13 * by Peter Braam <braam@clusterfs.com> &
14 * Andreas Dilger <braam@clusterfs.com>
16 * This server is single threaded at present (but can easily be multi threaded)
21 #define DEBUG_SUBSYSTEM S_MDS
23 #include <linux/module.h>
24 #include <linux/lustre_mds.h>
25 #include <linux/lustre_dlm.h>
26 extern int mds_update_last_rcvd(struct mds_obd *mds, void *handle,
27 struct ptlrpc_request *req);
28 static int mds_cleanup(struct obd_device * obddev);
30 inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req)
32 return &req->rq_export->export_obd->u.mds;
35 /* Assumes caller has already pushed into the kernel filesystem context */
36 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
40 struct mds_obd *mds = mds_req2mds(req);
41 struct ptlrpc_bulk_desc *desc;
42 struct ptlrpc_bulk_page *bulk;
46 desc = ptlrpc_prep_bulk(req->rq_connection);
48 GOTO(out, rc = -ENOMEM);
50 bulk = ptlrpc_prep_bulk_page(desc);
52 GOTO(cleanup_bulk, rc = -ENOMEM);
54 OBD_ALLOC(buf, PAGE_SIZE);
56 GOTO(cleanup_bulk, rc = -ENOMEM);
58 rc = mds_fs_readpage(mds, file, buf, PAGE_SIZE, (loff_t *)&offset);
61 GOTO(cleanup_buf, rc = -EIO);
63 bulk->b_xid = req->rq_xid;
65 bulk->b_buflen = PAGE_SIZE;
66 desc->b_portal = MDS_BULK_PORTAL;
68 rc = ptlrpc_send_bulk(desc);
70 GOTO(cleanup_buf, rc);
72 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
73 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
74 OBD_FAIL_MDS_SENDPAGE, rc);
75 ptlrpc_abort_bulk(desc);
76 GOTO(cleanup_buf, rc);
79 wait_event_interruptible(desc->b_waitq, ptlrpc_check_bulk_sent(desc));
80 if (desc->b_flags & PTL_RPC_FL_INTR)
81 GOTO(cleanup_buf, rc = -EINTR);
85 OBD_FREE(buf, PAGE_SIZE);
87 ptlrpc_free_bulk(desc);
92 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
93 struct vfsmount **mnt)
96 struct super_block *sb = mds->mds_sb;
97 unsigned long ino = fid->id;
98 __u32 generation = fid->generation;
100 struct list_head *lp;
101 struct dentry *result;
104 RETURN(ERR_PTR(-ESTALE));
106 inode = iget(sb, ino);
108 RETURN(ERR_PTR(-ENOMEM));
110 CDEBUG(D_DENTRY, "--> mds_fid2dentry: sb %p\n", inode->i_sb);
112 if (is_bad_inode(inode) ||
113 (generation && inode->i_generation != generation)) {
114 /* we didn't find the right inode.. */
115 CERROR("bad inode %lu, link: %d ct: %d or version %u/%u\n",
116 inode->i_ino, inode->i_nlink,
117 atomic_read(&inode->i_count), inode->i_generation,
121 RETURN(ERR_PTR(-ESTALE));
124 /* now to find a dentry.
125 * If possible, get a well-connected one
128 *mnt = mds->mds_vfsmnt;
129 spin_lock(&dcache_lock);
130 for (lp = inode->i_dentry.next; lp != &inode->i_dentry ; lp=lp->next) {
131 result = list_entry(lp,struct dentry, d_alias);
132 if (! (result->d_flags & DCACHE_NFSD_DISCONNECTED)) {
134 result->d_vfs_flags |= DCACHE_REFERENCED;
135 spin_unlock(&dcache_lock);
142 spin_unlock(&dcache_lock);
143 result = d_alloc_root(inode);
144 if (result == NULL) {
146 return ERR_PTR(-ENOMEM);
150 result->d_flags |= DCACHE_NFSD_DISCONNECTED;
154 static int mds_connect(struct obd_conn *conn, struct obd_device *obd)
159 rc = gen_connect(conn, obd);
167 static int mds_disconnect(struct obd_conn *conn)
171 rc = gen_disconnect(conn);
178 /* FIXME: the error cases need fixing to avoid leaks */
179 static int mds_getstatus(struct ptlrpc_request *req)
181 struct mds_obd *mds = mds_req2mds(req);
182 struct mds_body *body;
183 struct mds_client_info *mci;
184 struct mds_client_data *mcd;
185 int rc, size = sizeof(*body);
188 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
189 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
190 CERROR("mds: out of memory for message: size=%d\n", size);
191 req->rq_status = -ENOMEM;
195 body = lustre_msg_buf(req->rq_reqmsg, 0);
196 mds_unpack_body(body);
197 /* Anything we need to do here with the client's trans no or so? */
199 body = lustre_msg_buf(req->rq_repmsg, 0);
200 memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
202 mci = mds_uuid_to_mci(mds, ptlrpc_req_to_uuid(req));
204 /* We don't have any old connection data for this client */
207 CDEBUG(D_INFO, "allocating new client data for UUID '%s'",
208 ptlrpc_req_to_uuid(req));
210 OBD_ALLOC(mcd, sizeof(*mcd));
212 CERROR("mds: out of memory for client data\n");
213 req->rq_status = -ENOMEM;
216 memcpy(mcd->mcd_uuid, ptlrpc_req_to_uuid(req),
217 sizeof(mcd->mcd_uuid));
218 rc = mds_client_add(mds, mcd, -1);
224 /* We have old connection data for this client... */
226 CDEBUG(D_INFO, "found existing data for UUID '%s' at #%d\n",
227 mcd->mcd_uuid, mci->mci_off);
229 /* mcd_last_xid is is stored in little endian on the disk and
230 mds_pack_rep_body converts it to network order */
231 body->last_xid = le32_to_cpu(mcd->mcd_last_xid);
232 mds_pack_rep_body(req);
236 int mds_lock_callback(struct lustre_handle *lockh, struct ldlm_lock_desc *desc,
237 void *data, int data_len, struct ptlrpc_request **reqp)
242 /* Completion AST. Do nothing */
246 if (ldlm_cli_cancel(lockh, NULL) < 0)
251 static int mds_getattr_name(int offset, struct ptlrpc_request *req)
253 struct mds_obd *mds = mds_req2mds(req);
254 struct obd_run_ctxt saved;
255 struct mds_body *body;
256 struct dentry *de = NULL, *dchild = NULL;
258 struct lustre_handle lockh;
260 int namelen, flags, lock_mode, rc = 0;
261 __u64 res_id[3] = {0, 0, 0};
264 if (strcmp(req->rq_export->export_obd->obd_type->typ_name, "mds") != 0)
267 if (req->rq_reqmsg->bufcount <= offset + 1) {
269 GOTO(out_pre_de, rc = -EINVAL);
272 body = lustre_msg_buf(req->rq_reqmsg, offset);
273 name = lustre_msg_buf(req->rq_reqmsg, offset + 1);
274 namelen = req->rq_reqmsg->buflens[offset + 1];
275 /* requests were at offset 2, replies go back at 1 */
279 push_ctxt(&saved, &mds->mds_ctxt);
280 de = mds_fid2dentry(mds, &body->fid1, NULL);
283 GOTO(out_pre_de, rc = -ESTALE);
287 CDEBUG(D_INODE, "parent ino %ld\n", dir->i_ino);
289 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
290 res_id[0] = dir->i_ino;
292 rc = ldlm_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
293 NULL, 0, lock_mode, &lockh);
295 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
296 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
297 (struct lustre_handle *)&mds->mds_connh,
298 NULL, mds->mds_local_namespace, NULL,
299 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
300 &flags, (void *)mds_lock_callback,
302 if (rc != ELDLM_OK) {
303 CERROR("lock enqueue: err: %d\n", rc);
304 GOTO(out_create_de, rc = -EIO);
307 ldlm_lock_dump((void *)(unsigned long)lockh.addr);
310 dchild = lookup_one_len(name, de, namelen - 1);
311 if (IS_ERR(dchild)) {
312 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
315 GOTO(out_create_dchild, rc = -ESTALE);
318 if (dchild->d_inode) {
319 struct mds_body *body;
321 struct inode *inode = dchild->d_inode;
322 CERROR("child exists (dir %ld, name %s, ino %ld)\n",
323 dir->i_ino, name, dchild->d_inode->i_ino);
325 body = lustre_msg_buf(req->rq_repmsg, offset);
326 mds_pack_inode2fid(&body->fid1, inode);
327 mds_pack_inode2body(body, inode);
328 if (S_ISREG(inode->i_mode)) {
329 obdo = lustre_msg_buf(req->rq_repmsg, offset + 1);
330 mds_fs_get_obdo(mds, inode, obdo);
332 /* now a normal case for intent locking */
342 ldlm_lock_decref(&lockh, lock_mode);
352 static int mds_getattr(int offset, struct ptlrpc_request *req)
354 struct mds_obd *mds = mds_req2mds(req);
355 struct obd_run_ctxt saved;
358 struct mds_body *body;
359 int rc, size[2] = {sizeof(*body)}, bufcount = 1;
362 body = lustre_msg_buf(req->rq_reqmsg, offset);
363 push_ctxt(&saved, &mds->mds_ctxt);
364 de = mds_fid2dentry(mds, &body->fid1, NULL);
366 GOTO(out_pop, rc = -ENOENT);
370 if (S_ISREG(body->fid1.f_type)) {
372 size[1] = sizeof(struct obdo);
373 } else if (body->valid & OBD_MD_LINKNAME) {
375 size[1] = inode->i_size;
378 rc = lustre_pack_msg(bufcount, size, NULL, &req->rq_replen,
380 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
381 CERROR("mds: out of memory\n");
385 if (body->valid & OBD_MD_LINKNAME) {
386 char *tmp = lustre_msg_buf(req->rq_repmsg, 1);
388 rc = inode->i_op->readlink(de, tmp, size[1]);
391 CERROR("readlink failed: %d\n", rc);
396 body = lustre_msg_buf(req->rq_repmsg, 0);
397 body->ino = inode->i_ino;
398 body->generation = inode->i_generation;
399 body->atime = inode->i_atime;
400 body->ctime = inode->i_ctime;
401 body->mtime = inode->i_mtime;
402 body->uid = inode->i_uid;
403 body->gid = inode->i_gid;
404 body->size = inode->i_size;
405 body->mode = inode->i_mode;
406 body->nlink = inode->i_nlink;
407 body->valid = ~0; /* FIXME: should be more selective */
409 if (S_ISREG(inode->i_mode)) {
410 rc = mds_fs_get_obdo(mds, inode,
411 lustre_msg_buf(req->rq_repmsg, 1));
413 CERROR("mds_fs_get_obdo failed: %d\n", rc);
425 static int mds_statfs(struct ptlrpc_request *req)
427 struct mds_obd *mds = mds_req2mds(req);
428 struct obd_statfs *osfs;
430 int rc, size = sizeof(*osfs);
433 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen,
435 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK)) {
436 CERROR("mds: statfs lustre_pack_msg failed: rc = %d\n", rc);
440 rc = vfs_statfs(mds->mds_sb, &sfs);
442 CERROR("mds: statfs failed: rc %d\n", rc);
445 osfs = lustre_msg_buf(req->rq_repmsg, 0);
446 memset(osfs, 0, size);
447 /* FIXME: hack until the MDS gets the OST data, next month */
451 obd_statfs_pack(osfs, &sfs);
458 static int mds_open(struct ptlrpc_request *req)
461 struct mds_body *body;
463 struct vfsmount *mnt;
464 struct mds_obd *mds = mds_req2mds(req);
465 struct mds_client_info *mci;
467 struct list_head *tmp;
468 struct mds_file_data *mfd;
469 int rc, size = sizeof(*body);
472 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
473 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) {
474 CERROR("mds: out of memory\n");
475 req->rq_status = -ENOMEM;
479 mci = mds_uuid_to_mci(mds, ptlrpc_req_to_uuid(req));
481 CERROR("mds: no mci!\n");
482 req->rq_status = -ENOTCONN;
486 body = lustre_msg_buf(req->rq_reqmsg, 0);
488 /* was this animal open already? */
489 /* XXX we should only check on re-open, or do a refcount... */
490 list_for_each(tmp, &mci->mci_open_head) {
491 struct mds_file_data *fd;
492 fd = list_entry(tmp, struct mds_file_data, mfd_list);
493 if (body->extra == fd->mfd_clientfd &&
494 body->fid1.id == fd->mfd_file->f_dentry->d_inode->i_ino) {
495 CERROR("Re opening %Ld\n", body->fid1.id);
500 OBD_ALLOC(mfd, sizeof(*mfd));
502 CERROR("mds: out of memory\n");
503 req->rq_status = -ENOMEM;
507 de = mds_fid2dentry(mds, &body->fid1, &mnt);
509 req->rq_status = -ENOENT;
513 /* check if this inode has seen a delayed object creation */
514 if (req->rq_reqmsg->bufcount > 1) {
516 struct inode *inode = de->d_inode;
517 //struct iattr iattr;
521 obdo = lustre_msg_buf(req->rq_reqmsg, 1);
522 //iattr.ia_valid = ATTR_MODE;
523 //iattr.ia_mode = inode->i_mode;
525 handle = mds_fs_start(mds, de->d_inode, MDS_FSOP_SETATTR);
527 req->rq_status = -ENOMEM;
531 /* XXX error handling */
532 rc = mds_fs_set_obdo(mds, inode, handle, obdo);
533 // rc = mds_fs_setattr(mds, de, handle, &iattr);
535 struct obd_run_ctxt saved;
536 push_ctxt(&saved, &mds->mds_ctxt);
537 rc = mds_update_last_rcvd(mds, handle, req);
543 /* FIXME: need to return last_rcvd, last_committed */
545 /* FIXME: keep rc intact */
546 rc = mds_fs_commit(mds, de->d_inode, handle);
554 file = dentry_open(de, mnt, flags & ~O_DIRECT);
555 if (!file || IS_ERR(file)) {
556 req->rq_status = -EINVAL;
557 OBD_FREE(mfd, sizeof(*mfd));
561 file->private_data = mfd;
562 mfd->mfd_file = file;
563 mfd->mfd_clientfd = body->extra;
564 list_add(&mfd->mfd_list, &mci->mci_open_head);
566 body = lustre_msg_buf(req->rq_repmsg, 0);
567 body->extra = (__u64) (unsigned long)file;
571 static int mds_close(struct ptlrpc_request *req)
574 struct mds_body *body;
576 struct mds_obd *mds = mds_req2mds(req);
577 struct vfsmount *mnt;
578 struct mds_file_data *mfd;
582 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
583 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) {
584 CERROR("mds: out of memory\n");
585 req->rq_status = -ENOMEM;
589 body = lustre_msg_buf(req->rq_reqmsg, 0);
590 de = mds_fid2dentry(mds, &body->fid1, &mnt);
592 req->rq_status = -ENOENT;
596 file = (struct file *)(unsigned long)body->extra;
599 mfd = (struct mds_file_data *)file->private_data;
600 list_del(&mfd->mfd_list);
601 OBD_FREE(mfd, sizeof(*mfd));
603 req->rq_status = filp_close(file, 0);
610 static int mds_readpage(struct ptlrpc_request *req)
612 struct mds_obd *mds = mds_req2mds(req);
613 struct vfsmount *mnt;
616 struct mds_body *body;
617 struct obd_run_ctxt saved;
618 int rc, size = sizeof(*body);
621 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
622 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
623 CERROR("mds: out of memory\n");
624 GOTO(out, rc = -ENOMEM);
627 body = lustre_msg_buf(req->rq_reqmsg, 0);
628 push_ctxt(&saved, &mds->mds_ctxt);
629 de = mds_fid2dentry(mds, &body->fid1, &mnt);
631 GOTO(out_pop, rc = PTR_ERR(de));
633 CDEBUG(D_INODE, "ino %ld\n", de->d_inode->i_ino);
635 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
636 /* note: in case of an error, dentry_open puts dentry */
638 GOTO(out_pop, rc = PTR_ERR(file));
640 /* to make this asynchronous make sure that the handling function
641 doesn't send a reply when this function completes. Instead a
642 callback function would send the reply */
643 rc = mds_sendpage(req, file, body->size);
653 int mds_reint(int offset, struct ptlrpc_request *req)
656 struct mds_update_record rec;
658 rc = mds_update_unpack(req, offset, &rec);
659 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
660 CERROR("invalid record\n");
661 req->rq_status = -EINVAL;
664 /* rc will be used to interrupt a for loop over multiple records */
665 rc = mds_reint_rec(&rec, offset, req);
669 int mds_handle(struct ptlrpc_request *req)
674 rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
675 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
676 CERROR("lustre_mds: Invalid request\n");
680 if (req->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) {
681 CERROR("lustre_mds: wrong packet type sent %d\n",
682 req->rq_reqmsg->type);
683 GOTO(out, rc = -EINVAL);
686 if (req->rq_reqmsg->opc != MDS_CONNECT &&
687 req->rq_export == NULL)
688 GOTO(out, rc = -ENOTCONN);
690 if (strcmp(req->rq_obd->obd_type->typ_name, "mds") != 0)
691 GOTO(out, rc = -EINVAL);
693 switch (req->rq_reqmsg->opc) {
695 CDEBUG(D_INODE, "connect\n");
696 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
697 rc = target_handle_connect(req);
701 CDEBUG(D_INODE, "disconnect\n");
702 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
703 rc = target_handle_disconnect(req);
707 CDEBUG(D_INODE, "getstatus\n");
708 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
709 rc = mds_getstatus(req);
713 CDEBUG(D_INODE, "getattr\n");
714 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETATTR_NET, 0);
715 rc = mds_getattr(0, req);
719 CDEBUG(D_INODE, "statfs\n");
720 OBD_FAIL_RETURN(OBD_FAIL_MDS_STATFS_NET, 0);
721 rc = mds_statfs(req);
725 CDEBUG(D_INODE, "readpage\n");
726 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
727 rc = mds_readpage(req);
729 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
734 int size = sizeof(struct mds_body);
735 CDEBUG(D_INODE, "reint\n");
736 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
738 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen,
741 rc = req->rq_status = -ENOMEM;
744 rc = mds_reint(0, req);
745 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET_REP, 0);
750 CDEBUG(D_INODE, "open\n");
751 OBD_FAIL_RETURN(OBD_FAIL_MDS_OPEN_NET, 0);
756 CDEBUG(D_INODE, "close\n");
757 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
762 rc = ptlrpc_error(req->rq_svc, req);
768 /* Still not 100% sure whether we should reply with the server
769 * last_rcvd or that of this client. I'm not sure it even makes
770 * a difference on a per-client basis, because last_rcvd is global
771 * and we are not supposed to allow transactions while in recovery.
774 CERROR("mds: processing error %d\n", rc);
775 ptlrpc_error(req->rq_svc, req);
777 struct mds_obd *mds = mds_req2mds(req);
778 req->rq_repmsg->last_rcvd = HTON__u64(mds->mds_last_rcvd);
779 req->rq_repmsg->last_committed =
780 HTON__u64(mds->mds_last_committed);
781 CDEBUG(D_INFO, "last_rcvd %Lu, last_committed %Lu, xid %d\n",
782 (unsigned long long)mds->mds_last_rcvd,
783 (unsigned long long)mds->mds_last_committed,
784 cpu_to_le32(req->rq_xid));
785 CDEBUG(D_NET, "sending reply\n");
786 ptlrpc_reply(req->rq_svc, req);
791 /* Update the server data on disk. This stores the new mount_count and
792 * also the last_rcvd value to disk. If we don't have a clean shutdown,
793 * then the server last_rcvd value may be less than that of the clients.
794 * This will alert us that we may need to do client recovery.
797 int mds_update_server_data(struct mds_obd *mds)
799 struct obd_run_ctxt saved;
800 struct mds_server_data *msd = mds->mds_server_data;
801 struct file *filp = mds->mds_rcvd_filp;
805 msd->msd_last_rcvd = cpu_to_le64(mds->mds_last_rcvd);
806 msd->msd_mount_count = cpu_to_le64(mds->mds_mount_count);
808 CDEBUG(D_SUPER, "MDS mount_count is %Lu, last_rcvd is %Lu\n",
809 (unsigned long long)mds->mds_mount_count,
810 (unsigned long long)mds->mds_last_rcvd);
811 push_ctxt(&saved, &mds->mds_ctxt);
812 rc = lustre_fwrite(filp, (char *)msd, sizeof(*msd), &off);
813 if (rc != sizeof(*msd)) {
814 CERROR("error writing MDS server data: rc = %d\n", rc);
819 rc = fsync_dev(filp->f_dentry->d_inode->i_rdev);
822 CERROR("error flushing MDS server data: rc = %d\n", rc);
827 /* Do recovery actions for the MDS */
828 static int mds_recover(struct obd_device *obddev)
830 struct mds_obd *mds = &obddev->u.mds;
833 /* This happens at the end when recovery is complete */
834 ++mds->mds_mount_count;
835 rc = mds_update_server_data(mds);
841 /* mount the file system (secretly) */
842 static int mds_setup(struct obd_device *obddev, obd_count len, void *buf)
844 struct obd_ioctl_data* data = buf;
845 struct obd_export *export;
846 struct mds_obd *mds = &obddev->u.mds;
847 struct vfsmount *mnt;
852 #ifdef CONFIG_DEV_RDONLY
855 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2)
856 GOTO(err_dec, rc = -EINVAL);
858 mds->mds_fstype = strdup(data->ioc_inlbuf2);
860 mnt = do_kern_mount(mds->mds_fstype, 0, data->ioc_inlbuf1, NULL);
863 CERROR("do_kern_mount failed: rc = %d\n", rc);
867 mds->mds_sb = mnt->mnt_root->d_inode->i_sb;
869 GOTO(err_put, rc = -ENODEV);
871 rc = mds_fs_setup(mds, mnt);
873 CERROR("MDS filesystem method init failed: rc = %d\n", rc);
877 mds->mds_service = ptlrpc_init_svc(64 * 1024, MDS_REQUEST_PORTAL,
878 MDC_REPLY_PORTAL, "self",mds_handle);
879 if (!mds->mds_service) {
880 CERROR("failed to start service\n");
881 GOTO(err_fs, rc = -EINVAL);
884 rc = ptlrpc_start_thread(obddev, mds->mds_service, "lustre_mds");
886 CERROR("cannot start thread: rc = %d\n", rc);
891 mds->mds_ldlm_conn = ptlrpc_uuid_to_connection("self");
892 if (!mds->mds_ldlm_conn) {
894 GOTO(err_thread, rc);
897 obddev->obd_namespace =
898 ldlm_namespace_new("mds_server", LDLM_NAMESPACE_SERVER);
899 if (obddev->obd_namespace == NULL) {
902 GOTO(err_thread, rc);
905 mds->mds_local_namespace =
906 ldlm_namespace_new("mds_client", LDLM_NAMESPACE_CLIENT);
907 if (mds->mds_local_namespace == NULL) {
910 GOTO(err_thread, rc);
913 OBD_ALLOC(mds->mds_ldlm_client, sizeof(*mds->mds_ldlm_client));
914 if (mds->mds_ldlm_client == NULL) {
917 GOTO(err_thread, rc);
919 ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
920 mds->mds_ldlm_client);
921 mds->mds_ldlm_client->cli_target_devno = obddev->obd_minor;
922 mds->mds_ldlm_client->cli_name = "mds ldlm";
924 rc = mds_recover(obddev);
926 GOTO(err_thread, rc);
928 rc = gen_connect(&mds->mds_connh, obddev);
930 GOTO(err_thread, rc);
931 export = gen_client(&mds->mds_connh);
934 export->export_connection = mds->mds_ldlm_conn;
941 ptlrpc_stop_all_threads(mds->mds_service);
943 ptlrpc_unregister_service(mds->mds_service);
948 mntput(mds->mds_vfsmnt);
952 kfree(mds->mds_fstype);
958 static int mds_cleanup(struct obd_device * obddev)
960 struct super_block *sb;
961 struct mds_obd *mds = &obddev->u.mds;
964 gen_disconnect(&mds->mds_connh);
967 if ( !list_empty(&obddev->obd_exports) ) {
968 CERROR("still has exports!\n");
972 ptlrpc_stop_all_threads(mds->mds_service);
973 ptlrpc_unregister_service(mds->mds_service);
979 mds_update_server_data(mds);
981 if (mds->mds_rcvd_filp) {
982 int rc = filp_close(mds->mds_rcvd_filp, 0);
983 mds->mds_rcvd_filp = NULL;
986 CERROR("last_rcvd file won't close, rc=%d\n", rc);
990 mntput(mds->mds_vfsmnt);
992 kfree(mds->mds_fstype);
994 ldlm_namespace_free(mds->mds_local_namespace);
995 ldlm_namespace_free(obddev->obd_namespace);
997 if (mds->mds_ldlm_conn != NULL)
998 ptlrpc_put_connection(mds->mds_ldlm_conn);
1000 OBD_FREE(mds->mds_ldlm_client, sizeof(*mds->mds_ldlm_client));
1003 #ifdef CONFIG_DEV_RDONLY
1004 dev_clear_rdonly(2);
1006 mds_fs_cleanup(mds);
1012 /* use obd ops to offer management infrastructure */
1013 static struct obd_ops mds_obd_ops = {
1014 o_connect: mds_connect,
1015 o_disconnect: mds_disconnect,
1017 o_cleanup: mds_cleanup,
1020 static int __init mds_init(void)
1022 inter_module_register("mds_reint", THIS_MODULE, &mds_reint);
1023 inter_module_register("mds_getattr_name", THIS_MODULE,
1025 obd_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
1029 static void __exit mds_exit(void)
1031 inter_module_unregister("mds_reint");
1032 inter_module_unregister("mds_getattr_name");
1033 obd_unregister_type(LUSTRE_MDS_NAME);
1036 MODULE_AUTHOR("Cluster File Systems <info@clusterfs.com>");
1037 MODULE_DESCRIPTION("Lustre Metadata Server (MDS) v0.01");
1038 MODULE_LICENSE("GPL");
1040 module_init(mds_init);
1041 module_exit(mds_exit);