David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. |
Steven Whitehouse | 3a8a9a1 | 2006-05-18 15:09:15 -0400 | [diff] [blame] | 3 | * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 4 | * |
| 5 | * This copyrighted material is made available to anyone wishing to use, |
| 6 | * modify, copy, or redistribute it subject to the terms and conditions |
Steven Whitehouse | e9fc2aa | 2006-09-01 11:05:15 -0400 | [diff] [blame] | 7 | * of the GNU General Public License version 2. |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/completion.h> |
| 14 | #include <linux/buffer_head.h> |
| 15 | #include <linux/pagemap.h> |
| 16 | #include <linux/uio.h> |
| 17 | #include <linux/blkdev.h> |
| 18 | #include <linux/mm.h> |
| 19 | #include <linux/smp_lock.h> |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 20 | #include <linux/fs.h> |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 21 | #include <linux/gfs2_ondisk.h> |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 22 | #include <linux/ext2_fs.h> |
| 23 | #include <linux/crc32.h> |
Fabio Massimo Di Nitto | 7d30859 | 2006-09-19 07:56:29 +0200 | [diff] [blame] | 24 | #include <linux/lm_interface.h> |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 25 | #include <asm/uaccess.h> |
| 26 | |
| 27 | #include "gfs2.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 28 | #include "incore.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 29 | #include "bmap.h" |
| 30 | #include "dir.h" |
| 31 | #include "glock.h" |
| 32 | #include "glops.h" |
| 33 | #include "inode.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 34 | #include "lm.h" |
| 35 | #include "log.h" |
| 36 | #include "meta_io.h" |
| 37 | #include "ops_file.h" |
| 38 | #include "ops_vm.h" |
| 39 | #include "quota.h" |
| 40 | #include "rgrp.h" |
| 41 | #include "trans.h" |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 42 | #include "util.h" |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 43 | #include "eaops.h" |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 44 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 45 | /* For regular, non-NFS */ |
| 46 | struct filldir_reg { |
| 47 | struct gfs2_sbd *fdr_sbd; |
| 48 | int fdr_prefetch; |
| 49 | |
| 50 | filldir_t fdr_filldir; |
| 51 | void *fdr_opaque; |
| 52 | }; |
| 53 | |
Steven Whitehouse | 61a30dc | 2006-02-15 10:15:18 +0000 | [diff] [blame] | 54 | /* |
| 55 | * Most fields left uninitialised to catch anybody who tries to |
| 56 | * use them. f_flags set to prevent file_accessed() from touching |
| 57 | * any other part of this. Its use is purely as a flag so that we |
| 58 | * know (in readpage()) whether or not do to locking. |
| 59 | */ |
Steven Whitehouse | dd538c8 | 2006-09-04 14:53:30 -0400 | [diff] [blame] | 60 | struct file gfs2_internal_file_sentinel = { |
Steven Whitehouse | 61a30dc | 2006-02-15 10:15:18 +0000 | [diff] [blame] | 61 | .f_flags = O_NOATIME|O_RDONLY, |
| 62 | }; |
| 63 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 64 | static int gfs2_read_actor(read_descriptor_t *desc, struct page *page, |
| 65 | unsigned long offset, unsigned long size) |
| 66 | { |
| 67 | char *kaddr; |
| 68 | unsigned long count = desc->count; |
| 69 | |
| 70 | if (size > count) |
| 71 | size = count; |
| 72 | |
| 73 | kaddr = kmap(page); |
Al Viro | 9c9ab3d | 2006-10-13 23:49:23 -0400 | [diff] [blame] | 74 | memcpy(desc->arg.data, kaddr + offset, size); |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 75 | kunmap(page); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 76 | |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 77 | desc->count = count - size; |
| 78 | desc->written += size; |
| 79 | desc->arg.buf += size; |
| 80 | return size; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state, |
| 84 | char *buf, loff_t *pos, unsigned size) |
| 85 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 86 | struct inode *inode = &ip->i_inode; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 87 | read_descriptor_t desc; |
| 88 | desc.written = 0; |
Al Viro | 9c9ab3d | 2006-10-13 23:49:23 -0400 | [diff] [blame] | 89 | desc.arg.data = buf; |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 90 | desc.count = size; |
| 91 | desc.error = 0; |
Steven Whitehouse | 61a30dc | 2006-02-15 10:15:18 +0000 | [diff] [blame] | 92 | do_generic_mapping_read(inode->i_mapping, ra_state, |
Steven Whitehouse | dd538c8 | 2006-09-04 14:53:30 -0400 | [diff] [blame] | 93 | &gfs2_internal_file_sentinel, pos, &desc, |
Steven Whitehouse | 61a30dc | 2006-02-15 10:15:18 +0000 | [diff] [blame] | 94 | gfs2_read_actor); |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 95 | return desc.written ? desc.written : desc.error; |
| 96 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * gfs2_llseek - seek to a location in a file |
| 100 | * @file: the file |
| 101 | * @offset: the offset |
| 102 | * @origin: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END) |
| 103 | * |
| 104 | * SEEK_END requires the glock for the file because it references the |
| 105 | * file's size. |
| 106 | * |
| 107 | * Returns: The new offset, or errno |
| 108 | */ |
| 109 | |
| 110 | static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin) |
| 111 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 112 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 113 | struct gfs2_holder i_gh; |
| 114 | loff_t error; |
| 115 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 116 | if (origin == 2) { |
| 117 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, |
| 118 | &i_gh); |
| 119 | if (!error) { |
| 120 | error = remote_llseek(file, offset, origin); |
| 121 | gfs2_glock_dq_uninit(&i_gh); |
| 122 | } |
| 123 | } else |
| 124 | error = remote_llseek(file, offset, origin); |
| 125 | |
| 126 | return error; |
| 127 | } |
| 128 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 129 | /** |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 130 | * filldir_func - Report a directory entry to the caller of gfs2_dir_read() |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 131 | * @opaque: opaque data used by the function |
| 132 | * @name: the name of the directory entry |
| 133 | * @length: the length of the name |
| 134 | * @offset: the entry's offset in the directory |
| 135 | * @inum: the inode number the entry points to |
| 136 | * @type: the type of inode the entry points to |
| 137 | * |
| 138 | * Returns: 0 on success, 1 if buffer full |
| 139 | */ |
| 140 | |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 141 | static int filldir_func(void *opaque, const char *name, unsigned int length, |
Al Viro | 629a21e | 2006-10-13 22:51:24 -0400 | [diff] [blame] | 142 | u64 offset, struct gfs2_inum_host *inum, |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 143 | unsigned int type) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 144 | { |
| 145 | struct filldir_reg *fdr = (struct filldir_reg *)opaque; |
| 146 | struct gfs2_sbd *sdp = fdr->fdr_sbd; |
| 147 | int error; |
| 148 | |
| 149 | error = fdr->fdr_filldir(fdr->fdr_opaque, name, length, offset, |
Steven Whitehouse | 4340fe6 | 2006-07-11 09:46:33 -0400 | [diff] [blame] | 150 | inum->no_addr, type); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 151 | if (error) |
| 152 | return 1; |
| 153 | |
| 154 | if (fdr->fdr_prefetch && !(length == 1 && *name == '.')) { |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 155 | gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_inode_glops, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 156 | LM_ST_SHARED, LM_FLAG_TRY | LM_FLAG_ANY); |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 157 | gfs2_glock_prefetch_num(sdp, inum->no_addr, &gfs2_iopen_glops, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 158 | LM_ST_SHARED, LM_FLAG_TRY); |
| 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /** |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 165 | * gfs2_readdir - Read directory entries from a directory |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 166 | * @file: The directory to read from |
| 167 | * @dirent: Buffer for dirents |
| 168 | * @filldir: Function used to do the copying |
| 169 | * |
| 170 | * Returns: errno |
| 171 | */ |
| 172 | |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 173 | static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 174 | { |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 175 | struct inode *dir = file->f_mapping->host; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 176 | struct gfs2_inode *dip = GFS2_I(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 177 | struct filldir_reg fdr; |
| 178 | struct gfs2_holder d_gh; |
Steven Whitehouse | cd91549 | 2006-09-04 12:49:07 -0400 | [diff] [blame] | 179 | u64 offset = file->f_pos; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 180 | int error; |
| 181 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 182 | fdr.fdr_sbd = GFS2_SB(dir); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 183 | fdr.fdr_prefetch = 1; |
| 184 | fdr.fdr_filldir = filldir; |
| 185 | fdr.fdr_opaque = dirent; |
| 186 | |
| 187 | gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh); |
| 188 | error = gfs2_glock_nq_atime(&d_gh); |
| 189 | if (error) { |
| 190 | gfs2_holder_uninit(&d_gh); |
| 191 | return error; |
| 192 | } |
| 193 | |
Steven Whitehouse | f0e522a | 2006-09-19 16:41:11 -0400 | [diff] [blame] | 194 | error = gfs2_dir_read(dir, &offset, &fdr, filldir_func); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 195 | |
| 196 | gfs2_glock_dq_uninit(&d_gh); |
| 197 | |
| 198 | file->f_pos = offset; |
| 199 | |
| 200 | return error; |
| 201 | } |
| 202 | |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 203 | /** |
| 204 | * fsflags_cvt |
| 205 | * @table: A table of 32 u32 flags |
| 206 | * @val: a 32 bit value to convert |
| 207 | * |
| 208 | * This function can be used to convert between fsflags values and |
| 209 | * GFS2's own flags values. |
| 210 | * |
| 211 | * Returns: the converted flags |
| 212 | */ |
| 213 | static u32 fsflags_cvt(const u32 *table, u32 val) |
| 214 | { |
| 215 | u32 res = 0; |
| 216 | while(val) { |
| 217 | if (val & 1) |
| 218 | res |= *table; |
| 219 | table++; |
| 220 | val >>= 1; |
| 221 | } |
| 222 | return res; |
| 223 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 224 | |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 225 | static const u32 fsflags_to_gfs2[32] = { |
| 226 | [3] = GFS2_DIF_SYNC, |
| 227 | [4] = GFS2_DIF_IMMUTABLE, |
| 228 | [5] = GFS2_DIF_APPENDONLY, |
| 229 | [7] = GFS2_DIF_NOATIME, |
| 230 | [12] = GFS2_DIF_EXHASH, |
| 231 | [14] = GFS2_DIF_JDATA, |
| 232 | [20] = GFS2_DIF_DIRECTIO, |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 233 | }; |
| 234 | |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 235 | static const u32 gfs2_to_fsflags[32] = { |
| 236 | [gfs2fl_Sync] = FS_SYNC_FL, |
| 237 | [gfs2fl_Immutable] = FS_IMMUTABLE_FL, |
| 238 | [gfs2fl_AppendOnly] = FS_APPEND_FL, |
| 239 | [gfs2fl_NoAtime] = FS_NOATIME_FL, |
| 240 | [gfs2fl_ExHash] = FS_INDEX_FL, |
| 241 | [gfs2fl_Jdata] = FS_JOURNAL_DATA_FL, |
| 242 | [gfs2fl_Directio] = FS_DIRECTIO_FL, |
| 243 | [gfs2fl_InheritDirectio] = FS_DIRECTIO_FL, |
| 244 | [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL, |
Steven Whitehouse | 7ea9ea8 | 2006-03-31 15:01:28 -0500 | [diff] [blame] | 245 | }; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 246 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 247 | static int gfs2_get_flags(struct file *filp, u32 __user *ptr) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 248 | { |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 249 | struct inode *inode = filp->f_dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 250 | struct gfs2_inode *ip = GFS2_I(inode); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 251 | struct gfs2_holder gh; |
| 252 | int error; |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 253 | u32 fsflags; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 254 | |
| 255 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh); |
Steven Whitehouse | dcd2479 | 2006-11-16 11:08:16 -0500 | [diff] [blame] | 256 | error = gfs2_glock_nq_atime(&gh); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 257 | if (error) |
| 258 | return error; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 259 | |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 260 | fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_di.di_flags); |
| 261 | if (put_user(fsflags, ptr)) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 262 | error = -EFAULT; |
| 263 | |
| 264 | gfs2_glock_dq_m(1, &gh); |
| 265 | gfs2_holder_uninit(&gh); |
| 266 | return error; |
| 267 | } |
| 268 | |
Steven Whitehouse | 6b124d8 | 2006-11-08 12:51:06 -0500 | [diff] [blame] | 269 | void gfs2_set_inode_flags(struct inode *inode) |
| 270 | { |
| 271 | struct gfs2_inode *ip = GFS2_I(inode); |
| 272 | struct gfs2_dinode_host *di = &ip->i_di; |
| 273 | unsigned int flags = inode->i_flags; |
| 274 | |
| 275 | flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); |
| 276 | if (di->di_flags & GFS2_DIF_IMMUTABLE) |
| 277 | flags |= S_IMMUTABLE; |
| 278 | if (di->di_flags & GFS2_DIF_APPENDONLY) |
| 279 | flags |= S_APPEND; |
| 280 | if (di->di_flags & GFS2_DIF_NOATIME) |
| 281 | flags |= S_NOATIME; |
| 282 | if (di->di_flags & GFS2_DIF_SYNC) |
| 283 | flags |= S_SYNC; |
| 284 | inode->i_flags = flags; |
| 285 | } |
| 286 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 287 | /* Flags that can be set by user space */ |
| 288 | #define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \ |
| 289 | GFS2_DIF_DIRECTIO| \ |
| 290 | GFS2_DIF_IMMUTABLE| \ |
| 291 | GFS2_DIF_APPENDONLY| \ |
| 292 | GFS2_DIF_NOATIME| \ |
| 293 | GFS2_DIF_SYNC| \ |
| 294 | GFS2_DIF_SYSTEM| \ |
| 295 | GFS2_DIF_INHERIT_DIRECTIO| \ |
| 296 | GFS2_DIF_INHERIT_JDATA) |
| 297 | |
| 298 | /** |
| 299 | * gfs2_set_flags - set flags on an inode |
| 300 | * @inode: The inode |
| 301 | * @flags: The flags to set |
| 302 | * @mask: Indicates which flags are valid |
| 303 | * |
| 304 | */ |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 305 | static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 306 | { |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 307 | struct inode *inode = filp->f_dentry->d_inode; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 308 | struct gfs2_inode *ip = GFS2_I(inode); |
| 309 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 310 | struct buffer_head *bh; |
| 311 | struct gfs2_holder gh; |
| 312 | int error; |
Steven Whitehouse | 55eccc6 | 2006-04-04 14:29:30 -0400 | [diff] [blame] | 313 | u32 new_flags, flags; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 314 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 315 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh); |
Abhijith Das | 52f341c | 2006-07-21 02:03:21 -0400 | [diff] [blame] | 316 | if (error) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 317 | return error; |
| 318 | |
Steven Whitehouse | 55eccc6 | 2006-04-04 14:29:30 -0400 | [diff] [blame] | 319 | flags = ip->i_di.di_flags; |
| 320 | new_flags = (flags & ~mask) | (reqflags & mask); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 321 | if ((new_flags ^ flags) == 0) |
| 322 | goto out; |
| 323 | |
Steven Whitehouse | 4bcf709 | 2006-04-25 13:20:27 -0400 | [diff] [blame] | 324 | if (S_ISDIR(inode->i_mode)) { |
| 325 | if ((new_flags ^ flags) & GFS2_DIF_JDATA) |
| 326 | new_flags ^= (GFS2_DIF_JDATA|GFS2_DIF_INHERIT_JDATA); |
| 327 | if ((new_flags ^ flags) & GFS2_DIF_DIRECTIO) |
| 328 | new_flags ^= (GFS2_DIF_DIRECTIO|GFS2_DIF_INHERIT_DIRECTIO); |
| 329 | } |
| 330 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 331 | error = -EINVAL; |
| 332 | if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET) |
| 333 | goto out; |
| 334 | |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 335 | error = -EPERM; |
| 336 | if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE)) |
| 337 | goto out; |
| 338 | if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY)) |
| 339 | goto out; |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 340 | if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) && |
Steven Whitehouse | b9cb981 | 2006-05-12 17:07:56 -0400 | [diff] [blame] | 341 | !capable(CAP_LINUX_IMMUTABLE)) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 342 | goto out; |
Steven Whitehouse | b9cb981 | 2006-05-12 17:07:56 -0400 | [diff] [blame] | 343 | if (!IS_IMMUTABLE(inode)) { |
Steven Whitehouse | faf450e | 2006-06-22 10:59:10 -0400 | [diff] [blame] | 344 | error = permission(inode, MAY_WRITE, NULL); |
Steven Whitehouse | b9cb981 | 2006-05-12 17:07:56 -0400 | [diff] [blame] | 345 | if (error) |
| 346 | goto out; |
| 347 | } |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 348 | |
Steven Whitehouse | 55eccc6 | 2006-04-04 14:29:30 -0400 | [diff] [blame] | 349 | error = gfs2_trans_begin(sdp, RES_DINODE, 0); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 350 | if (error) |
| 351 | goto out; |
Steven Whitehouse | 55eccc6 | 2006-04-04 14:29:30 -0400 | [diff] [blame] | 352 | error = gfs2_meta_inode_buffer(ip, &bh); |
| 353 | if (error) |
| 354 | goto out_trans_end; |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 355 | gfs2_trans_add_bh(ip->i_gl, bh, 1); |
| 356 | ip->i_di.di_flags = new_flags; |
Steven Whitehouse | 539e5d6 | 2006-10-31 15:07:05 -0500 | [diff] [blame] | 357 | gfs2_dinode_out(ip, bh->b_data); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 358 | brelse(bh); |
Steven Whitehouse | 6b124d8 | 2006-11-08 12:51:06 -0500 | [diff] [blame] | 359 | gfs2_set_inode_flags(inode); |
Steven Whitehouse | 55eccc6 | 2006-04-04 14:29:30 -0400 | [diff] [blame] | 360 | out_trans_end: |
| 361 | gfs2_trans_end(sdp); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 362 | out: |
| 363 | gfs2_glock_dq_uninit(&gh); |
| 364 | return error; |
| 365 | } |
| 366 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 367 | static int gfs2_set_flags(struct file *filp, u32 __user *ptr) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 368 | { |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 369 | u32 fsflags, gfsflags; |
| 370 | if (get_user(fsflags, ptr)) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 371 | return -EFAULT; |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 372 | gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags); |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 373 | return do_gfs2_set_flags(filp, gfsflags, ~0); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 374 | } |
| 375 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 376 | static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 377 | { |
| 378 | switch(cmd) { |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 379 | case FS_IOC_GETFLAGS: |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 380 | return gfs2_get_flags(filp, (u32 __user *)arg); |
Steven Whitehouse | 128e5eb | 2006-10-02 11:24:43 -0400 | [diff] [blame] | 381 | case FS_IOC_SETFLAGS: |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 382 | return gfs2_set_flags(filp, (u32 __user *)arg); |
Steven Whitehouse | 71b86f5 | 2006-03-28 14:14:04 -0500 | [diff] [blame] | 383 | } |
| 384 | return -ENOTTY; |
| 385 | } |
| 386 | |
| 387 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 388 | /** |
| 389 | * gfs2_mmap - |
| 390 | * @file: The file to map |
| 391 | * @vma: The VMA which described the mapping |
| 392 | * |
| 393 | * Returns: 0 or error code |
| 394 | */ |
| 395 | |
| 396 | static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) |
| 397 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 398 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 399 | struct gfs2_holder i_gh; |
| 400 | int error; |
| 401 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 402 | gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &i_gh); |
| 403 | error = gfs2_glock_nq_atime(&i_gh); |
| 404 | if (error) { |
| 405 | gfs2_holder_uninit(&i_gh); |
| 406 | return error; |
| 407 | } |
| 408 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 409 | /* This is VM_MAYWRITE instead of VM_WRITE because a call |
| 410 | to mprotect() can turn on VM_WRITE later. */ |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 411 | |
Steven Whitehouse | 18ec7d5 | 2006-02-08 11:50:51 +0000 | [diff] [blame] | 412 | if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) == |
| 413 | (VM_MAYSHARE | VM_MAYWRITE)) |
| 414 | vma->vm_ops = &gfs2_vm_ops_sharewrite; |
| 415 | else |
| 416 | vma->vm_ops = &gfs2_vm_ops_private; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 417 | |
| 418 | gfs2_glock_dq_uninit(&i_gh); |
| 419 | |
| 420 | return error; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * gfs2_open - open a file |
| 425 | * @inode: the inode to open |
| 426 | * @file: the struct file for this opening |
| 427 | * |
| 428 | * Returns: errno |
| 429 | */ |
| 430 | |
| 431 | static int gfs2_open(struct inode *inode, struct file *file) |
| 432 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 433 | struct gfs2_inode *ip = GFS2_I(inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 434 | struct gfs2_holder i_gh; |
| 435 | struct gfs2_file *fp; |
| 436 | int error; |
| 437 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 438 | fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL); |
| 439 | if (!fp) |
| 440 | return -ENOMEM; |
| 441 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 442 | mutex_init(&fp->f_fl_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 443 | |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 444 | gfs2_assert_warn(GFS2_SB(inode), !file->private_data); |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 445 | file->private_data = fp; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 446 | |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 447 | if (S_ISREG(ip->i_inode.i_mode)) { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 448 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, |
| 449 | &i_gh); |
| 450 | if (error) |
| 451 | goto fail; |
| 452 | |
| 453 | if (!(file->f_flags & O_LARGEFILE) && |
| 454 | ip->i_di.di_size > MAX_NON_LFS) { |
| 455 | error = -EFBIG; |
| 456 | goto fail_gunlock; |
| 457 | } |
| 458 | |
| 459 | /* Listen to the Direct I/O flag */ |
| 460 | |
| 461 | if (ip->i_di.di_flags & GFS2_DIF_DIRECTIO) |
| 462 | file->f_flags |= O_DIRECT; |
| 463 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 464 | gfs2_glock_dq_uninit(&i_gh); |
| 465 | } |
| 466 | |
| 467 | return 0; |
| 468 | |
Steven Whitehouse | 420b9e5 | 2006-07-31 15:42:17 -0400 | [diff] [blame] | 469 | fail_gunlock: |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 470 | gfs2_glock_dq_uninit(&i_gh); |
Steven Whitehouse | 420b9e5 | 2006-07-31 15:42:17 -0400 | [diff] [blame] | 471 | fail: |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 472 | file->private_data = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 473 | kfree(fp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 474 | return error; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * gfs2_close - called to close a struct file |
| 479 | * @inode: the inode the struct file belongs to |
| 480 | * @file: the struct file being closed |
| 481 | * |
| 482 | * Returns: errno |
| 483 | */ |
| 484 | |
| 485 | static int gfs2_close(struct inode *inode, struct file *file) |
| 486 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 487 | struct gfs2_sbd *sdp = inode->i_sb->s_fs_info; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 488 | struct gfs2_file *fp; |
| 489 | |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 490 | fp = file->private_data; |
| 491 | file->private_data = NULL; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 492 | |
| 493 | if (gfs2_assert_warn(sdp, fp)) |
| 494 | return -EIO; |
| 495 | |
| 496 | kfree(fp); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * gfs2_fsync - sync the dirty data for a file (across the cluster) |
| 503 | * @file: the file that points to the dentry (we ignore this) |
| 504 | * @dentry: the dentry that points to the inode to sync |
| 505 | * |
| 506 | * Returns: errno |
| 507 | */ |
| 508 | |
| 509 | static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync) |
| 510 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 511 | struct gfs2_inode *ip = GFS2_I(dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 512 | |
Steven Whitehouse | b09e593 | 2006-04-07 11:17:32 -0400 | [diff] [blame] | 513 | gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * gfs2_lock - acquire/release a posix lock on a file |
| 520 | * @file: the file pointer |
| 521 | * @cmd: either modify or retrieve lock state, possibly wait |
| 522 | * @fl: type and range of lock |
| 523 | * |
| 524 | * Returns: errno |
| 525 | */ |
| 526 | |
| 527 | static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl) |
| 528 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 529 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
| 530 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 531 | struct lm_lockname name = |
| 532 | { .ln_number = ip->i_num.no_addr, |
| 533 | .ln_type = LM_TYPE_PLOCK }; |
| 534 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 535 | if (!(fl->fl_flags & FL_POSIX)) |
| 536 | return -ENOLCK; |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 537 | if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 538 | return -ENOLCK; |
| 539 | |
| 540 | if (sdp->sd_args.ar_localflocks) { |
| 541 | if (IS_GETLK(cmd)) { |
Steven Whitehouse | 8628de0 | 2006-03-31 16:48:41 -0500 | [diff] [blame] | 542 | struct file_lock tmp; |
| 543 | int ret; |
| 544 | ret = posix_test_lock(file, fl, &tmp); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 545 | fl->fl_type = F_UNLCK; |
Steven Whitehouse | 8628de0 | 2006-03-31 16:48:41 -0500 | [diff] [blame] | 546 | if (ret) |
| 547 | memcpy(fl, &tmp, sizeof(struct file_lock)); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 548 | return 0; |
| 549 | } else { |
Steven Whitehouse | 8628de0 | 2006-03-31 16:48:41 -0500 | [diff] [blame] | 550 | return posix_lock_file_wait(file, fl); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | if (IS_GETLK(cmd)) |
| 555 | return gfs2_lm_plock_get(sdp, &name, file, fl); |
| 556 | else if (fl->fl_type == F_UNLCK) |
| 557 | return gfs2_lm_punlock(sdp, &name, file, fl); |
| 558 | else |
| 559 | return gfs2_lm_plock(sdp, &name, file, cmd, fl); |
| 560 | } |
| 561 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 562 | static int do_flock(struct file *file, int cmd, struct file_lock *fl) |
| 563 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 564 | struct gfs2_file *fp = file->private_data; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 565 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 566 | struct gfs2_inode *ip = GFS2_I(file->f_dentry->d_inode); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 567 | struct gfs2_glock *gl; |
| 568 | unsigned int state; |
| 569 | int flags; |
| 570 | int error = 0; |
| 571 | |
| 572 | state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 573 | flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 574 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 575 | mutex_lock(&fp->f_fl_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 576 | |
| 577 | gl = fl_gh->gh_gl; |
| 578 | if (gl) { |
| 579 | if (fl_gh->gh_state == state) |
| 580 | goto out; |
| 581 | gfs2_glock_hold(gl); |
| 582 | flock_lock_file_wait(file, |
Steven Whitehouse | 907b9bc | 2006-09-25 09:26:04 -0400 | [diff] [blame] | 583 | &(struct file_lock){.fl_type = F_UNLCK}); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 584 | gfs2_glock_dq_uninit(fl_gh); |
| 585 | } else { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 586 | error = gfs2_glock_get(GFS2_SB(&ip->i_inode), |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 587 | ip->i_num.no_addr, &gfs2_flock_glops, |
| 588 | CREATE, &gl); |
| 589 | if (error) |
| 590 | goto out; |
| 591 | } |
| 592 | |
| 593 | gfs2_holder_init(gl, state, flags, fl_gh); |
| 594 | gfs2_glock_put(gl); |
| 595 | |
| 596 | error = gfs2_glock_nq(fl_gh); |
| 597 | if (error) { |
| 598 | gfs2_holder_uninit(fl_gh); |
| 599 | if (error == GLR_TRYFAILED) |
| 600 | error = -EAGAIN; |
| 601 | } else { |
| 602 | error = flock_lock_file_wait(file, fl); |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 603 | gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Steven Whitehouse | 420b9e5 | 2006-07-31 15:42:17 -0400 | [diff] [blame] | 606 | out: |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 607 | mutex_unlock(&fp->f_fl_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 608 | return error; |
| 609 | } |
| 610 | |
| 611 | static void do_unflock(struct file *file, struct file_lock *fl) |
| 612 | { |
Steven Whitehouse | 5c676f6 | 2006-02-27 17:23:27 -0500 | [diff] [blame] | 613 | struct gfs2_file *fp = file->private_data; |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 614 | struct gfs2_holder *fl_gh = &fp->f_fl_gh; |
| 615 | |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 616 | mutex_lock(&fp->f_fl_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 617 | flock_lock_file_wait(file, fl); |
| 618 | if (fl_gh->gh_gl) |
| 619 | gfs2_glock_dq_uninit(fl_gh); |
Steven Whitehouse | f55ab26 | 2006-02-21 12:51:39 +0000 | [diff] [blame] | 620 | mutex_unlock(&fp->f_fl_mutex); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | /** |
| 624 | * gfs2_flock - acquire/release a flock lock on a file |
| 625 | * @file: the file pointer |
| 626 | * @cmd: either modify or retrieve lock state, possibly wait |
| 627 | * @fl: type and range of lock |
| 628 | * |
| 629 | * Returns: errno |
| 630 | */ |
| 631 | |
| 632 | static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) |
| 633 | { |
Steven Whitehouse | feaa7bb | 2006-06-14 15:32:57 -0400 | [diff] [blame] | 634 | struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); |
| 635 | struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 636 | |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 637 | if (!(fl->fl_flags & FL_FLOCK)) |
| 638 | return -ENOLCK; |
Steven Whitehouse | b60623c | 2006-11-01 12:22:46 -0500 | [diff] [blame] | 639 | if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID) |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 640 | return -ENOLCK; |
| 641 | |
| 642 | if (sdp->sd_args.ar_localflocks) |
| 643 | return flock_lock_file_wait(file, fl); |
| 644 | |
| 645 | if (fl->fl_type == F_UNLCK) { |
| 646 | do_unflock(file, fl); |
| 647 | return 0; |
Steven Whitehouse | d00223f | 2006-10-02 10:28:05 -0400 | [diff] [blame] | 648 | } else { |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 649 | return do_flock(file, cmd, fl); |
Steven Whitehouse | d00223f | 2006-10-02 10:28:05 -0400 | [diff] [blame] | 650 | } |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Steven Whitehouse | b0dd930 | 2006-07-03 13:47:02 -0400 | [diff] [blame] | 653 | const struct file_operations gfs2_file_fops = { |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 654 | .llseek = gfs2_llseek, |
Steven Whitehouse | d00223f | 2006-10-02 10:28:05 -0400 | [diff] [blame] | 655 | .read = do_sync_read, |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 656 | .aio_read = generic_file_aio_read, |
Steven Whitehouse | d00223f | 2006-10-02 10:28:05 -0400 | [diff] [blame] | 657 | .write = do_sync_write, |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 658 | .aio_write = generic_file_aio_write, |
| 659 | .unlocked_ioctl = gfs2_ioctl, |
| 660 | .mmap = gfs2_mmap, |
| 661 | .open = gfs2_open, |
| 662 | .release = gfs2_close, |
| 663 | .fsync = gfs2_fsync, |
| 664 | .lock = gfs2_lock, |
| 665 | .sendfile = generic_file_sendfile, |
| 666 | .flock = gfs2_flock, |
| 667 | .splice_read = generic_file_splice_read, |
| 668 | .splice_write = generic_file_splice_write, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 669 | }; |
| 670 | |
Steven Whitehouse | b0dd930 | 2006-07-03 13:47:02 -0400 | [diff] [blame] | 671 | const struct file_operations gfs2_dir_fops = { |
Steven Whitehouse | 26c1a57 | 2006-09-04 15:32:10 -0400 | [diff] [blame] | 672 | .readdir = gfs2_readdir, |
| 673 | .unlocked_ioctl = gfs2_ioctl, |
| 674 | .open = gfs2_open, |
| 675 | .release = gfs2_close, |
| 676 | .fsync = gfs2_fsync, |
| 677 | .lock = gfs2_lock, |
| 678 | .flock = gfs2_flock, |
David Teigland | b3b94fa | 2006-01-16 16:50:04 +0000 | [diff] [blame] | 679 | }; |
| 680 | |