Whamcloud - gitweb
current branches now use lnet from HEAD
[fs/lustre-release.git] / lustre / obdfilter / filter_san.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  linux/fs/obdfilter/filter_san.c
5  *
6  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
7  *   Author: Peter Braam <braam@clusterfs.com>
8  *   Author: Andreas Dilger <adilger@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org.
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 #define DEBUG_SUBSYSTEM S_FILTER
27
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/pagemap.h> // XXX kill me soon
31 #include <linux/version.h>
32
33 #include <linux/obd_class.h>
34 #include <linux/lustre_fsfilt.h>
35 #include "filter_internal.h"
36
37 /* sanobd setup methods - use a specific mount option */
38 int filter_san_setup(struct obd_device *obd, obd_count len, void *buf)
39 {
40         struct lustre_cfg *lcfg = buf;
41         unsigned long page;
42         int rc;
43         
44         if (lcfg->lcfg_bufcount < 3 || LUSTRE_CFG_BUFLEN(lcfg, 2) < 1)
45                 RETURN(-EINVAL);
46
47         /* 2.6.9 selinux wants a full option page for do_kern_mount (bug6471) */
48         page = get_zeroed_page(GFP_KERNEL);
49         if (!page)
50                 RETURN(-ENOMEM);
51
52         /* for extN/ext3 filesystem, we must mount it with 'writeback' mode */
53         if (!strcmp(lustre_cfg_string(lcfg, 2), "ldiskfs"))
54                 strcpy((void *)page, "data=writeback");
55         else if (!strcmp(lustre_cfg_string(lcfg, 2), "ext3"))
56                 strcpy((void *)page, "data=writeback,asyncdel");
57         else
58                 LBUG(); /* just a reminder */
59
60         rc = filter_common_setup(obd, len, buf, (void *)page);
61         free_page(page);
62         
63         return rc;
64 }
65
66 int filter_san_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
67                       int objcount, struct obd_ioobj *obj, int niocount,
68                       struct niobuf_remote *nb)
69 {
70         struct obd_ioobj *o = obj;
71         struct niobuf_remote *rnb = nb;
72         int rc = 0;
73         int i;
74         ENTRY;
75         LASSERT(objcount == 1);
76
77         for (i = 0; i < objcount; i++, o++) {
78                 struct dentry *dentry;
79                 struct inode *inode;
80 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
81                 sector_t (*fs_bmap)(struct address_space *, sector_t);
82 #else
83                 int (*fs_bmap)(struct address_space *, long);
84 #endif
85                 int j;
86
87                 dentry = filter_oa2dentry(exp->exp_obd, oa);
88                 if (IS_ERR(dentry))
89                         GOTO(out, rc = PTR_ERR(dentry));
90
91                 inode = dentry->d_inode;
92                 if (!inode) {
93                         CERROR("trying to BRW to non-existent file "LPU64"\n",
94                                o->ioo_id);
95                         f_dput(dentry);
96                         GOTO(out, rc = -ENOENT);
97                 }
98                 fs_bmap = inode->i_mapping->a_ops->bmap;
99
100                 for (j = 0; j < o->ioo_bufcnt; j++, rnb++) {
101                         long block;
102
103                         block = rnb->offset >> inode->i_blkbits;
104
105                         if (cmd == OBD_BRW_READ) {
106                                 block = fs_bmap(inode->i_mapping, block);
107                         } else {
108                                 loff_t newsize = rnb->offset + rnb->len;
109                                 /* fs_prep_san_write will also update inode
110                                  * size for us:
111                                  * (1) new alloced block
112                                  * (2) existed block but size extented
113                                  */
114                                 /* FIXME We could call fs_prep_san_write()
115                                  * only once for all the blocks allocation.
116                                  * Now call it once for each block, for
117                                  * simplicity. And if error happens, we
118                                  * probably need to release previous alloced
119                                  * block */
120                                 rc = fs_prep_san_write(exp->exp_obd, inode,
121                                                        &block, 1, newsize);
122                                 if (rc)
123                                         break;
124                         }
125
126                         rnb->offset = block;
127                 }
128                 f_dput(dentry);
129         }
130 out:
131         RETURN(rc);
132 }
133