Whamcloud - gitweb
aa04a1a628b202649c56c65d4692640884c90fea
[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 #define EXPORT_SYMTAB
23 #define DEBUG_SUBSYSTEM S_OSC
24
25 #ifdef __KERNEL__
26 # include <linux/module.h>
27 # include <linux/obd.h>
28 # include <linux/obd_ost.h>
29 # include <linux/lustre_net.h>
30 # include <linux/lustre_dlm.h>
31
32 /* convert a pathname into a kdev_t */
33 static kdev_t path2dev(char *path)
34 {
35         struct dentry *dentry;
36         struct nameidata nd;
37         kdev_t dev;
38         KDEVT_VAL(dev, 0);
39
40         if (!path_init(path, LOOKUP_FOLLOW, &nd))
41                 return 0;
42
43         if (path_walk(path, &nd))
44                 return 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 obd_ioctl_data* data = buf;
58         struct client_obd *cli = &obddev->u.cli;
59         ENTRY;
60
61         if (data->ioc_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(data->ioc_inlbuf3);
69         if (!kdev_t_to_nr(cli->cl_sandev)) {
70                 CERROR("%s seems not a valid SAN device\n", data->ioc_inlbuf3);
71                 RETURN(-EINVAL);
72         }
73
74         RETURN(0);
75 }
76 #endif