Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[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 = KDEVT_INIT(0);
38
39         if (!path_init(path, LOOKUP_FOLLOW, &nd))
40                 return 0;
41
42         if (path_walk(path, &nd))
43                 return 0;
44
45         dentry = nd.dentry;
46         if (dentry->d_inode && !is_bad_inode(dentry->d_inode) &&
47             S_ISBLK(dentry->d_inode->i_mode))
48                 dev = dentry->d_inode->i_rdev;
49         path_release(&nd);
50
51         return dev;
52 }
53
54 int client_sanobd_setup(struct obd_device *obddev, obd_count len, void *buf)
55 {
56         struct obd_ioctl_data* data = buf;
57         struct client_obd *cli = &obddev->u.cli;
58         ENTRY;
59
60         if (data->ioc_inllen3 < 1) {
61                 CERROR("setup requires a SAN device pathname\n");
62                 RETURN(-EINVAL);
63         }
64
65         client_obd_setup(obddev, len, buf);
66
67         cli->cl_sandev = path2dev(data->ioc_inlbuf3);
68         if (!kdev_t_to_nr(cli->cl_sandev)) {
69                 CERROR("%s seems not a valid SAN device\n", data->ioc_inlbuf3);
70                 RETURN(-EINVAL);
71         }
72
73         RETURN(0);
74 }
75 #endif