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) 2006 Cluster File Systems, Inc.
8 * Author: Nathan Rutman <nathan@clusterfs.com>
10 * This file is part of Lustre, http://www.lustre.org.
12 * Lustre is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * Lustre is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Lustre; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_MGS
30 #include <linux/module.h>
31 #include <linux/kmod.h>
32 #include <linux/version.h>
33 #include <linux/sched.h>
34 #include <linux/lustre_quota.h>
35 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
36 #include <linux/mount.h>
38 #include <linux/obd_class.h>
39 #include <linux/obd_support.h>
40 #include <linux/lustre_disk.h>
41 #include <linux/lustre_lib.h>
42 #include <linux/lustre_fsfilt.h>
43 #include <linux/lustre_commit_confd.h>
44 #include <libcfs/list.h>
45 #include "mgs_internal.h"
47 /* Same as mds_fid2dentry */
48 /* Look up an entry by inode number. */
49 /* this function ONLY returns valid dget'd dentries with an initialized inode
51 static struct dentry *mgs_fid2dentry(struct mgs_obd *mgs,
56 struct dentry *result;
59 CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
60 (unsigned long)ino, gen, mgs->mgs_sb);
63 RETURN(ERR_PTR(-ESTALE));
65 snprintf(fid_name, sizeof(fid_name), "0x%lx", (unsigned long)ino);
67 /* under ext3 this is neither supposed to return bad inodes nor NULL
69 result = ll_lookup_one_len(fid_name, mgs->mgs_fid_de, strlen(fid_name));
73 inode = result->d_inode;
75 RETURN(ERR_PTR(-ENOENT));
77 if (inode->i_generation == 0 || inode->i_nlink == 0) {
78 LCONSOLE_WARN("Found inode with zero generation or link -- this"
79 " may indicate disk corruption (inode: %lu, link:"
80 " %lu, count: %d)\n", inode->i_ino,
81 (unsigned long)inode->i_nlink,
82 atomic_read(&inode->i_count));
84 RETURN(ERR_PTR(-ENOENT));
87 if (gen && inode->i_generation != gen) {
88 /* we didn't find the right inode.. */
89 CDEBUG(D_INODE, "found wrong generation: inode %lu, link: %lu, "
90 "count: %d, generation %u/%u\n", inode->i_ino,
91 (unsigned long)inode->i_nlink, atomic_read(&inode->i_count),
92 inode->i_generation, gen);
94 RETURN(ERR_PTR(-ENOENT));
100 static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen,
101 __u64 gr, void *data)
103 struct obd_device *obd = data;
104 return mgs_fid2dentry(&obd->u.mgs, id, gen);
107 struct lvfs_callback_ops mgs_lvfs_ops = {
108 l_fid2dentry: mgs_lvfs_fid2dentry,
111 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
113 struct mgs_obd *mgs = &obd->u.mgs;
114 struct lvfs_run_ctxt saved;
115 struct dentry *dentry;
119 // FIXME what's this?
120 rc = cleanup_group_info();
124 mgs->mgs_vfsmnt = mnt;
125 mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
127 fsfilt_setup(obd, mgs->mgs_sb);
129 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
130 obd->obd_lvfs_ctxt.pwdmnt = mnt;
131 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
132 obd->obd_lvfs_ctxt.fs = get_ds();
133 obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
135 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
137 /* Setup the configs dir */
138 dentry = simple_mkdir(current->fs->pwd, MOUNT_CONFIGS_DIR, 0777, 1);
139 if (IS_ERR(dentry)) {
140 rc = PTR_ERR(dentry);
141 CERROR("cannot create %s directory: rc = %d\n",
142 MOUNT_CONFIGS_DIR, rc);
145 mgs->mgs_configs_dir = dentry;
147 /* Need the iopen dir for fid2dentry, required by
148 LLOG_ORIGIN_HANDLE_READ_HEADER */
149 dentry = lookup_one_len("__iopen__", current->fs->pwd,
150 strlen("__iopen__"));
151 if (IS_ERR(dentry)) {
152 rc = PTR_ERR(dentry);
153 CERROR("cannot lookup __iopen__ directory: rc = %d\n", rc);
154 GOTO(err_configs, rc);
156 mgs->mgs_fid_de = dentry;
157 if (!dentry->d_inode || is_bad_inode(dentry->d_inode)) {
159 CERROR("__iopen__ directory has no inode? rc = %d\n", rc);
164 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
167 dput(mgs->mgs_fid_de);
169 dput(mgs->mgs_configs_dir);
173 int mgs_fs_cleanup(struct obd_device *obd)
175 struct mgs_obd *mgs = &obd->u.mgs;
176 struct lvfs_run_ctxt saved;
179 class_disconnect_exports(obd); /* cleans up client info too */
181 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
183 if (mgs->mgs_configs_dir) {
184 /*CERROR("configs dir dcount=%d\n",
185 atomic_read(&mgs->mgs_configs_dir->d_count));*/
186 l_dput(mgs->mgs_configs_dir);
187 mgs->mgs_configs_dir = NULL;
190 shrink_dcache_parent(mgs->mgs_fid_de);
191 /*CERROR("fid dir dcount=%d\n",
192 atomic_read(&mgs->mgs_fid_de->d_count));*/
193 dput(mgs->mgs_fid_de);
195 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);