Whamcloud - gitweb
* vibnal fixes
[fs/lustre-release.git] / lustre / osc / osc_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_OSC
26
27 #ifdef __KERNEL__
28 # include <linux/module.h>
29 # include <linux/obd.h>
30 # include <linux/obd_ost.h>
31 # include <linux/lustre_net.h>
32 # include <linux/lustre_dlm.h>
33 # include <linux/lustre_lib.h>
34 # include <linux/lustre_compat25.h>
35
36 /* convert a pathname into a kdev_t */
37 static kdev_t path2dev(char *path)
38 {
39         struct dentry *dentry;
40         struct nameidata nd;
41         kdev_t dev = KDEVT_INIT(0);
42
43         if (ll_path_lookup(path, LOOKUP_FOLLOW, &nd))
44                 return val_to_kdev(0);
45
46         dentry = nd.dentry;
47         if (dentry->d_inode && !is_bad_inode(dentry->d_inode) &&
48             S_ISBLK(dentry->d_inode->i_mode))
49                 dev = dentry->d_inode->i_rdev;
50         path_release(&nd);
51
52         return dev;
53 }
54
55 int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf)
56 {
57         struct lustre_cfg* lcfg = buf;
58         struct client_obd *cli = &obddev->u.cli;
59         ENTRY;
60
61         if (lcfg->lcfg_inllen3 < 1) {
62                 CERROR("setup requires a SAN device pathname\n");
63                 RETURN(-EINVAL);
64         }
65
66         client_obd_setup(obddev, len, buf);
67
68         cli->cl_sandev = path2dev(lcfg->lcfg_inlbuf3);
69         if (!kdev_t_to_nr(cli->cl_sandev)) {
70                 CERROR("%s seems not a valid SAN device\n", lcfg->lcfg_inlbuf3);
71                 RETURN(-EINVAL);
72         }
73
74         RETURN(0);
75 }
76 #endif