Whamcloud - gitweb
b=3031
[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/dcache.h>
30 # include <linux/namei.h>
31 # include <linux/obd.h>
32 # include <linux/obd_ost.h>
33 # include <linux/lustre_net.h>
34 # include <linux/lustre_dlm.h>
35 # include <linux/lustre_lib.h>
36 # include <linux/lustre_compat25.h>
37
38 /* convert a pathname into a kdev_t */
39 static kdev_t path2dev(char *path)
40 {
41         struct dentry *dentry;
42         struct nameidata nd;
43         kdev_t dev = KDEVT_INIT(0);
44
45         if (ll_path_lookup(path, LOOKUP_FOLLOW, &nd))
46                 return val_to_kdev(0);
47
48         dentry = nd.dentry;
49         if (dentry->d_inode && !is_bad_inode(dentry->d_inode) &&
50             S_ISBLK(dentry->d_inode->i_mode))
51                 dev = dentry->d_inode->i_rdev;
52         path_release(&nd);
53
54         return dev;
55 }
56
57 int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf)
58 {
59         struct lustre_cfg* lcfg = buf;
60         struct client_obd *cli = &obddev->u.cli;
61         ENTRY;
62
63         if (lcfg->lcfg_inllen3 < 1) {
64                 CERROR("setup requires a SAN device pathname\n");
65                 RETURN(-EINVAL);
66         }
67
68         client_obd_setup(obddev, len, buf);
69
70         cli->cl_sandev = path2dev(lcfg->lcfg_inlbuf3);
71         if (!kdev_t_to_nr(cli->cl_sandev)) {
72                 CERROR("%s seems not a valid SAN device\n", lcfg->lcfg_inlbuf3);
73                 RETURN(-EINVAL);
74         }
75
76         RETURN(0);
77 }
78 #endif