ops_file.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  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
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/pagemap.h>
  14. #include <linux/uio.h>
  15. #include <linux/blkdev.h>
  16. #include <linux/mm.h>
  17. #include <linux/fs.h>
  18. #include <linux/gfs2_ondisk.h>
  19. #include <linux/ext2_fs.h>
  20. #include <linux/crc32.h>
  21. #include <linux/lm_interface.h>
  22. #include <linux/writeback.h>
  23. #include <asm/uaccess.h>
  24. #include "gfs2.h"
  25. #include "incore.h"
  26. #include "bmap.h"
  27. #include "dir.h"
  28. #include "glock.h"
  29. #include "glops.h"
  30. #include "inode.h"
  31. #include "lm.h"
  32. #include "log.h"
  33. #include "meta_io.h"
  34. #include "ops_file.h"
  35. #include "ops_vm.h"
  36. #include "quota.h"
  37. #include "rgrp.h"
  38. #include "trans.h"
  39. #include "util.h"
  40. #include "eaops.h"
  41. /*
  42. * Most fields left uninitialised to catch anybody who tries to
  43. * use them. f_flags set to prevent file_accessed() from touching
  44. * any other part of this. Its use is purely as a flag so that we
  45. * know (in readpage()) whether or not do to locking.
  46. */
  47. struct file gfs2_internal_file_sentinel = {
  48. .f_flags = O_NOATIME|O_RDONLY,
  49. };
  50. static int gfs2_read_actor(read_descriptor_t *desc, struct page *page,
  51. unsigned long offset, unsigned long size)
  52. {
  53. char *kaddr;
  54. unsigned long count = desc->count;
  55. if (size > count)
  56. size = count;
  57. kaddr = kmap(page);
  58. memcpy(desc->arg.data, kaddr + offset, size);
  59. kunmap(page);
  60. desc->count = count - size;
  61. desc->written += size;
  62. desc->arg.buf += size;
  63. return size;
  64. }
  65. int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
  66. char *buf, loff_t *pos, unsigned size)
  67. {
  68. struct inode *inode = &ip->i_inode;
  69. read_descriptor_t desc;
  70. desc.written = 0;
  71. desc.arg.data = buf;
  72. desc.count = size;
  73. desc.error = 0;
  74. do_generic_mapping_read(inode->i_mapping, ra_state,
  75. &gfs2_internal_file_sentinel, pos, &desc,
  76. gfs2_read_actor);
  77. return desc.written ? desc.written : desc.error;
  78. }
  79. /**
  80. * gfs2_llseek - seek to a location in a file
  81. * @file: the file
  82. * @offset: the offset
  83. * @origin: Where to seek from (SEEK_SET, SEEK_CUR, or SEEK_END)
  84. *
  85. * SEEK_END requires the glock for the file because it references the
  86. * file's size.
  87. *
  88. * Returns: The new offset, or errno
  89. */
  90. static loff_t gfs2_llseek(struct file *file, loff_t offset, int origin)
  91. {
  92. struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
  93. struct gfs2_holder i_gh;
  94. loff_t error;
  95. if (origin == 2) {
  96. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
  97. &i_gh);
  98. if (!error) {
  99. error = remote_llseek(file, offset, origin);
  100. gfs2_glock_dq_uninit(&i_gh);
  101. }
  102. } else
  103. error = remote_llseek(file, offset, origin);
  104. return error;
  105. }
  106. /**
  107. * gfs2_readdir - Read directory entries from a directory
  108. * @file: The directory to read from
  109. * @dirent: Buffer for dirents
  110. * @filldir: Function used to do the copying
  111. *
  112. * Returns: errno
  113. */
  114. static int gfs2_readdir(struct file *file, void *dirent, filldir_t filldir)
  115. {
  116. struct inode *dir = file->f_mapping->host;
  117. struct gfs2_inode *dip = GFS2_I(dir);
  118. struct gfs2_holder d_gh;
  119. u64 offset = file->f_pos;
  120. int error;
  121. gfs2_holder_init(dip->i_gl, LM_ST_SHARED, GL_ATIME, &d_gh);
  122. error = gfs2_glock_nq_atime(&d_gh);
  123. if (error) {
  124. gfs2_holder_uninit(&d_gh);
  125. return error;
  126. }
  127. error = gfs2_dir_read(dir, &offset, dirent, filldir);
  128. gfs2_glock_dq_uninit(&d_gh);
  129. file->f_pos = offset;
  130. return error;
  131. }
  132. /**
  133. * fsflags_cvt
  134. * @table: A table of 32 u32 flags
  135. * @val: a 32 bit value to convert
  136. *
  137. * This function can be used to convert between fsflags values and
  138. * GFS2's own flags values.
  139. *
  140. * Returns: the converted flags
  141. */
  142. static u32 fsflags_cvt(const u32 *table, u32 val)
  143. {
  144. u32 res = 0;
  145. while(val) {
  146. if (val & 1)
  147. res |= *table;
  148. table++;
  149. val >>= 1;
  150. }
  151. return res;
  152. }
  153. static const u32 fsflags_to_gfs2[32] = {
  154. [3] = GFS2_DIF_SYNC,
  155. [4] = GFS2_DIF_IMMUTABLE,
  156. [5] = GFS2_DIF_APPENDONLY,
  157. [7] = GFS2_DIF_NOATIME,
  158. [12] = GFS2_DIF_EXHASH,
  159. [14] = GFS2_DIF_JDATA,
  160. [20] = GFS2_DIF_DIRECTIO,
  161. };
  162. static const u32 gfs2_to_fsflags[32] = {
  163. [gfs2fl_Sync] = FS_SYNC_FL,
  164. [gfs2fl_Immutable] = FS_IMMUTABLE_FL,
  165. [gfs2fl_AppendOnly] = FS_APPEND_FL,
  166. [gfs2fl_NoAtime] = FS_NOATIME_FL,
  167. [gfs2fl_ExHash] = FS_INDEX_FL,
  168. [gfs2fl_Jdata] = FS_JOURNAL_DATA_FL,
  169. [gfs2fl_Directio] = FS_DIRECTIO_FL,
  170. [gfs2fl_InheritDirectio] = FS_DIRECTIO_FL,
  171. [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
  172. };
  173. static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
  174. {
  175. struct inode *inode = filp->f_path.dentry->d_inode;
  176. struct gfs2_inode *ip = GFS2_I(inode);
  177. struct gfs2_holder gh;
  178. int error;
  179. u32 fsflags;
  180. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh);
  181. error = gfs2_glock_nq_atime(&gh);
  182. if (error)
  183. return error;
  184. fsflags = fsflags_cvt(gfs2_to_fsflags, ip->i_di.di_flags);
  185. if (put_user(fsflags, ptr))
  186. error = -EFAULT;
  187. gfs2_glock_dq_m(1, &gh);
  188. gfs2_holder_uninit(&gh);
  189. return error;
  190. }
  191. void gfs2_set_inode_flags(struct inode *inode)
  192. {
  193. struct gfs2_inode *ip = GFS2_I(inode);
  194. struct gfs2_dinode_host *di = &ip->i_di;
  195. unsigned int flags = inode->i_flags;
  196. flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
  197. if (di->di_flags & GFS2_DIF_IMMUTABLE)
  198. flags |= S_IMMUTABLE;
  199. if (di->di_flags & GFS2_DIF_APPENDONLY)
  200. flags |= S_APPEND;
  201. if (di->di_flags & GFS2_DIF_NOATIME)
  202. flags |= S_NOATIME;
  203. if (di->di_flags & GFS2_DIF_SYNC)
  204. flags |= S_SYNC;
  205. inode->i_flags = flags;
  206. }
  207. /* Flags that can be set by user space */
  208. #define GFS2_FLAGS_USER_SET (GFS2_DIF_JDATA| \
  209. GFS2_DIF_DIRECTIO| \
  210. GFS2_DIF_IMMUTABLE| \
  211. GFS2_DIF_APPENDONLY| \
  212. GFS2_DIF_NOATIME| \
  213. GFS2_DIF_SYNC| \
  214. GFS2_DIF_SYSTEM| \
  215. GFS2_DIF_INHERIT_DIRECTIO| \
  216. GFS2_DIF_INHERIT_JDATA)
  217. /**
  218. * gfs2_set_flags - set flags on an inode
  219. * @inode: The inode
  220. * @flags: The flags to set
  221. * @mask: Indicates which flags are valid
  222. *
  223. */
  224. static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
  225. {
  226. struct inode *inode = filp->f_path.dentry->d_inode;
  227. struct gfs2_inode *ip = GFS2_I(inode);
  228. struct gfs2_sbd *sdp = GFS2_SB(inode);
  229. struct buffer_head *bh;
  230. struct gfs2_holder gh;
  231. int error;
  232. u32 new_flags, flags;
  233. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  234. if (error)
  235. return error;
  236. flags = ip->i_di.di_flags;
  237. new_flags = (flags & ~mask) | (reqflags & mask);
  238. if ((new_flags ^ flags) == 0)
  239. goto out;
  240. if (S_ISDIR(inode->i_mode)) {
  241. if ((new_flags ^ flags) & GFS2_DIF_JDATA)
  242. new_flags ^= (GFS2_DIF_JDATA|GFS2_DIF_INHERIT_JDATA);
  243. if ((new_flags ^ flags) & GFS2_DIF_DIRECTIO)
  244. new_flags ^= (GFS2_DIF_DIRECTIO|GFS2_DIF_INHERIT_DIRECTIO);
  245. }
  246. error = -EINVAL;
  247. if ((new_flags ^ flags) & ~GFS2_FLAGS_USER_SET)
  248. goto out;
  249. error = -EPERM;
  250. if (IS_IMMUTABLE(inode) && (new_flags & GFS2_DIF_IMMUTABLE))
  251. goto out;
  252. if (IS_APPEND(inode) && (new_flags & GFS2_DIF_APPENDONLY))
  253. goto out;
  254. if (((new_flags ^ flags) & GFS2_DIF_IMMUTABLE) &&
  255. !capable(CAP_LINUX_IMMUTABLE))
  256. goto out;
  257. if (!IS_IMMUTABLE(inode)) {
  258. error = permission(inode, MAY_WRITE, NULL);
  259. if (error)
  260. goto out;
  261. }
  262. error = gfs2_trans_begin(sdp, RES_DINODE, 0);
  263. if (error)
  264. goto out;
  265. error = gfs2_meta_inode_buffer(ip, &bh);
  266. if (error)
  267. goto out_trans_end;
  268. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  269. ip->i_di.di_flags = new_flags;
  270. gfs2_dinode_out(ip, bh->b_data);
  271. brelse(bh);
  272. gfs2_set_inode_flags(inode);
  273. out_trans_end:
  274. gfs2_trans_end(sdp);
  275. out:
  276. gfs2_glock_dq_uninit(&gh);
  277. return error;
  278. }
  279. static int gfs2_set_flags(struct file *filp, u32 __user *ptr)
  280. {
  281. u32 fsflags, gfsflags;
  282. if (get_user(fsflags, ptr))
  283. return -EFAULT;
  284. gfsflags = fsflags_cvt(fsflags_to_gfs2, fsflags);
  285. return do_gfs2_set_flags(filp, gfsflags, ~0);
  286. }
  287. static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  288. {
  289. switch(cmd) {
  290. case FS_IOC_GETFLAGS:
  291. return gfs2_get_flags(filp, (u32 __user *)arg);
  292. case FS_IOC_SETFLAGS:
  293. return gfs2_set_flags(filp, (u32 __user *)arg);
  294. }
  295. return -ENOTTY;
  296. }
  297. /**
  298. * gfs2_mmap -
  299. * @file: The file to map
  300. * @vma: The VMA which described the mapping
  301. *
  302. * Returns: 0 or error code
  303. */
  304. static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
  305. {
  306. struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
  307. struct gfs2_holder i_gh;
  308. int error;
  309. gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &i_gh);
  310. error = gfs2_glock_nq_atime(&i_gh);
  311. if (error) {
  312. gfs2_holder_uninit(&i_gh);
  313. return error;
  314. }
  315. /* This is VM_MAYWRITE instead of VM_WRITE because a call
  316. to mprotect() can turn on VM_WRITE later. */
  317. if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) ==
  318. (VM_MAYSHARE | VM_MAYWRITE))
  319. vma->vm_ops = &gfs2_vm_ops_sharewrite;
  320. else
  321. vma->vm_ops = &gfs2_vm_ops_private;
  322. vma->vm_flags |= VM_CAN_INVALIDATE;
  323. gfs2_glock_dq_uninit(&i_gh);
  324. return error;
  325. }
  326. /**
  327. * gfs2_open - open a file
  328. * @inode: the inode to open
  329. * @file: the struct file for this opening
  330. *
  331. * Returns: errno
  332. */
  333. static int gfs2_open(struct inode *inode, struct file *file)
  334. {
  335. struct gfs2_inode *ip = GFS2_I(inode);
  336. struct gfs2_holder i_gh;
  337. struct gfs2_file *fp;
  338. int error;
  339. fp = kzalloc(sizeof(struct gfs2_file), GFP_KERNEL);
  340. if (!fp)
  341. return -ENOMEM;
  342. mutex_init(&fp->f_fl_mutex);
  343. gfs2_assert_warn(GFS2_SB(inode), !file->private_data);
  344. file->private_data = fp;
  345. if (S_ISREG(ip->i_inode.i_mode)) {
  346. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY,
  347. &i_gh);
  348. if (error)
  349. goto fail;
  350. if (!(file->f_flags & O_LARGEFILE) &&
  351. ip->i_di.di_size > MAX_NON_LFS) {
  352. error = -EFBIG;
  353. goto fail_gunlock;
  354. }
  355. /* Listen to the Direct I/O flag */
  356. if (ip->i_di.di_flags & GFS2_DIF_DIRECTIO)
  357. file->f_flags |= O_DIRECT;
  358. gfs2_glock_dq_uninit(&i_gh);
  359. }
  360. return 0;
  361. fail_gunlock:
  362. gfs2_glock_dq_uninit(&i_gh);
  363. fail:
  364. file->private_data = NULL;
  365. kfree(fp);
  366. return error;
  367. }
  368. /**
  369. * gfs2_close - called to close a struct file
  370. * @inode: the inode the struct file belongs to
  371. * @file: the struct file being closed
  372. *
  373. * Returns: errno
  374. */
  375. static int gfs2_close(struct inode *inode, struct file *file)
  376. {
  377. struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
  378. struct gfs2_file *fp;
  379. fp = file->private_data;
  380. file->private_data = NULL;
  381. if (gfs2_assert_warn(sdp, fp))
  382. return -EIO;
  383. kfree(fp);
  384. return 0;
  385. }
  386. /**
  387. * gfs2_fsync - sync the dirty data for a file (across the cluster)
  388. * @file: the file that points to the dentry (we ignore this)
  389. * @dentry: the dentry that points to the inode to sync
  390. *
  391. * The VFS will flush "normal" data for us. We only need to worry
  392. * about metadata here. For journaled data, we just do a log flush
  393. * as we can't avoid it. Otherwise we can just bale out if datasync
  394. * is set. For stuffed inodes we must flush the log in order to
  395. * ensure that all data is on disk.
  396. *
  397. * The call to write_inode_now() is there to write back metadata and
  398. * the inode itself. It does also try and write the data, but thats
  399. * (hopefully) a no-op due to the VFS having already called filemap_fdatawrite()
  400. * for us.
  401. *
  402. * Returns: errno
  403. */
  404. static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync)
  405. {
  406. struct inode *inode = dentry->d_inode;
  407. int sync_state = inode->i_state & (I_DIRTY_SYNC|I_DIRTY_DATASYNC);
  408. int ret = 0;
  409. if (gfs2_is_jdata(GFS2_I(inode))) {
  410. gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl);
  411. return 0;
  412. }
  413. if (sync_state != 0) {
  414. if (!datasync)
  415. ret = write_inode_now(inode, 0);
  416. if (gfs2_is_stuffed(GFS2_I(inode)))
  417. gfs2_log_flush(GFS2_SB(inode), GFS2_I(inode)->i_gl);
  418. }
  419. return ret;
  420. }
  421. /**
  422. * gfs2_setlease - acquire/release a file lease
  423. * @file: the file pointer
  424. * @arg: lease type
  425. * @fl: file lock
  426. *
  427. * Returns: errno
  428. */
  429. static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
  430. {
  431. struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
  432. /*
  433. * We don't currently have a way to enforce a lease across the whole
  434. * cluster; until we do, disable leases (by just returning -EINVAL),
  435. * unless the administrator has requested purely local locking.
  436. */
  437. if (!sdp->sd_args.ar_localflocks)
  438. return -EINVAL;
  439. return setlease(file, arg, fl);
  440. }
  441. /**
  442. * gfs2_lock - acquire/release a posix lock on a file
  443. * @file: the file pointer
  444. * @cmd: either modify or retrieve lock state, possibly wait
  445. * @fl: type and range of lock
  446. *
  447. * Returns: errno
  448. */
  449. static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
  450. {
  451. struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
  452. struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
  453. struct lm_lockname name =
  454. { .ln_number = ip->i_no_addr,
  455. .ln_type = LM_TYPE_PLOCK };
  456. if (!(fl->fl_flags & FL_POSIX))
  457. return -ENOLCK;
  458. if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
  459. return -ENOLCK;
  460. if (sdp->sd_args.ar_localflocks) {
  461. if (IS_GETLK(cmd)) {
  462. posix_test_lock(file, fl);
  463. return 0;
  464. } else {
  465. return posix_lock_file_wait(file, fl);
  466. }
  467. }
  468. if (cmd == F_CANCELLK) {
  469. /* Hack: */
  470. cmd = F_SETLK;
  471. fl->fl_type = F_UNLCK;
  472. }
  473. if (IS_GETLK(cmd))
  474. return gfs2_lm_plock_get(sdp, &name, file, fl);
  475. else if (fl->fl_type == F_UNLCK)
  476. return gfs2_lm_punlock(sdp, &name, file, fl);
  477. else
  478. return gfs2_lm_plock(sdp, &name, file, cmd, fl);
  479. }
  480. static int do_flock(struct file *file, int cmd, struct file_lock *fl)
  481. {
  482. struct gfs2_file *fp = file->private_data;
  483. struct gfs2_holder *fl_gh = &fp->f_fl_gh;
  484. struct gfs2_inode *ip = GFS2_I(file->f_path.dentry->d_inode);
  485. struct gfs2_glock *gl;
  486. unsigned int state;
  487. int flags;
  488. int error = 0;
  489. state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED;
  490. flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT | GL_NOCACHE;
  491. mutex_lock(&fp->f_fl_mutex);
  492. gl = fl_gh->gh_gl;
  493. if (gl) {
  494. if (fl_gh->gh_state == state)
  495. goto out;
  496. gfs2_glock_hold(gl);
  497. flock_lock_file_wait(file,
  498. &(struct file_lock){.fl_type = F_UNLCK});
  499. gfs2_glock_dq_uninit(fl_gh);
  500. } else {
  501. error = gfs2_glock_get(GFS2_SB(&ip->i_inode),
  502. ip->i_no_addr, &gfs2_flock_glops,
  503. CREATE, &gl);
  504. if (error)
  505. goto out;
  506. }
  507. gfs2_holder_init(gl, state, flags, fl_gh);
  508. gfs2_glock_put(gl);
  509. error = gfs2_glock_nq(fl_gh);
  510. if (error) {
  511. gfs2_holder_uninit(fl_gh);
  512. if (error == GLR_TRYFAILED)
  513. error = -EAGAIN;
  514. } else {
  515. error = flock_lock_file_wait(file, fl);
  516. gfs2_assert_warn(GFS2_SB(&ip->i_inode), !error);
  517. }
  518. out:
  519. mutex_unlock(&fp->f_fl_mutex);
  520. return error;
  521. }
  522. static void do_unflock(struct file *file, struct file_lock *fl)
  523. {
  524. struct gfs2_file *fp = file->private_data;
  525. struct gfs2_holder *fl_gh = &fp->f_fl_gh;
  526. mutex_lock(&fp->f_fl_mutex);
  527. flock_lock_file_wait(file, fl);
  528. if (fl_gh->gh_gl)
  529. gfs2_glock_dq_uninit(fl_gh);
  530. mutex_unlock(&fp->f_fl_mutex);
  531. }
  532. /**
  533. * gfs2_flock - acquire/release a flock lock on a file
  534. * @file: the file pointer
  535. * @cmd: either modify or retrieve lock state, possibly wait
  536. * @fl: type and range of lock
  537. *
  538. * Returns: errno
  539. */
  540. static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
  541. {
  542. struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
  543. struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
  544. if (!(fl->fl_flags & FL_FLOCK))
  545. return -ENOLCK;
  546. if ((ip->i_inode.i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
  547. return -ENOLCK;
  548. if (sdp->sd_args.ar_localflocks)
  549. return flock_lock_file_wait(file, fl);
  550. if (fl->fl_type == F_UNLCK) {
  551. do_unflock(file, fl);
  552. return 0;
  553. } else {
  554. return do_flock(file, cmd, fl);
  555. }
  556. }
  557. const struct file_operations gfs2_file_fops = {
  558. .llseek = gfs2_llseek,
  559. .read = do_sync_read,
  560. .aio_read = generic_file_aio_read,
  561. .write = do_sync_write,
  562. .aio_write = generic_file_aio_write,
  563. .unlocked_ioctl = gfs2_ioctl,
  564. .mmap = gfs2_mmap,
  565. .open = gfs2_open,
  566. .release = gfs2_close,
  567. .fsync = gfs2_fsync,
  568. .lock = gfs2_lock,
  569. .flock = gfs2_flock,
  570. .splice_read = generic_file_splice_read,
  571. .splice_write = generic_file_splice_write,
  572. .setlease = gfs2_setlease,
  573. };
  574. const struct file_operations gfs2_dir_fops = {
  575. .readdir = gfs2_readdir,
  576. .unlocked_ioctl = gfs2_ioctl,
  577. .open = gfs2_open,
  578. .release = gfs2_close,
  579. .fsync = gfs2_fsync,
  580. .lock = gfs2_lock,
  581. .flock = gfs2_flock,
  582. };