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 static int mds_sendpage(struct ptlrpc_request *req, struct file *file,
34 mm_segment_t oldfs = get_fs();
35 struct ptlrpc_bulk_desc *desc;
36 struct ptlrpc_bulk_page *bulk;
40 desc = ptlrpc_prep_bulk(req->rq_connection);
42 GOTO(out, rc = -ENOMEM);
44 bulk = ptlrpc_prep_bulk_page(desc);
46 GOTO(cleanup_bulk, rc = -ENOMEM);
48 OBD_ALLOC(buf, PAGE_SIZE);
50 GOTO(cleanup_bulk, rc = -ENOMEM);
53 rc = mds_fs_readpage(&req->rq_obd->u.mds, file, buf, PAGE_SIZE,
58 GOTO(cleanup_buf, rc = -EIO);
60 bulk->b_xid = req->rq_xid;
62 bulk->b_buflen = PAGE_SIZE;
63 desc->b_portal = MDS_BULK_PORTAL;
65 rc = ptlrpc_send_bulk(desc);
67 GOTO(cleanup_buf, rc);
69 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE)) {
70 CERROR("obd_fail_loc=%x, fail operation rc=%d\n",
71 OBD_FAIL_MDS_SENDPAGE, rc);
72 ptlrpc_abort_bulk(desc);
73 GOTO(cleanup_buf, rc);
76 wait_event_interruptible(desc->b_waitq, ptlrpc_check_bulk_sent(desc));
77 if (desc->b_flags & PTL_RPC_FL_INTR)
78 GOTO(cleanup_buf, rc = -EINTR);
82 OBD_FREE(buf, PAGE_SIZE);
84 ptlrpc_free_bulk(desc);
89 struct dentry *mds_fid2dentry(struct mds_obd *mds, struct ll_fid *fid,
90 struct vfsmount **mnt)
93 struct super_block *sb = mds->mds_sb;
94 unsigned long ino = fid->id;
95 __u32 generation = fid->generation;
98 struct dentry *result;
101 RETURN(ERR_PTR(-ESTALE));
103 inode = iget(sb, ino);
105 RETURN(ERR_PTR(-ENOMEM));
107 CDEBUG(D_DENTRY, "--> mds_fid2dentry: sb %p\n", inode->i_sb);
109 if (is_bad_inode(inode) ||
110 (generation && inode->i_generation != generation)) {
111 /* we didn't find the right inode.. */
112 CERROR("bad inode %lu, link: %d ct: %d or version %u/%u\n",
113 inode->i_ino, inode->i_nlink,
114 atomic_read(&inode->i_count), inode->i_generation,
118 RETURN(ERR_PTR(-ESTALE));
121 /* now to find a dentry.
122 * If possible, get a well-connected one
125 *mnt = mds->mds_vfsmnt;
126 spin_lock(&dcache_lock);
127 for (lp = inode->i_dentry.next; lp != &inode->i_dentry ; lp=lp->next) {
128 result = list_entry(lp,struct dentry, d_alias);
129 if (! (result->d_flags & DCACHE_NFSD_DISCONNECTED)) {
131 result->d_vfs_flags |= DCACHE_REFERENCED;
132 spin_unlock(&dcache_lock);
139 spin_unlock(&dcache_lock);
140 result = d_alloc_root(inode);
141 if (result == NULL) {
143 return ERR_PTR(-ENOMEM);
147 result->d_flags |= DCACHE_NFSD_DISCONNECTED;
151 static int mds_connect(struct ptlrpc_request *req)
158 uuid = lustre_msg_buf(req->rq_reqmsg, 0);
159 if (req->rq_reqmsg->buflens[0] > 37) {
161 req->rq_status = -EINVAL;
165 i = obd_class_name2dev(uuid);
167 req->rq_status = -ENODEV;
171 mds = &(obd_dev[i].u.mds);
172 if (mds != &(req->rq_obd->u.mds)) {
173 CERROR("device %d (%s) is not an mds\n", i, uuid);
174 req->rq_status = -ENODEV;
178 CDEBUG(D_INFO, "MDS connect from UUID '%s'\n",
179 ptlrpc_req_to_uuid(req));
180 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
181 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_CONNECT_PACK)) {
182 req->rq_status = -ENOMEM;
185 req->rq_repmsg->target_id = i;
190 /* FIXME: the error cases need fixing to avoid leaks */
191 static int mds_getstatus(struct mds_obd *mds, struct ptlrpc_request *req)
193 struct mds_body *body;
194 struct mds_client_info *mci;
195 struct mds_client_data *mcd;
196 int rc, size = sizeof(*body);
199 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
200 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETSTATUS_PACK)) {
201 CERROR("mds: out of memory for message: size=%d\n", size);
202 req->rq_status = -ENOMEM;
206 body = lustre_msg_buf(req->rq_reqmsg, 0);
207 mds_unpack_body(body);
208 /* Anything we need to do here with the client's trans no or so? */
210 body = lustre_msg_buf(req->rq_repmsg, 0);
211 memcpy(&body->fid1, &mds->mds_rootfid, sizeof(body->fid1));
213 mci = mds_uuid_to_mci(mds, ptlrpc_req_to_uuid(req));
215 /* We don't have any old connection data for this client */
218 CDEBUG(D_INFO, "allocating new client data for UUID '%s'",
219 ptlrpc_req_to_uuid(req));
221 OBD_ALLOC(mcd, sizeof(*mcd));
223 CERROR("mds: out of memory for client data\n");
224 req->rq_status = -ENOMEM;
227 memcpy(mcd->mcd_uuid, ptlrpc_req_to_uuid(req),
228 sizeof(mcd->mcd_uuid));
229 rc = mds_client_add(mds, mcd, -1);
235 /* We have old connection data for this client... */
237 CDEBUG(D_INFO, "found existing data for UUID '%s' at #%d\n",
238 mcd->mcd_uuid, mci->mci_off);
240 /* mcd_last_xid is is stored in little endian on the disk and
241 mds_pack_rep_body converts it to network order */
242 body->last_xid = le32_to_cpu(mcd->mcd_last_xid);
243 mds_pack_rep_body(req);
247 static int mds_disconnect(struct mds_obd *mds, struct ptlrpc_request *req)
249 struct mds_body *body;
253 body = lustre_msg_buf(req->rq_reqmsg, 0);
255 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
262 int mds_lock_callback(struct ldlm_lock *lock, struct ldlm_lock *new,
263 void *data, int data_len, struct ptlrpc_request **reqp)
268 /* Completion AST. Do nothing */
272 if (ldlm_cli_cancel(lock->l_client, lock) < 0)
277 static int mds_getattr_name(int offset, struct ptlrpc_request *req)
279 struct mds_obd *mds = &req->rq_obd->u.mds;
280 struct mds_body *body;
281 struct dentry *de = NULL, *dchild = NULL;
283 struct ldlm_lock *lock;
284 struct lustre_handle lockh;
286 int namelen, flags, lock_mode, rc = 0;
287 __u64 res_id[3] = {0, 0, 0};
290 if (strcmp(req->rq_obd->obd_type->typ_name, "mds") != 0)
293 if (req->rq_reqmsg->bufcount <= offset + 1) {
295 GOTO(out_pre_de, rc = -EINVAL);
298 body = lustre_msg_buf(req->rq_reqmsg, offset);
299 name = lustre_msg_buf(req->rq_reqmsg, offset + 1);
300 namelen = req->rq_reqmsg->buflens[offset + 1];
301 /* requests were at offset 2, replies go back at 1 */
305 de = mds_fid2dentry(mds, &body->fid1, NULL);
308 GOTO(out_pre_de, rc = -ESTALE);
312 CDEBUG(D_INODE, "parent ino %ld\n", dir->i_ino);
314 lock_mode = (req->rq_reqmsg->opc == MDS_REINT) ? LCK_CW : LCK_PW;
315 res_id[0] = dir->i_ino;
317 rc = ldlm_local_lock_match(mds->mds_local_namespace, res_id, LDLM_PLAIN,
318 NULL, 0, lock_mode, &lockh);
320 LDLM_DEBUG_NOLOCK("enqueue res %Lu", res_id[0]);
321 rc = ldlm_cli_enqueue(mds->mds_ldlm_client, mds->mds_ldlm_conn,
322 NULL, mds->mds_local_namespace, NULL,
323 res_id, LDLM_PLAIN, NULL, 0, lock_mode,
324 &flags, (void *)mds_lock_callback,
326 if (rc != ELDLM_OK) {
327 CERROR("lock enqueue: err: %d\n", rc);
328 GOTO(out_create_de, rc = -EIO);
331 lock = lustre_handle2object(&lockh);
332 LDLM_DEBUG(lock, "matched");
334 ldlm_lock_dump((void *)(unsigned long)lockh.addr);
337 dchild = lookup_one_len(name, de, namelen - 1);
338 if (IS_ERR(dchild)) {
339 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
342 GOTO(out_create_dchild, rc = -ESTALE);
345 if (dchild->d_inode) {
346 struct mds_body *body;
348 struct inode *inode = dchild->d_inode;
349 CERROR("child exists (dir %ld, name %s, ino %ld)\n",
350 dir->i_ino, name, dchild->d_inode->i_ino);
352 body = lustre_msg_buf(req->rq_repmsg, offset);
353 mds_pack_inode2fid(&body->fid1, inode);
354 mds_pack_inode2body(body, inode);
355 if (S_ISREG(inode->i_mode)) {
356 obdo = lustre_msg_buf(req->rq_repmsg, offset + 1);
357 mds_fs_get_obdo(mds, inode, obdo);
359 /* now a normal case for intent locking */
369 lock = lustre_handle2object(&lockh);
370 ldlm_lock_decref(lock, lock_mode);
379 static int mds_getattr(int offset, struct ptlrpc_request *req)
381 struct mds_obd *mds = &req->rq_obd->u.mds;
384 struct mds_body *body;
385 int rc, size[2] = {sizeof(*body)}, bufcount = 1;
388 body = lustre_msg_buf(req->rq_reqmsg, offset);
389 de = mds_fid2dentry(mds, &body->fid1, NULL);
391 req->rq_status = -ENOENT;
396 if (S_ISREG(body->fid1.f_type)) {
398 size[1] = sizeof(struct obdo);
399 } else if (body->valid & OBD_MD_LINKNAME) {
401 size[1] = inode->i_size;
404 rc = lustre_pack_msg(bufcount, size, NULL, &req->rq_replen,
406 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_GETATTR_PACK)) {
407 CERROR("mds: out of memory\n");
408 req->rq_status = -ENOMEM;
409 GOTO(out, rc = -ENOMEM);
412 if (body->valid & OBD_MD_LINKNAME) {
413 char *tmp = lustre_msg_buf(req->rq_repmsg, 1);
418 rc = inode->i_op->readlink(de, tmp, size[1]);
423 CERROR("readlink failed: %d\n", rc);
428 body = lustre_msg_buf(req->rq_repmsg, 0);
429 body->ino = inode->i_ino;
430 body->generation = inode->i_generation;
431 body->atime = inode->i_atime;
432 body->ctime = inode->i_ctime;
433 body->mtime = inode->i_mtime;
434 body->uid = inode->i_uid;
435 body->gid = inode->i_gid;
436 body->size = inode->i_size;
437 body->mode = inode->i_mode;
438 body->nlink = inode->i_nlink;
439 body->valid = ~0; /* FIXME: should be more selective */
441 if (S_ISREG(inode->i_mode)) {
442 rc = mds_fs_get_obdo(mds, inode,
443 lustre_msg_buf(req->rq_repmsg, 1));
446 CERROR("mds_fs_get_obdo failed: %d\n", rc);
455 static int mds_open(struct ptlrpc_request *req)
458 struct mds_body *body;
460 struct vfsmount *mnt;
461 struct mds_obd *mds = &req->rq_obd->u.mds;
462 struct mds_client_info *mci;
464 struct list_head *tmp;
465 struct mds_file_data *mfd;
466 int rc, size = sizeof(*body);
469 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
470 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_OPEN_PACK)) {
471 CERROR("mds: out of memory\n");
472 req->rq_status = -ENOMEM;
476 mci = mds_uuid_to_mci(mds, ptlrpc_req_to_uuid(req));
478 CERROR("mds: no mci!\n");
479 req->rq_status = -ENOTCONN;
483 body = lustre_msg_buf(req->rq_reqmsg, 0);
485 /* was this animal open already? */
486 list_for_each(tmp, &mci->mci_open_head) {
487 struct mds_file_data *fd;
488 fd = list_entry(tmp, struct mds_file_data, mfd_list);
489 if (body->extra == fd->mfd_clientfd &&
490 body->fid1.id == fd->mfd_file->f_dentry->d_inode->i_ino) {
491 CERROR("Re opening %Ld\n", body->fid1.id);
496 OBD_ALLOC(mfd, sizeof(*mfd));
498 CERROR("mds: out of memory\n");
499 req->rq_status = -ENOMEM;
503 de = mds_fid2dentry(mds, &body->fid1, &mnt);
505 req->rq_status = -ENOENT;
509 /* check if this inode has seen a delayed object creation */
510 if (req->rq_reqmsg->bufcount > 1) {
512 struct inode *inode = de->d_inode;
517 obdo = lustre_msg_buf(req->rq_reqmsg, 1);
518 iattr.ia_valid = ATTR_MODE;
519 iattr.ia_mode = inode->i_mode;
521 handle = mds_fs_start(mds, de->d_inode, MDS_FSOP_SETATTR);
523 req->rq_status = -ENOMEM;
527 /* XXX error handling */
528 rc = mds_fs_set_obdo(mds, inode, handle, obdo);
529 rc = mds_fs_setattr(mds, de, handle, &iattr);
531 rc = mds_update_last_rcvd(mds, handle, req);
536 /* FIXME: need to return last_rcvd, last_committed */
538 /* FIXME: keep rc intact */
539 rc = mds_fs_commit(mds, de->d_inode, handle);
547 file = dentry_open(de, mnt, flags & ~O_DIRECT);
548 if (!file || IS_ERR(file)) {
549 req->rq_status = -EINVAL;
550 OBD_FREE(mfd, sizeof(*mfd));
554 file->private_data = mfd;
555 mfd->mfd_file = file;
556 mfd->mfd_clientfd = body->extra;
557 list_add(&mfd->mfd_list, &mci->mci_open_head);
559 body = lustre_msg_buf(req->rq_repmsg, 0);
560 body->extra = (__u64) (unsigned long)file;
565 int mds_close(struct ptlrpc_request *req)
568 struct mds_body *body;
570 struct mds_obd *mds = &req->rq_obd->u.mds;
571 struct vfsmount *mnt;
572 struct mds_file_data *mfd;
576 rc = lustre_pack_msg(0, NULL, NULL, &req->rq_replen, &req->rq_repmsg);
577 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_CLOSE_PACK)) {
578 CERROR("mds: out of memory\n");
579 req->rq_status = -ENOMEM;
583 body = lustre_msg_buf(req->rq_reqmsg, 0);
584 de = mds_fid2dentry(mds, &body->fid1, &mnt);
586 req->rq_status = -ENOENT;
590 file = (struct file *)(unsigned long)body->extra;
593 mfd = (struct mds_file_data *)file->private_data;
594 list_del(&mfd->mfd_list);
595 OBD_FREE(mfd, sizeof(*mfd));
597 req->rq_status = filp_close(file, 0);
604 static int mds_readpage(struct mds_obd *mds, struct ptlrpc_request *req)
606 struct vfsmount *mnt;
609 struct mds_body *body;
610 int rc, size = sizeof(*body);
613 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen, &req->rq_repmsg);
614 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_READPAGE_PACK)) {
615 CERROR("mds: out of memory\n");
616 req->rq_status = -ENOMEM;
620 body = lustre_msg_buf(req->rq_reqmsg, 0);
621 de = mds_fid2dentry(mds, &body->fid1, &mnt);
623 req->rq_status = PTR_ERR(de);
627 CDEBUG(D_INODE, "ino %ld\n", de->d_inode->i_ino);
629 file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);
630 /* note: in case of an error, dentry_open puts dentry */
632 req->rq_status = PTR_ERR(file);
636 /* to make this asynchronous make sure that the handling function
637 doesn't send a reply when this function completes. Instead a
638 callback function would send the reply */
639 rc = mds_sendpage(req, file, body->size);
646 int mds_reint(int offset, struct ptlrpc_request *req)
649 struct mds_update_record rec;
651 rc = mds_update_unpack(req, offset, &rec);
652 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {
653 CERROR("invalid record\n");
654 req->rq_status = -EINVAL;
657 /* rc will be used to interrupt a for loop over multiple records */
658 rc = mds_reint_rec(&rec, offset, req);
662 int mds_handle(struct obd_device *dev, struct ptlrpc_service *svc,
663 struct ptlrpc_request *req)
669 rc = lustre_unpack_msg(req->rq_reqmsg, req->rq_reqlen);
670 if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_HANDLE_UNPACK)) {
671 CERROR("lustre_mds: Invalid request\n");
675 if (req->rq_reqmsg->type != PTL_RPC_MSG_REQUEST) {
676 CERROR("lustre_mds: wrong packet type sent %d\n",
677 req->rq_reqmsg->type);
678 GOTO(out, rc = -EINVAL);
681 if (req->rq_reqmsg->opc != MDS_CONNECT) {
682 int id = req->rq_reqmsg->target_id;
683 struct obd_device *obddev;
684 if (id < 0 || id > MAX_OBD_DEVICES)
685 GOTO(out, rc = -ENODEV);
686 obddev = &obd_dev[id];
687 if (strcmp(obddev->obd_type->typ_name, "mds") != 0)
688 GOTO(out, rc = -EINVAL);
689 mds = &obddev->u.mds;
690 req->rq_obd = obddev;
693 switch (req->rq_reqmsg->opc) {
695 CDEBUG(D_INODE, "connect\n");
696 OBD_FAIL_RETURN(OBD_FAIL_MDS_CONNECT_NET, 0);
697 rc = mds_connect(req);
701 CDEBUG(D_INODE, "disconnect\n");
702 OBD_FAIL_RETURN(OBD_FAIL_MDS_DISCONNECT_NET, 0);
703 rc = mds_disconnect(mds, req);
707 CDEBUG(D_INODE, "getstatus\n");
708 OBD_FAIL_RETURN(OBD_FAIL_MDS_GETSTATUS_NET, 0);
709 rc = mds_getstatus(mds, 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, "readpage\n");
720 OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_NET, 0);
721 rc = mds_readpage(mds, req);
723 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SENDPAGE))
728 int size = sizeof(struct mds_body);
729 CDEBUG(D_INODE, "reint\n");
730 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET, 0);
732 rc = lustre_pack_msg(1, &size, NULL, &req->rq_replen,
735 rc = req->rq_status = -ENOMEM;
738 rc = mds_reint(0, req);
739 OBD_FAIL_RETURN(OBD_FAIL_MDS_REINT_NET_REP, 0);
744 CDEBUG(D_INODE, "open\n");
745 OBD_FAIL_RETURN(OBD_FAIL_MDS_OPEN_NET, 0);
750 CDEBUG(D_INODE, "close\n");
751 OBD_FAIL_RETURN(OBD_FAIL_MDS_CLOSE_NET, 0);
756 rc = ptlrpc_error(svc, req);
762 /* Still not 100% sure whether we should reply with the server
763 * last_rcvd or that of this client. I'm not sure it even makes
764 * a difference on a per-client basis, because last_rcvd is global
765 * and we are not supposed to allow transactions while in recovery.
768 ptlrpc_error(svc, req);
770 req->rq_repmsg->last_rcvd = HTON__u64(mds->mds_last_rcvd);
771 req->rq_repmsg->last_committed =
772 HTON__u64(mds->mds_last_committed);
773 CDEBUG(D_INFO, "last_rcvd %Lu, last_committed %Lu, xid %d\n",
774 (unsigned long long)mds->mds_last_rcvd,
775 (unsigned long long)mds->mds_last_committed,
776 cpu_to_le32(req->rq_xid));
777 CDEBUG(D_NET, "sending reply\n");
778 ptlrpc_reply(svc, req);
784 /* Update the server data on disk. This stores the new mount_count and
785 * also the last_rcvd value to disk. If we don't have a clean shutdown,
786 * then the server last_rcvd value may be less than that of the clients.
787 * This will alert us that we may need to do client recovery.
790 int mds_update_server_data(struct mds_obd *mds)
792 struct obd_run_ctxt saved;
793 struct mds_server_data *msd = mds->mds_server_data;
794 struct file *filp = mds->mds_rcvd_filp;
798 msd->msd_last_rcvd = cpu_to_le64(mds->mds_last_rcvd);
799 msd->msd_mount_count = cpu_to_le64(mds->mds_mount_count);
801 CDEBUG(D_SUPER, "MDS mount_count is %Lu, last_rcvd is %Lu\n",
802 (unsigned long long)mds->mds_mount_count,
803 (unsigned long long)mds->mds_last_rcvd);
804 push_ctxt(&saved, &mds->mds_ctxt);
805 rc = lustre_fwrite(filp, (char *)msd, sizeof(*msd), &off);
806 if (rc != sizeof(*msd)) {
807 CERROR("error writing MDS server data: rc = %d\n", rc);
812 rc = fsync_dev(filp->f_dentry->d_inode->i_rdev);
815 CERROR("error flushing MDS server data: rc = %d\n", rc);
820 /* Do recovery actions for the MDS */
821 static int mds_recover(struct obd_device *obddev)
823 struct mds_obd *mds = &obddev->u.mds;
826 /* This happens at the end when recovery is complete */
827 ++mds->mds_mount_count;
828 rc = mds_update_server_data(mds);
834 /* mount the file system (secretly) */
835 static int mds_setup(struct obd_device *obddev, obd_count len, void *buf)
837 struct obd_ioctl_data* data = buf;
838 struct mds_obd *mds = &obddev->u.mds;
839 struct vfsmount *mnt;
844 #ifdef CONFIG_DEV_RDONLY
847 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2)
848 GOTO(err_dec, rc = -EINVAL);
850 mds->mds_fstype = strdup(data->ioc_inlbuf2);
852 mnt = do_kern_mount(mds->mds_fstype, 0, data->ioc_inlbuf1, NULL);
855 CERROR("do_kern_mount failed: rc = %d\n", rc);
859 mds->mds_sb = mnt->mnt_root->d_inode->i_sb;
861 GOTO(err_put, rc = -ENODEV);
863 rc = mds_fs_setup(mds, mnt);
865 CERROR("MDS filesystem method init failed: rc = %d\n", rc);
869 mds->mds_service = ptlrpc_init_svc(64 * 1024,
870 MDS_REQUEST_PORTAL, MDC_REPLY_PORTAL, "self", mds_handle);
871 if (!mds->mds_service) {
872 CERROR("failed to start service\n");
873 GOTO(err_fs, rc = -EINVAL);
876 rc = ptlrpc_start_thread(obddev, mds->mds_service, "lustre_mds");
878 CERROR("cannot start thread: rc = %d\n", rc);
883 mds->mds_ldlm_conn = ptlrpc_uuid_to_connection("self");
884 if (!mds->mds_ldlm_conn) {
886 GOTO(err_thread, rc);
889 obddev->obd_namespace =
890 ldlm_namespace_new("mds_server", LDLM_NAMESPACE_SERVER);
891 if (obddev->obd_namespace == NULL) {
894 GOTO(err_thread, rc);
897 mds->mds_local_namespace =
898 ldlm_namespace_new("mds_client", LDLM_NAMESPACE_CLIENT);
899 if (mds->mds_local_namespace == NULL) {
902 GOTO(err_thread, rc);
905 OBD_ALLOC(mds->mds_ldlm_client, sizeof(*mds->mds_ldlm_client));
906 if (mds->mds_ldlm_client == NULL) {
909 GOTO(err_thread, rc);
911 ptlrpc_init_client(NULL, NULL, LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
912 mds->mds_ldlm_client);
913 mds->mds_ldlm_client->cli_target_devno = obddev->obd_minor;
914 mds->mds_ldlm_client->cli_name = "mds ldlm";
916 rc = mds_recover(obddev);
918 GOTO(err_thread, rc);
923 ptlrpc_stop_all_threads(mds->mds_service);
925 rpc_unregister_service(mds->mds_service);
926 OBD_FREE(mds->mds_service, sizeof(*mds->mds_service));
931 mntput(mds->mds_vfsmnt);
935 kfree(mds->mds_fstype);
941 static int mds_cleanup(struct obd_device * obddev)
943 struct super_block *sb;
944 struct mds_obd *mds = &obddev->u.mds;
948 if ( !list_empty(&obddev->obd_gen_clients) ) {
949 CERROR("still has clients!\n");
953 ptlrpc_stop_all_threads(mds->mds_service);
954 rpc_unregister_service(mds->mds_service);
955 if (!list_empty(&mds->mds_service->srv_reqs)) {
956 // XXX reply with errors and clean up
957 CERROR("Request list not empty!\n");
959 OBD_FREE(mds->mds_service, sizeof(*mds->mds_service));
965 mds_update_server_data(mds);
967 if (mds->mds_rcvd_filp) {
968 int rc = filp_close(mds->mds_rcvd_filp, 0);
969 mds->mds_rcvd_filp = NULL;
972 CERROR("last_rcvd file won't close, rc=%d\n", rc);
976 mntput(mds->mds_vfsmnt);
978 kfree(mds->mds_fstype);
980 ldlm_namespace_free(mds->mds_local_namespace);
981 ldlm_namespace_free(obddev->obd_namespace);
983 if (mds->mds_ldlm_conn != NULL)
984 ptlrpc_put_connection(mds->mds_ldlm_conn);
986 OBD_FREE(mds->mds_ldlm_client, sizeof(*mds->mds_ldlm_client));
989 #ifdef CONFIG_DEV_RDONLY
998 /* use obd ops to offer management infrastructure */
999 static struct obd_ops mds_obd_ops = {
1001 o_cleanup: mds_cleanup,
1004 static int __init mds_init(void)
1006 inter_module_register("mds_reint", THIS_MODULE, &mds_reint);
1007 inter_module_register("mds_getattr_name", THIS_MODULE,
1009 obd_register_type(&mds_obd_ops, LUSTRE_MDS_NAME);
1013 static void __exit mds_exit(void)
1015 inter_module_unregister("mds_reint");
1016 inter_module_unregister("mds_getattr_name");
1017 obd_unregister_type(LUSTRE_MDS_NAME);
1020 MODULE_AUTHOR("Cluster File Systems <info@clusterfs.com>");
1021 MODULE_DESCRIPTION("Lustre Metadata Server (MDS) v0.01");
1022 MODULE_LICENSE("GPL");
1024 module_init(mds_init);
1025 module_exit(mds_exit);