1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Metadata Server (MDS) filesystem interface code
7 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
8 * Author: Andreas Dilger <adilger@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_MDS
34 #include <linux/module.h>
35 #include <linux/kmod.h>
36 #include <linux/version.h>
37 #include <linux/sched.h>
38 #include <lustre_quota.h>
39 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
40 #include <linux/mount.h>
42 #include <lustre_mds.h>
43 #include <obd_class.h>
44 #include <obd_support.h>
45 #include <lustre_lib.h>
46 #include <lustre_fsfilt.h>
47 #include <lustre_disk.h>
48 #include <libcfs/list.h>
50 #include "mds_internal.h"
53 static int mds_export_stats_init(struct obd_device *obd, struct obd_export *exp)
57 rc = lprocfs_exp_setup(exp);
60 num_stats = (sizeof(*obd->obd_type->typ_ops) / sizeof(void *)) +
62 exp->exp_ops_stats = lprocfs_alloc_stats(num_stats,
63 LPROCFS_STATS_FLAG_NOPERCPU);
64 if (exp->exp_ops_stats == NULL)
66 lprocfs_init_ops_stats(LPROC_MDS_LAST, exp->exp_ops_stats);
67 mds_stats_counter_init(exp->exp_ops_stats);
68 lprocfs_register_stats(exp->exp_proc, "stats", exp->exp_ops_stats);
72 /* Add client data to the MDS. We use a bitmap to locate a free space
73 * in the last_rcvd file if cl_off is -1 (i.e. a new client).
74 * Otherwise, we have just read the data from the last_rcvd file and
77 * It should not be possible to fail adding an existing client - otherwise
78 * mds_init_server_data() callsite needs to be fixed.
80 int mds_client_add(struct obd_device *obd, struct obd_export *exp,
83 struct mds_obd *mds = &obd->u.mds;
84 struct mds_export_data *med = &exp->exp_mds_data;
85 unsigned long *bitmap = mds->mds_client_bitmap;
86 int new_client = (cl_idx == -1);
90 LASSERT(bitmap != NULL);
91 LASSERTF(cl_idx > -2, "%d\n", cl_idx);
93 /* XXX if mcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
94 if (!strcmp(med->med_mcd->mcd_uuid, obd->obd_uuid.uuid))
97 /* the bitmap operations can handle cl_idx > sizeof(long) * 8, so
98 * there's no need for extra complication here
101 cl_idx = find_first_zero_bit(bitmap, LR_MAX_CLIENTS);
103 if (cl_idx >= LR_MAX_CLIENTS ||
104 OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_CLIENT_ADD)) {
105 CERROR("no room for %u clients - fix LR_MAX_CLIENTS\n",
109 if (test_and_set_bit(cl_idx, bitmap)) {
110 cl_idx = find_next_zero_bit(bitmap, LR_MAX_CLIENTS,
115 if (test_and_set_bit(cl_idx, bitmap)) {
116 CERROR("MDS client %d: bit already set in bitmap!!\n",
122 CDEBUG(D_INFO, "client at idx %d with UUID '%s' added\n",
123 cl_idx, med->med_mcd->mcd_uuid);
125 med->med_lr_idx = cl_idx;
126 med->med_lr_off = le32_to_cpu(mds->mds_server_data->lsd_client_start) +
127 (cl_idx * le16_to_cpu(mds->mds_server_data->lsd_client_size));
128 LASSERTF(med->med_lr_off > 0, "med_lr_off = %llu\n", med->med_lr_off);
129 mds_export_stats_init(obd, exp);
132 struct lvfs_run_ctxt saved;
133 loff_t off = med->med_lr_off;
134 struct file *file = mds->mds_rcvd_filp;
137 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
138 handle = fsfilt_start(obd, file->f_dentry->d_inode,
139 FSFILT_OP_SETATTR, NULL);
140 if (IS_ERR(handle)) {
141 rc = PTR_ERR(handle);
142 CERROR("unable to start transaction: rc %d\n", rc);
144 rc = fsfilt_add_journal_cb(obd, 0, handle,
145 target_client_add_cb, exp);
147 spin_lock(&exp->exp_lock);
148 exp->exp_need_sync = 1;
149 spin_unlock(&exp->exp_lock);
151 rc = fsfilt_write_record(obd, file, med->med_mcd,
152 sizeof(*med->med_mcd),
153 &off, rc /* sync if no cb */);
154 fsfilt_commit(obd, file->f_dentry->d_inode, handle, 0);
157 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
161 CDEBUG(D_INFO, "wrote client mcd at idx %u off %llu (len %u)\n",
162 med->med_lr_idx, med->med_lr_off,
163 (unsigned int)sizeof(*med->med_mcd));
168 int mds_client_free(struct obd_export *exp)
170 struct mds_export_data *med = &exp->exp_mds_data;
171 struct mds_obd *mds = &exp->exp_obd->u.mds;
172 struct obd_device *obd = exp->exp_obd;
173 struct mds_client_data zero_mcd;
174 struct lvfs_run_ctxt saved;
182 /* XXX if mcd_uuid were a real obd_uuid, I could use obd_uuid_equals */
183 if (!strcmp(med->med_mcd->mcd_uuid, obd->obd_uuid.uuid))
186 CDEBUG(D_INFO, "freeing client at idx %u, offset %lld with UUID '%s'\n",
187 med->med_lr_idx, med->med_lr_off, med->med_mcd->mcd_uuid);
189 LASSERT(mds->mds_client_bitmap != NULL);
191 lprocfs_exp_cleanup(exp);
193 off = med->med_lr_off;
195 /* Don't clear med_lr_idx here as it is likely also unset. At worst
196 * we leak a client slot that will be cleaned on the next recovery. */
198 CERROR("%s: client idx %d has offset %lld\n",
199 obd->obd_name, med->med_lr_idx, off);
200 GOTO(free, rc = -EINVAL);
203 /* Clear the bit _after_ zeroing out the client so we don't
204 race with mds_client_add and zero out new clients.*/
205 if (!test_bit(med->med_lr_idx, mds->mds_client_bitmap)) {
206 CERROR("MDS client %u: bit already clear in bitmap!!\n",
211 if (!(exp->exp_flags & OBD_OPT_FAILOVER)) {
212 memset(&zero_mcd, 0, sizeof zero_mcd);
213 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
214 rc = fsfilt_write_record(obd, mds->mds_rcvd_filp, &zero_mcd,
215 sizeof(zero_mcd), &off,
216 (!exp->exp_libclient ||
217 exp->exp_need_sync));
218 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
220 CDEBUG(rc == 0 ? D_INFO : D_ERROR,
221 "zeroing out client %s idx %u in %s rc %d\n",
222 med->med_mcd->mcd_uuid, med->med_lr_idx, LAST_RCVD, rc);
225 if (!test_and_clear_bit(med->med_lr_idx, mds->mds_client_bitmap)) {
226 CERROR("MDS client %u: bit already clear in bitmap!!\n",
232 /* Make sure the server's last_transno is up to date. Do this
233 * after the client is freed so we know all the client's
234 * transactions have been committed. */
235 mds_update_server_data(exp->exp_obd, 0);
239 OBD_FREE(med->med_mcd, sizeof(*med->med_mcd));
245 static int mds_server_free_data(struct mds_obd *mds)
247 OBD_FREE(mds->mds_client_bitmap, LR_MAX_CLIENTS / 8);
248 OBD_FREE(mds->mds_server_data, sizeof(*mds->mds_server_data));
249 mds->mds_server_data = NULL;
254 static int mds_init_server_data(struct obd_device *obd, struct file *file)
256 struct mds_obd *mds = &obd->u.mds;
257 struct lr_server_data *lsd;
258 struct mds_client_data *mcd = NULL;
260 unsigned long last_rcvd_size = i_size_read(file->f_dentry->d_inode);
265 /* ensure padding in the struct is the correct size */
266 LASSERT(offsetof(struct lr_server_data, lsd_padding) +
267 sizeof(lsd->lsd_padding) == LR_SERVER_SIZE);
268 LASSERT(offsetof(struct mds_client_data, mcd_padding) +
269 sizeof(mcd->mcd_padding) == LR_CLIENT_SIZE);
271 OBD_ALLOC_WAIT(lsd, sizeof(*lsd));
275 OBD_ALLOC_WAIT(mds->mds_client_bitmap, LR_MAX_CLIENTS / 8);
276 if (!mds->mds_client_bitmap) {
277 OBD_FREE(lsd, sizeof(*lsd));
281 mds->mds_server_data = lsd;
283 if (last_rcvd_size == 0) {
284 LCONSOLE_WARN("%s: new disk, initializing\n", obd->obd_name);
286 memcpy(lsd->lsd_uuid, obd->obd_uuid.uuid,sizeof(lsd->lsd_uuid));
287 lsd->lsd_last_transno = 0;
288 mount_count = lsd->lsd_mount_count = 0;
289 lsd->lsd_server_size = cpu_to_le32(LR_SERVER_SIZE);
290 lsd->lsd_client_start = cpu_to_le32(LR_CLIENT_START);
291 lsd->lsd_client_size = cpu_to_le16(LR_CLIENT_SIZE);
292 lsd->lsd_feature_rocompat = cpu_to_le32(OBD_ROCOMPAT_LOVOBJID);
293 lsd->lsd_feature_incompat = cpu_to_le32(OBD_INCOMPAT_MDT);
295 rc = fsfilt_read_record(obd, file, lsd, sizeof(*lsd), &off);
297 CERROR("error reading MDS %s: rc %d\n", LAST_RCVD, rc);
300 if (strcmp(lsd->lsd_uuid, obd->obd_uuid.uuid) != 0) {
301 LCONSOLE_ERROR_MSG(0x157, "Trying to start OBD %s using"
302 " the wrong disk %s. Were the /dev/ "
303 "assignments rearranged?\n",
304 obd->obd_uuid.uuid, lsd->lsd_uuid);
305 GOTO(err_msd, rc = -EINVAL);
308 /* Assume old last_rcvd format unless I_C_LR is set */
309 if (!(lsd->lsd_feature_incompat &
310 cpu_to_le32(OBD_INCOMPAT_COMMON_LR)))
311 lsd->lsd_mount_count = lsd->lsd_compat14;
313 mount_count = le64_to_cpu(lsd->lsd_mount_count);
316 if (lsd->lsd_feature_incompat & ~cpu_to_le32(MDT_INCOMPAT_SUPP)) {
317 CERROR("%s: unsupported incompat filesystem feature(s) %x\n",
318 obd->obd_name, le32_to_cpu(lsd->lsd_feature_incompat) &
320 GOTO(err_msd, rc = -EINVAL);
322 if (lsd->lsd_feature_rocompat & ~cpu_to_le32(MDT_ROCOMPAT_SUPP)) {
323 CERROR("%s: unsupported read-only filesystem feature(s) %x\n",
324 obd->obd_name, le32_to_cpu(lsd->lsd_feature_rocompat) &
326 /* Do something like remount filesystem read-only */
327 GOTO(err_msd, rc = -EINVAL);
330 lsd->lsd_feature_compat = cpu_to_le32(OBD_COMPAT_MDT);
332 mds->mds_last_transno = le64_to_cpu(lsd->lsd_last_transno);
334 CDEBUG(D_INODE, "%s: server last_transno: "LPU64"\n",
335 obd->obd_name, mds->mds_last_transno);
336 CDEBUG(D_INODE, "%s: server mount_count: "LPU64"\n",
337 obd->obd_name, mount_count + 1);
338 CDEBUG(D_INODE, "%s: server data size: %u\n",
339 obd->obd_name, le32_to_cpu(lsd->lsd_server_size));
340 CDEBUG(D_INODE, "%s: per-client data start: %u\n",
341 obd->obd_name, le32_to_cpu(lsd->lsd_client_start));
342 CDEBUG(D_INODE, "%s: per-client data size: %u\n",
343 obd->obd_name, le32_to_cpu(lsd->lsd_client_size));
344 CDEBUG(D_INODE, "%s: last_rcvd size: %lu\n",
345 obd->obd_name, last_rcvd_size);
346 CDEBUG(D_INODE, "%s: last_rcvd clients: %lu\n", obd->obd_name,
347 last_rcvd_size <= le32_to_cpu(lsd->lsd_client_start) ? 0 :
348 (last_rcvd_size - le32_to_cpu(lsd->lsd_client_start)) /
349 le16_to_cpu(lsd->lsd_client_size));
351 if (!lsd->lsd_server_size || !lsd->lsd_client_start ||
352 !lsd->lsd_client_size) {
353 CERROR("Bad last_rcvd contents!\n");
354 GOTO(err_msd, rc = -EINVAL);
357 /* When we do a clean MDS shutdown, we save the last_transno into
358 * the header. If we find clients with higher last_transno values
359 * then those clients may need recovery done. */
360 for (cl_idx = 0, off = le32_to_cpu(lsd->lsd_client_start);
361 off < last_rcvd_size; cl_idx++) {
363 struct obd_export *exp;
364 struct mds_export_data *med;
367 OBD_ALLOC_WAIT(mcd, sizeof(*mcd));
369 GOTO(err_client, rc = -ENOMEM);
372 /* Don't assume off is incremented properly by
373 * fsfilt_read_record(), in case sizeof(*mcd)
374 * isn't the same as lsd->lsd_client_size. */
375 off = le32_to_cpu(lsd->lsd_client_start) +
376 cl_idx * le16_to_cpu(lsd->lsd_client_size);
377 rc = fsfilt_read_record(obd, file, mcd, sizeof(*mcd), &off);
379 CERROR("error reading MDS %s idx %d, off %llu: rc %d\n",
380 LAST_RCVD, cl_idx, off, rc);
381 break; /* read error shouldn't cause startup to fail */
384 if (mcd->mcd_uuid[0] == '\0') {
385 CDEBUG(D_INFO, "skipping zeroed client at offset %d\n",
390 last_transno = le64_to_cpu(mcd->mcd_last_transno) >
391 le64_to_cpu(mcd->mcd_last_close_transno) ?
392 le64_to_cpu(mcd->mcd_last_transno) :
393 le64_to_cpu(mcd->mcd_last_close_transno);
395 /* These exports are cleaned up by mds_disconnect(), so they
396 * need to be set up like real exports as mds_connect() does.
398 CDEBUG(D_HA, "RCVRNG CLIENT uuid: %s idx: %d lr: "LPU64
399 " srv lr: "LPU64" lx: "LPU64"\n", mcd->mcd_uuid, cl_idx,
400 last_transno, le64_to_cpu(lsd->lsd_last_transno),
401 le64_to_cpu(mcd->mcd_last_xid));
403 exp = class_new_export(obd, (struct obd_uuid *)mcd->mcd_uuid);
405 if (PTR_ERR(exp) == -EALREADY) {
406 /* export already exists, zero out this one */
407 mcd->mcd_uuid[0] = '\0';
409 GOTO(err_client, rc = PTR_ERR(exp));
412 med = &exp->exp_mds_data;
414 rc = mds_client_add(obd, exp, cl_idx);
415 /* can't fail for existing client */
416 LASSERTF(rc == 0, "rc = %d\n", rc);
420 spin_lock(&exp->exp_lock);
421 exp->exp_replay_needed = 1;
422 exp->exp_connecting = 0;
423 spin_unlock(&exp->exp_lock);
425 obd->obd_recoverable_clients++;
426 obd->obd_max_recoverable_clients++;
427 class_export_put(exp);
430 /* Need to check last_rcvd even for duplicated exports. */
431 CDEBUG(D_OTHER, "client at idx %d has last_transno = "LPU64"\n",
432 cl_idx, last_transno);
434 if (last_transno > mds->mds_last_transno)
435 mds->mds_last_transno = last_transno;
439 OBD_FREE(mcd, sizeof(*mcd));
441 obd->obd_last_committed = mds->mds_last_transno;
443 if (obd->obd_recoverable_clients) {
444 CWARN("RECOVERY: service %s, %d recoverable clients, "
445 "last_transno "LPU64"\n", obd->obd_name,
446 obd->obd_recoverable_clients, mds->mds_last_transno);
447 obd->obd_next_recovery_transno = obd->obd_last_committed + 1;
448 obd->obd_recovering = 1;
449 obd->obd_recovery_start = 0;
450 obd->obd_recovery_end = 0;
453 mds->mds_mount_count = mount_count + 1;
454 lsd->lsd_mount_count = lsd->lsd_compat14 =
455 cpu_to_le64(mds->mds_mount_count);
457 /* save it, so mount count and last_transno is current */
458 rc = mds_update_server_data(obd, 1);
460 GOTO(err_client, rc);
465 class_disconnect_exports(obd);
467 mds_server_free_data(mds);
471 int mds_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
473 struct mds_obd *mds = &obd->u.mds;
474 struct lvfs_run_ctxt saved;
475 struct dentry *dentry;
480 OBD_FAIL_RETURN(OBD_FAIL_MDS_FS_SETUP, -ENOENT);
482 rc = cleanup_group_info();
486 mds->mds_vfsmnt = mnt;
487 /* why not mnt->mnt_sb instead of mnt->mnt_root->d_inode->i_sb? */
488 obd->u.obt.obt_sb = mnt->mnt_root->d_inode->i_sb;
490 fsfilt_setup(obd, obd->u.obt.obt_sb);
492 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
493 obd->obd_lvfs_ctxt.pwdmnt = mnt;
494 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
495 obd->obd_lvfs_ctxt.fs = get_ds();
496 obd->obd_lvfs_ctxt.cb_ops = mds_lvfs_ops;
498 /* setup the directory tree */
499 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
500 dentry = simple_mkdir(current->fs->pwd, "ROOT", 0755, 0);
501 if (IS_ERR(dentry)) {
502 rc = PTR_ERR(dentry);
503 CERROR("cannot create ROOT directory: rc = %d\n", rc);
507 mds->mds_rootfid.id = dentry->d_inode->i_ino;
508 mds->mds_rootfid.generation = dentry->d_inode->i_generation;
509 mds->mds_rootfid.f_type = S_IFDIR;
513 dentry = lookup_one_len("__iopen__", current->fs->pwd,
514 strlen("__iopen__"));
515 if (IS_ERR(dentry)) {
516 rc = PTR_ERR(dentry);
517 CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
521 mds->mds_fid_de = dentry;
522 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
524 CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
528 dentry = simple_mkdir(current->fs->pwd, "PENDING", 0777, 1);
529 if (IS_ERR(dentry)) {
530 rc = PTR_ERR(dentry);
531 CERROR("cannot create PENDING directory: rc = %d\n", rc);
534 mds->mds_pending_dir = dentry;
537 dentry = simple_mkdir(current->fs->pwd, MDT_LOGS_DIR, 0777, 1);
538 if (IS_ERR(dentry)) {
539 rc = PTR_ERR(dentry);
540 CERROR("cannot create %s directory: rc = %d\n",
542 GOTO(err_pending, rc);
544 mds->mds_logs_dir = dentry;
547 dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
548 if (IS_ERR(dentry)) {
549 rc = PTR_ERR(dentry);
550 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
553 mds->mds_objects_dir = dentry;
555 /* open and test the last rcvd file */
556 file = filp_open(LAST_RCVD, O_RDWR | O_CREAT, 0644);
559 CERROR("cannot open/create %s file: rc = %d\n", LAST_RCVD, rc);
560 GOTO(err_objects, rc = PTR_ERR(file));
562 mds->mds_rcvd_filp = file;
563 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
564 CERROR("%s is not a regular file!: mode = %o\n", LAST_RCVD,
565 file->f_dentry->d_inode->i_mode);
566 GOTO(err_last_rcvd, rc = -ENOENT);
569 rc = mds_init_server_data(obd, file);
571 CERROR("cannot read %s: rc = %d\n", LAST_RCVD, rc);
572 GOTO(err_last_rcvd, rc);
575 /* open and test the lov objd file */
576 file = filp_open(LOV_OBJID, O_RDWR | O_CREAT, 0644);
579 CERROR("cannot open/create %s file: rc = %d\n", LOV_OBJID, rc);
580 GOTO(err_client, rc = PTR_ERR(file));
582 mds->mds_lov_objid_filp = file;
583 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
584 CERROR("%s is not a regular file!: mode = %o\n", LOV_OBJID,
585 file->f_dentry->d_inode->i_mode);
586 GOTO(err_lov_objid, rc = -ENOENT);
589 /* open and test the check io file junk */
590 file = filp_open(HEALTH_CHECK, O_RDWR | O_CREAT, 0644);
593 CERROR("cannot open/create %s file: rc = %d\n",HEALTH_CHECK,rc);
594 GOTO(err_lov_objid, rc = PTR_ERR(file));
596 mds->mds_health_check_filp = file;
597 if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {
598 CERROR("%s is not a regular file!: mode = %o\n", HEALTH_CHECK,
599 file->f_dentry->d_inode->i_mode);
600 GOTO(err_health_check, rc = -ENOENT);
602 rc = lvfs_check_io_health(obd, file);
604 GOTO(err_health_check, rc);
606 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
611 if (mds->mds_health_check_filp &&
612 filp_close(mds->mds_health_check_filp, 0))
613 CERROR("can't close %s after error\n", HEALTH_CHECK);
615 if (mds->mds_lov_objid_filp && filp_close(mds->mds_lov_objid_filp, 0))
616 CERROR("can't close %s after error\n", LOV_OBJID);
618 class_disconnect_exports(obd);
620 if (mds->mds_rcvd_filp && filp_close(mds->mds_rcvd_filp, 0))
621 CERROR("can't close %s after error\n", LAST_RCVD);
623 dput(mds->mds_objects_dir);
625 dput(mds->mds_logs_dir);
627 dput(mds->mds_pending_dir);
629 dput(mds->mds_fid_de);
634 int mds_fs_cleanup(struct obd_device *obd)
636 struct mds_obd *mds = &obd->u.mds;
637 struct lvfs_run_ctxt saved;
641 LCONSOLE_WARN("%s: shutting down for failover; client state "
642 "will be preserved.\n", obd->obd_name);
644 class_disconnect_exports(obd); /* cleans up client info too */
645 mds_server_free_data(mds);
647 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
648 if (mds->mds_rcvd_filp) {
649 rc = filp_close(mds->mds_rcvd_filp, 0);
650 mds->mds_rcvd_filp = NULL;
652 CERROR("%s file won't close, rc=%d\n", LAST_RCVD, rc);
654 if (mds->mds_lov_objid_filp) {
655 rc = filp_close(mds->mds_lov_objid_filp, 0);
656 mds->mds_lov_objid_filp = NULL;
658 CERROR("%s file won't close, rc=%d\n", LOV_OBJID, rc);
660 if (mds->mds_health_check_filp) {
661 rc = filp_close(mds->mds_health_check_filp, 0);
662 mds->mds_health_check_filp = NULL;
664 CERROR("%s file won't close, rc=%d\n", HEALTH_CHECK,rc);
666 if (mds->mds_objects_dir != NULL) {
667 l_dput(mds->mds_objects_dir);
668 mds->mds_objects_dir = NULL;
670 if (mds->mds_logs_dir) {
671 l_dput(mds->mds_logs_dir);
672 mds->mds_logs_dir = NULL;
674 if (mds->mds_pending_dir) {
675 l_dput(mds->mds_pending_dir);
676 mds->mds_pending_dir = NULL;
679 lquota_fs_cleanup(mds_quota_interface_ref, obd);
681 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
682 shrink_dcache_parent(mds->mds_fid_de);
683 dput(mds->mds_fid_de);
684 LL_DQUOT_OFF(obd->u.obt.obt_sb);
689 /* Creates an object with the same name as its fid. Because this is not at all
690 * performance sensitive, it is accomplished by creating a file, checking the
691 * fid, and renaming it. */
692 int mds_obd_create(struct obd_export *exp, struct obdo *oa,
693 struct lov_stripe_md **ea, struct obd_trans_info *oti)
695 struct mds_obd *mds = &exp->exp_obd->u.mds;
696 struct inode *parent_inode = mds->mds_objects_dir->d_inode;
697 unsigned int tmpname = ll_rand();
699 struct dentry *new_child;
700 struct lvfs_run_ctxt saved;
701 char fidname[LL_FID_NAMELEN];
703 struct lvfs_ucred ucred = { 0 };
704 int rc = 0, err, namelen;
707 /* the owner of object file should always be root */
708 cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
710 push_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
712 sprintf(fidname, "OBJECTS/%u.%u", tmpname, current->pid);
713 filp = filp_open(fidname, O_CREAT | O_EXCL, 0666);
717 CERROR("impossible object name collision %u\n",
721 CERROR("error creating tmp object %u: rc %d\n", tmpname, rc);
725 LASSERT(mds->mds_objects_dir == filp->f_dentry->d_parent);
727 oa->o_id = filp->f_dentry->d_inode->i_ino;
728 oa->o_generation = filp->f_dentry->d_inode->i_generation;
729 namelen = ll_fid2str(fidname, oa->o_id, oa->o_generation);
731 LOCK_INODE_MUTEX(parent_inode);
732 new_child = lookup_one_len(fidname, mds->mds_objects_dir, namelen);
734 if (IS_ERR(new_child)) {
735 CERROR("getting neg dentry for obj rename: %d\n", rc);
736 GOTO(out_close, rc = PTR_ERR(new_child));
738 if (new_child->d_inode != NULL) {
739 CERROR("impossible non-negative obj dentry " LPU64":%u!\n",
740 oa->o_id, oa->o_generation);
744 handle = fsfilt_start(exp->exp_obd, mds->mds_objects_dir->d_inode,
745 FSFILT_OP_RENAME, NULL);
747 GOTO(out_dput, rc = PTR_ERR(handle));
750 rc = vfs_rename(mds->mds_objects_dir->d_inode, filp->f_dentry,
751 mds->mds_objects_dir->d_inode, new_child);
754 CERROR("error renaming new object "LPU64":%u: rc %d\n",
755 oa->o_id, oa->o_generation, rc);
757 err = fsfilt_commit(exp->exp_obd, mds->mds_objects_dir->d_inode,
760 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGENER;
766 UNLOCK_INODE_MUTEX(parent_inode);
767 err = filp_close(filp, 0);
769 CERROR("closing tmpfile %u: rc %d\n", tmpname, rc);
774 pop_ctxt(&saved, &exp->exp_obd->obd_lvfs_ctxt, &ucred);
778 int mds_obd_destroy(struct obd_export *exp, struct obdo *oa,
779 struct lov_stripe_md *ea, struct obd_trans_info *oti,
780 struct obd_export *md_exp)
782 struct mds_obd *mds = &exp->exp_obd->u.mds;
783 struct inode *parent_inode = mds->mds_objects_dir->d_inode;
784 struct obd_device *obd = exp->exp_obd;
785 struct lvfs_run_ctxt saved;
786 struct lvfs_ucred ucred = { 0 };
787 char fidname[LL_FID_NAMELEN];
788 struct inode *inode = NULL;
791 int err, namelen, rc = 0;
794 cap_raise(ucred.luc_cap, CAP_SYS_RESOURCE);
795 push_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred);
797 namelen = ll_fid2str(fidname, oa->o_id, oa->o_generation);
799 LOCK_INODE_MUTEX(parent_inode);
800 de = lookup_one_len(fidname, mds->mds_objects_dir, namelen);
804 CERROR("error looking up object "LPU64" %s: rc %d\n",
805 oa->o_id, fidname, rc);
808 if (de->d_inode == NULL) {
809 CERROR("destroying non-existent object "LPU64" %s: rc %d\n",
810 oa->o_id, fidname, rc);
811 GOTO(out_dput, rc = -ENOENT);
814 /* Stripe count is 1 here since this is some MDS specific stuff
815 that is unlinked, not spanned across multiple OSTs */
816 handle = fsfilt_start_log(obd, mds->mds_objects_dir->d_inode,
817 FSFILT_OP_UNLINK, oti, 1);
820 GOTO(out_dput, rc = PTR_ERR(handle));
822 /* take a reference to protect inode from truncation within
823 vfs_unlink() context. bug 10409 */
825 atomic_inc(&inode->i_count);
826 rc = vfs_unlink(mds->mds_objects_dir->d_inode, de);
828 CERROR("error destroying object "LPU64":%u: rc %d\n",
829 oa->o_id, oa->o_generation, rc);
831 err = fsfilt_commit(obd, mds->mds_objects_dir->d_inode, handle, 0);
837 UNLOCK_INODE_MUTEX(parent_inode);
842 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &ucred);