Whamcloud - gitweb
Branch b1_6
[fs/lustre-release.git] / lustre / llite / rw24.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Lite I/O page cache for the 2.4 kernel version
5  *
6  *  Copyright (c) 2001-2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23 #ifdef HAVE_KERNEL_CONFIG_H
24 #include <linux/config.h>
25 #endif
26 #include <linux/kernel.h>
27 #include <linux/mm.h>
28 #include <linux/string.h>
29 #include <linux/stat.h>
30 #include <linux/errno.h>
31 #include <linux/smp_lock.h>
32 #include <linux/unistd.h>
33 #include <linux/version.h>
34 #include <asm/system.h>
35 #include <asm/uaccess.h>
36
37 #include <linux/fs.h>
38 #include <linux/iobuf.h>
39 #include <linux/stat.h>
40 #include <asm/uaccess.h>
41 #include <asm/segment.h>
42 #include <linux/mm.h>
43 #include <linux/pagemap.h>
44 #include <linux/smp_lock.h>
45
46 #define DEBUG_SUBSYSTEM S_LLITE
47
48 #include <lustre_lite.h>
49 #include "llite_internal.h"
50 #include <linux/lustre_compat25.h>
51
52 static int ll_direct_IO_24(int rw,
53 #ifdef HAVE_DIO_FILE
54                            struct file *file,
55 #else
56                            struct inode *inode,
57 #endif
58                            struct kiobuf *iobuf, unsigned long blocknr,
59                            int blocksize)
60 {
61 #ifdef HAVE_DIO_FILE
62         struct inode *inode = file->f_dentry->d_inode;
63 #endif
64         struct ll_inode_info *lli = ll_i2info(inode);
65         struct lov_stripe_md *lsm = lli->lli_smd;
66         struct brw_page *pga;
67         struct obdo oa;
68         int length, i, flags, rc = 0;
69         loff_t offset, offset_orig;
70         ENTRY;
71
72         if (!lsm || !lsm->lsm_object_id)
73                 RETURN(-EBADF);
74
75         offset = ((obd_off)blocknr << inode->i_blkbits);
76         offset_orig = offset;
77         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p), size="LPSZ
78                ", offset=%lld=%llx, pages %u\n",
79                inode->i_ino, inode->i_generation, inode, iobuf->length,
80                offset, offset, iobuf->nr_pages);
81
82         /* FIXME: io smaller than CFS_PAGE_SIZE is broken on ia64 */
83         if ((iobuf->offset & (~CFS_PAGE_MASK)) ||
84             (iobuf->length & (~CFS_PAGE_MASK)))
85                 RETURN(-EINVAL);
86
87         OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
88         if (!pga)
89                 RETURN(-ENOMEM);
90
91         flags = 0 /* | OBD_BRW_DIRECTIO */;
92         length = iobuf->length;
93         rw = rw ? OBD_BRW_WRITE : OBD_BRW_READ;
94
95         for (i = 0, length = iobuf->length; length > 0;
96              length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
97                 pga[i].pg = iobuf->maplist[i];
98                 pga[i].off = offset;
99                 /* To the end of the page, or the length, whatever is less */
100                 pga[i].count = min_t(int, CFS_PAGE_SIZE - (offset & ~CFS_PAGE_MASK),
101                                      length);
102                 pga[i].flag = flags;
103                 if (rw == OBD_BRW_READ)
104                         POISON_PAGE(iobuf->maplist[i], 0x0d);
105         }
106
107         ll_inode_fill_obdo(inode, rw, &oa);
108
109         if (rw == OBD_BRW_WRITE)
110                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_DIRECT_WRITE, iobuf->length);
111         else
112                 ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_DIRECT_READ, iobuf->length);
113         rc = obd_brw_rqset(rw, ll_i2obdexp(inode), &oa, lsm, iobuf->nr_pages,
114                            pga, NULL);
115         if ((rc > 0) && (rw == OBD_BRW_WRITE)) {
116                 lov_stripe_lock(lsm);
117                 obd_adjust_kms(ll_i2obdexp(inode), lsm, offset_orig + rc, 0);
118                 lov_stripe_unlock(lsm);
119         }
120
121         OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
122         RETURN(rc);
123 }
124
125 #ifdef KERNEL_HAS_AS_MAX_READAHEAD
126 static int ll_max_readahead(struct inode *inode)
127 {
128         return 0;
129 }
130 #endif
131
132 struct address_space_operations ll_aops = {
133         .readpage       = ll_readpage,
134         .direct_IO      = ll_direct_IO_24,
135         .writepage      = ll_writepage,
136         .prepare_write  = ll_prepare_write,
137         .commit_write   = ll_commit_write,
138         .removepage     = ll_removepage,
139         .sync_page      = NULL,
140         .bmap           = NULL,
141 #ifdef KERNEL_HAS_AS_MAX_READAHEAD
142         .max_readahead  = ll_max_readahead,
143 #endif
144 };
145