1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre Management Server (MGS) filesystem interface code
7 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
8 * Author: Nathan <nathan@clusterfs.com>
9 * Author: LinSongtao <lincent@clusterfs.com>
11 * This file is part of Lustre, http://www.lustre.org.
13 * Lustre is free software; you can redistribute it and/or
14 * modify it under the terms of version 2 of the GNU General Public
15 * License as published by the Free Software Foundation.
17 * Lustre is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Lustre; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 # define EXPORT_SYMTAB
29 #define DEBUG_SUBSYSTEM S_MGS
31 #include <linux/module.h>
32 #include <linux/kmod.h>
33 #include <linux/version.h>
34 #include <linux/sched.h>
35 #include <linux/lustre_quota.h>
36 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
37 #include <linux/mount.h>
39 #include <linux/lustre_mgs.h>
40 #include <linux/obd_class.h>
41 #include <linux/obd_support.h>
42 #include <linux/lustre_disk.h>
43 #include <linux/lustre_lib.h>
44 #include <linux/lustre_fsfilt.h>
45 #include <linux/lustre_commit_confd.h>
46 #include <libcfs/list.h>
47 #include "mgs_internal.h"
49 /* Same as mds_fid2dentry */
50 /* Look up an entry by inode number. */
51 /* this function ONLY returns valid dget'd dentries with an initialized inode
53 static struct dentry *mgs_fid2dentry(struct mgs_obd *mgs, struct ll_fid *fid)
56 unsigned long ino = fid->id;
57 __u32 generation = fid->generation;
59 struct dentry *result;
61 CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
62 ino, generation, mgs->mgs_sb);
65 RETURN(ERR_PTR(-ESTALE));
67 snprintf(fid_name, sizeof(fid_name), "0x%lx", ino);
69 /* under ext3 this is neither supposed to return bad inodes
71 result = ll_lookup_one_len(fid_name, mgs->mgs_fid_de, strlen(fid_name));
75 inode = result->d_inode;
77 RETURN(ERR_PTR(-ENOENT));
79 if (inode->i_generation == 0 || inode->i_nlink == 0) {
80 LCONSOLE_WARN("Found inode with zero generation or link -- this"
81 " may indicate disk corruption (inode: %lu, link:"
82 " %lu, count: %d)\n", inode->i_ino,
83 (unsigned long)inode->i_nlink,
84 atomic_read(&inode->i_count));
86 RETURN(ERR_PTR(-ENOENT));
89 if (generation && inode->i_generation != generation) {
90 /* we didn't find the right inode.. */
91 CDEBUG(D_INODE, "found wrong generation: inode %lu, link: %lu, "
92 "count: %d, generation %u/%u\n", inode->i_ino,
93 (unsigned long)inode->i_nlink,
94 atomic_read(&inode->i_count), inode->i_generation,
97 RETURN(ERR_PTR(-ENOENT));
103 static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen, __u64 gr,
106 struct obd_device *obd = data;
109 fid.generation = gen;
110 return mgs_fid2dentry(&obd->u.mgs, &fid);
113 struct lvfs_callback_ops mgs_lvfs_ops = {
114 l_fid2dentry: mgs_lvfs_fid2dentry,
117 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
119 struct mgs_obd *mgs = &obd->u.mgs;
120 struct lvfs_run_ctxt saved;
121 struct dentry *dentry;
125 // FIXME what's this?
126 rc = cleanup_group_info();
130 mgs->mgs_vfsmnt = mnt;
131 mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
133 fsfilt_setup(obd, mgs->mgs_sb);
135 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
136 obd->obd_lvfs_ctxt.pwdmnt = mnt;
137 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
138 obd->obd_lvfs_ctxt.fs = get_ds();
139 obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
141 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
143 /* Setup the configs dir */
144 dentry = simple_mkdir(current->fs->pwd, MOUNT_CONFIGS_DIR, 0777, 1);
145 if (IS_ERR(dentry)) {
146 rc = PTR_ERR(dentry);
147 CERROR("cannot create %s directory: rc = %d\n",
148 MOUNT_CONFIGS_DIR, rc);
151 mgs->mgs_configs_dir = dentry;
153 /* Need the iopen dir for fid2dentry, required by
154 LLOG_ORIGIN_HANDLE_READ_HEADER */
155 dentry = lookup_one_len("__iopen__", current->fs->pwd,
156 strlen("__iopen__"));
157 if (IS_ERR(dentry)) {
158 rc = PTR_ERR(dentry);
159 CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
160 GOTO(err_configs, rc);
162 mgs->mgs_fid_de = dentry;
163 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
165 CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
170 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
173 dput(mgs->mgs_fid_de);
175 dput(mgs->mgs_configs_dir);
179 int mgs_fs_cleanup(struct obd_device *obd)
181 struct mgs_obd *mgs = &obd->u.mgs;
182 struct lvfs_run_ctxt saved;
185 class_disconnect_exports(obd); /* cleans up client info too */
187 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
189 if (mgs->mgs_configs_dir) {
190 CERROR("configs dir dcount=%d\n",
191 atomic_read(&mgs->mgs_configs_dir->d_count));
192 l_dput(mgs->mgs_configs_dir);
193 mgs->mgs_configs_dir = NULL;
196 shrink_dcache_parent(mgs->mgs_fid_de);
197 CERROR("fid dir dcount=%d\n",
198 atomic_read(&mgs->mgs_fid_de->d_count));
199 dput(mgs->mgs_fid_de);
201 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);