Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[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 obd_ioctl_data* data = buf;
41         char *option = NULL;
42
43         if (!data->ioc_inlbuf2)
44                 RETURN(-EINVAL);
45
46         /* for extN/ext3 filesystem, we must mount it with 'writeback' mode */
47         if (!strcmp(data->ioc_inlbuf2, "extN"))
48                 option = "data=writeback";
49         else if (!strcmp(data->ioc_inlbuf2, "ext3"))
50                 option = "data=writeback,asyncdel";
51         else
52                 LBUG(); /* just a reminder */
53
54         return filter_common_setup(obd, len, buf, option);
55 }
56
57 int filter_san_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
58                       int objcount, struct obd_ioobj *obj, int niocount,
59                       struct niobuf_remote *nb)
60 {
61         struct obd_ioobj *o = obj;
62         struct niobuf_remote *rnb = nb;
63         int rc = 0;
64         int i;
65         ENTRY;
66         LASSERT(objcount == 1);
67
68         for (i = 0; i < objcount; i++, o++) {
69                 struct dentry *dentry;
70                 struct inode *inode;
71 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
72                 sector_t (*fs_bmap)(struct address_space *, sector_t);
73 #else
74                 int (*fs_bmap)(struct address_space *, long);
75 #endif
76                 int j;
77
78                 dentry = filter_oa2dentry(exp->exp_obd, oa);
79                 if (IS_ERR(dentry))
80                         GOTO(out, rc = PTR_ERR(dentry));
81
82                 inode = dentry->d_inode;
83                 if (!inode) {
84                         CERROR("trying to BRW to non-existent file "LPU64"\n",
85                                o->ioo_id);
86                         f_dput(dentry);
87                         GOTO(out, rc = -ENOENT);
88                 }
89                 fs_bmap = inode->i_mapping->a_ops->bmap;
90
91                 for (j = 0; j < o->ioo_bufcnt; j++, rnb++) {
92                         long block;
93
94                         block = rnb->offset >> inode->i_blkbits;
95
96                         if (cmd == OBD_BRW_READ) {
97                                 block = fs_bmap(inode->i_mapping, block);
98                         } else {
99                                 loff_t newsize = rnb->offset + rnb->len;
100                                 /* fs_prep_san_write will also update inode
101                                  * size for us:
102                                  * (1) new alloced block
103                                  * (2) existed block but size extented
104                                  */
105                                 /* FIXME We could call fs_prep_san_write()
106                                  * only once for all the blocks allocation.
107                                  * Now call it once for each block, for
108                                  * simplicity. And if error happens, we
109                                  * probably need to release previous alloced
110                                  * block */
111                                 rc = fs_prep_san_write(exp->exp_obd, inode,
112                                                        &block, 1, newsize);
113                                 if (rc)
114                                         break;
115                         }
116
117                         rnb->offset = block;
118                 }
119                 f_dput(dentry);
120         }
121 out:
122         RETURN(rc);
123 }
124