Whamcloud - gitweb
- changes with names on exports and another fields in llite and mds. lov_exp is
[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
24 #include <linux/config.h>
25 #include <linux/kernel.h>
26 #include <linux/mm.h>
27 #include <linux/string.h>
28 #include <linux/stat.h>
29 #include <linux/errno.h>
30 #include <linux/smp_lock.h>
31 #include <linux/unistd.h>
32 #include <linux/version.h>
33 #include <asm/system.h>
34 #include <asm/uaccess.h>
35
36 #include <linux/fs.h>
37 #include <linux/iobuf.h>
38 #include <linux/stat.h>
39 #include <asm/uaccess.h>
40 #include <asm/segment.h>
41 #include <linux/mm.h>
42 #include <linux/pagemap.h>
43 #include <linux/smp_lock.h>
44
45 #define DEBUG_SUBSYSTEM S_LLITE
46
47 #include <linux/lustre_mds.h>
48 #include <linux/lustre_lite.h>
49 #include "llite_internal.h"
50 #include <linux/lustre_compat25.h>
51
52 #ifdef HAVE_DIO_FILE
53 static int ll_direct_IO_24(int rw, struct file *file, struct kiobuf *iobuf,
54                            unsigned long blocknr, int blocksize)
55 #else
56 static int ll_direct_IO_24(int rw, struct inode *inode, struct kiobuf *iobuf,
57                            unsigned long blocknr, int blocksize)
58 #endif
59 {
60 #ifdef HAVE_DIO_FILE
61         struct inode *inode = file->f_dentry->d_inode;
62 #endif
63         struct ll_inode_info *lli = ll_i2info(inode);
64         struct lov_stripe_md *lsm = lli->lli_smd;
65         struct brw_page *pga;
66         struct ptlrpc_request_set *set;
67         struct obdo *oa = NULL;
68         int length, i, flags, rc = 0;
69         loff_t offset;
70         ENTRY;
71
72         if (!lsm || !lsm->lsm_object_id)
73                 RETURN(-EBADF);
74
75         set = ptlrpc_prep_set();
76         if (set == NULL)
77                 RETURN(-ENOMEM);
78
79         OBD_ALLOC(pga, sizeof(*pga) * iobuf->nr_pages);
80         if (!pga) {
81                 ptlrpc_set_destroy(set);
82                 RETURN(-ENOMEM);
83         }
84
85         flags = 0 /* | OBD_BRW_DIRECTIO */;
86         offset = ((obd_off)blocknr * blocksize);
87         length = iobuf->length;
88         pga[0].page_offset = iobuf->offset;
89         LASSERT(iobuf->offset < PAGE_SIZE);
90
91         for (i = 0, length = iobuf->length; length > 0;
92              length -= pga[i].count, offset += pga[i].count, i++) { /*i last!*/
93                 pga[i].pg = iobuf->maplist[i];
94                 pga[i].disk_offset = offset;
95                 /* To the end of the page, or the length, whatever is less */
96                 pga[i].count = min_t(int, PAGE_SIZE - pga[i].page_offset,
97                                      length);
98                 pga[i].flag = flags;
99                 if (rw == READ)
100                         POISON_PAGE(iobuf->maplist[i], 0x0d);
101         }
102
103         oa = obdo_alloc();
104         if (oa == NULL) {
105                 ptlrpc_set_destroy(set);
106                 GOTO(out_free_pga, -ENOMEM);
107         }
108         ll_inode_fill_obdo(inode, rw, oa);
109
110         if (rw == WRITE)
111                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
112                                     LPROC_LL_DIRECT_WRITE, iobuf->length);
113         else
114                 lprocfs_counter_add(ll_i2sbi(inode)->ll_stats,
115                                     LPROC_LL_DIRECT_READ, iobuf->length);
116         rc = obd_brw_async(rw == WRITE ? OBD_BRW_WRITE : OBD_BRW_READ,
117                            ll_i2dtexp(inode), oa, lsm, iobuf->nr_pages, pga,
118                            set, NULL);
119         if (rc) {
120                 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
121                        "error from obd_brw_async: rc = %d\n", rc);
122         } else {
123                 rc = ptlrpc_set_wait(set);
124                 if (rc)
125                         CERROR("error from callback: rc = %d\n", rc);
126         }
127         ptlrpc_set_destroy(set);
128         if (rc == 0 && rw == WRITE) {
129                 void lov_increase_kms(struct obd_export *,
130                                       struct lov_stripe_md *, obd_off size);
131                 obd_off size = offset + length;
132                 lov_increase_kms(ll_i2dtexp(inode), lsm, size);
133                 if (size > inode->i_size)
134                         inode->i_size = size;
135         }
136         if (rc == 0) {
137                 rc = iobuf->length;
138                 obdo_to_inode(inode, oa, OBD_MD_FLBLOCKS);
139         }
140         obdo_free(oa);
141         EXIT;
142 out_free_pga:
143         OBD_FREE(pga, sizeof(*pga) * iobuf->nr_pages);
144         return rc;
145 }
146
147 struct address_space_operations ll_aops = {
148         .readpage       = ll_readpage,
149         .direct_IO      = ll_direct_IO_24,
150         .writepage      = ll_writepage,
151         .prepare_write  = ll_prepare_write,
152         .commit_write   = ll_commit_write,
153         .removepage     = ll_removepage,
154         .sync_page      = NULL,
155         .bmap           = NULL
156 };