Whamcloud - gitweb
mgs_handler mgs_fs_setup
[fs/lustre-release.git] / lustre / mgs / mgs_fs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  mgs/mgs_fs.c
5  *  Lustre Management Server (MGS) filesystem interface code
6  *
7  *  Copyright (C) 2002, 2003 Cluster File Systems, Inc.
8  *   Author: Nathan <nathan@clusterfs.com>
9  *   Author: LinSongtao <lincent@clusterfs.com>
10  *
11  *   This file is part of Lustre, http://www.lustre.org.
12  *
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.
16  *
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.
21  *
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.
25  */
26 #ifndef EXPORT_SYMTAB
27 # define EXPORT_SYMTAB
28 #endif
29 #define DEBUG_SUBSYSTEM S_MGS
30
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>
38 #endif
39 #include <linux/lustre_mgs.h>
40 #include <linux/obd_class.h>
41 #include <linux/obd_support.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_fsfilt.h>
44 #include <libcfs/list.h>
45
46 #include "mgs_internal.h"
47
48 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
49 {
50         struct mgs_obd *mgs = &obd->u.mgs;
51         struct lvfs_run_ctxt saved;
52         struct dentry *dentry;
53         int rc;
54         ENTRY;
55
56         rc = cleanup_group_info();
57         if (rc)
58                 RETURN(rc);
59
60         mgs->mgs_vfsmnt = mnt;
61         mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
62
63         fsfilt_setup(obd, mgs->mgs_sb);
64
65         OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
66         obd->obd_lvfs_ctxt.pwdmnt = mnt;
67         obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
68         obd->obd_lvfs_ctxt.fs = get_ds();
69         obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
70
71         /* setup the directory tree */
72         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
73
74         dentry = simple_mkdir(current->fs->pwd, "CONFIGS", 0777, 1);
75         if (IS_ERR(dentry)) 
76                 rc = PTR_ERR(dentry);
77                 CERROR("cannot create CONFIGS directory: rc = %d\n", rc);
78                 GOTO(err_pop, rc);
79         }
80
81         mgs->mgs_configs_dir = dentry;
82      
83         INIT_LIST_HEAD(&mgs->mgs_opens_logs);
84
85 err_pop:
86         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
87         return rc;
88 }
89
90 int mgs_fs_cleanup(struct obd_device *obd)
91 {
92         struct mgs_obd *mgs = &obd->u.mgs;
93         struct lvfs_run_ctxt saved;
94         int rc = 0;
95
96         if (obd->obd_fail)
97                 CERROR("%s: shutting down for failover; client state will"
98                        " be preserved.\n", obd->obd_name);
99
100         class_disconnect_exports(obd); /* cleans up client info too */
101
102         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
103
104         if (mgs->mgs_configs_dir) {
105                 l_dput(mgs->mgs_configs_dir);
106                 mgs->mgs_configs_dir = NULL;
107         }
108
109         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
110
111         return rc;
112 }
113