2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
8 * Linux VFS file operations.
12 #include "pvfs2-kernel.h"
13 #include "pvfs2-bufmap.h"
15 #include <linux/pagemap.h>
17 #define wake_up_daemon_for_return(op) \
19 spin_lock(&op->lock); \
20 op->io_completed = 1; \
21 spin_unlock(&op->lock); \
22 wake_up_interruptible(&op->io_completion_waitq);\
26 * Copy to client-core's address space from the buffers specified
27 * by the iovec upto total_size bytes.
28 * NOTE: the iovector can either contain addresses which
29 * can futher be kernel-space or user-space addresses.
30 * or it can pointers to struct page's
32 static int precopy_buffers(struct pvfs2_bufmap
*bufmap
,
34 const struct iovec
*vec
,
35 unsigned long nr_segs
,
42 * copy data from application/kernel by pulling it out
48 iov_iter_init(&iter
, WRITE
, vec
, nr_segs
, total_size
);
49 ret
= pvfs_bufmap_copy_from_iovec(bufmap
,
54 gossip_err("%s: Failed to copy-in buffers. Please make sure that the pvfs2-client is running. %ld\n",
61 gossip_err("%s: Failed to copy-in buffers. Please make sure that the pvfs2-client is running. %ld\n",
68 * Copy from client-core's address space to the buffers specified
69 * by the iovec upto total_size bytes.
70 * NOTE: the iovector can either contain addresses which
71 * can futher be kernel-space or user-space addresses.
72 * or it can pointers to struct page's
74 static int postcopy_buffers(struct pvfs2_bufmap
*bufmap
,
76 const struct iovec
*vec
,
85 * copy data to application/kernel by pushing it out to
86 * the iovec. NOTE; target buffers can be addresses or
87 * struct page pointers.
90 iov_iter_init(&iter
, READ
, vec
, nr_segs
, total_size
);
91 ret
= pvfs_bufmap_copy_to_iovec(bufmap
,
95 gossip_err("%s: Failed to copy-out buffers. Please make sure that the pvfs2-client is running (%ld)\n",
103 * Post and wait for the I/O upcall to finish
105 static ssize_t
wait_for_direct_io(enum PVFS_io_type type
, struct inode
*inode
,
106 loff_t
*offset
, struct iovec
*vec
, unsigned long nr_segs
,
107 size_t total_size
, loff_t readahead_size
)
109 struct pvfs2_inode_s
*pvfs2_inode
= PVFS2_I(inode
);
110 struct pvfs2_khandle
*handle
= &pvfs2_inode
->refn
.khandle
;
111 struct pvfs2_bufmap
*bufmap
= NULL
;
112 struct pvfs2_kernel_op_s
*new_op
= NULL
;
113 int buffer_index
= -1;
116 new_op
= op_alloc(PVFS2_VFS_OP_FILE_IO
);
121 /* synchronous I/O */
122 new_op
->upcall
.req
.io
.async_vfs_io
= PVFS_VFS_SYNC_IO
;
123 new_op
->upcall
.req
.io
.readahead_size
= readahead_size
;
124 new_op
->upcall
.req
.io
.io_type
= type
;
125 new_op
->upcall
.req
.io
.refn
= pvfs2_inode
->refn
;
127 populate_shared_memory
:
128 /* get a shared buffer index */
129 ret
= pvfs_bufmap_get(&bufmap
, &buffer_index
);
131 gossip_debug(GOSSIP_FILE_DEBUG
,
132 "%s: pvfs_bufmap_get failure (%ld)\n",
133 __func__
, (long)ret
);
136 gossip_debug(GOSSIP_FILE_DEBUG
,
137 "%s(%pU): GET op %p -> buffer_index %d\n",
143 new_op
->uses_shared_memory
= 1;
144 new_op
->upcall
.req
.io
.buf_index
= buffer_index
;
145 new_op
->upcall
.req
.io
.count
= total_size
;
146 new_op
->upcall
.req
.io
.offset
= *offset
;
148 gossip_debug(GOSSIP_FILE_DEBUG
,
149 "%s(%pU): nr_segs %lu, offset: %llu total_size: %zd\n",
156 * Stage 1: copy the buffers into client-core's address space
157 * precopy_buffers only pertains to writes.
159 if (type
== PVFS_IO_WRITE
) {
160 ret
= precopy_buffers(bufmap
,
169 gossip_debug(GOSSIP_FILE_DEBUG
,
170 "%s(%pU): Calling post_io_request with tag (%llu)\n",
175 /* Stage 2: Service the I/O operation */
176 ret
= service_operation(new_op
,
177 type
== PVFS_IO_WRITE
?
180 get_interruptible_flag(inode
));
183 * If service_operation() returns -EAGAIN #and# the operation was
184 * purged from pvfs2_request_list or htable_ops_in_progress, then
185 * we know that the client was restarted, causing the shared memory
186 * area to be wiped clean. To restart a write operation in this
187 * case, we must re-copy the data from the user's iovec to a NEW
188 * shared memory location. To restart a read operation, we must get
189 * a new shared memory location.
191 if (ret
== -EAGAIN
&& op_state_purged(new_op
)) {
192 pvfs_bufmap_put(bufmap
, buffer_index
);
193 gossip_debug(GOSSIP_FILE_DEBUG
,
194 "%s:going to repopulate_shared_memory.\n",
196 goto populate_shared_memory
;
200 handle_io_error(); /* defined in pvfs2-kernel.h */
202 don't write an error to syslog on signaled operation
203 termination unless we've got debugging turned on, as
204 this can happen regularly (i.e. ctrl-c)
207 gossip_debug(GOSSIP_FILE_DEBUG
,
208 "%s: returning error %ld\n", __func__
,
211 gossip_err("%s: error in %s handle %pU, returning %zd\n",
213 type
== PVFS_IO_READ
?
214 "read from" : "write to",
220 * Stage 3: Post copy buffers from client-core's address space
221 * postcopy_buffers only pertains to reads.
223 if (type
== PVFS_IO_READ
) {
224 ret
= postcopy_buffers(bufmap
,
228 new_op
->downcall
.resp
.io
.amt_complete
);
231 * put error codes in downcall so that handle_io_error()
232 * preserves it properly
234 new_op
->downcall
.status
= ret
;
239 gossip_debug(GOSSIP_FILE_DEBUG
,
240 "%s(%pU): Amount written as returned by the sys-io call:%d\n",
243 (int)new_op
->downcall
.resp
.io
.amt_complete
);
245 ret
= new_op
->downcall
.resp
.io
.amt_complete
;
248 tell the device file owner waiting on I/O that this read has
249 completed and it can return now. in this exact case, on
250 wakeup the daemon will free the op, so we *cannot* touch it
253 wake_up_daemon_for_return(new_op
);
257 if (buffer_index
>= 0) {
258 pvfs_bufmap_put(bufmap
, buffer_index
);
259 gossip_debug(GOSSIP_FILE_DEBUG
,
260 "%s(%pU): PUT buffer_index %d\n",
261 __func__
, handle
, buffer_index
);
272 * The reason we need to do this is to be able to support readv and writev
273 * that are larger than (pvfs_bufmap_size_query()) Default is
274 * PVFS2_BUFMAP_DEFAULT_DESC_SIZE MB. What that means is that we will
275 * create a new io vec descriptor for those memory addresses that
276 * go beyond the limit. Return value for this routine is negative in case
277 * of errors and 0 in case of success.
279 * Further, the new_nr_segs pointer is updated to hold the new value
280 * of number of iovecs, the new_vec pointer is updated to hold the pointer
281 * to the new split iovec, and the size array is an array of integers holding
282 * the number of iovecs that straddle pvfs_bufmap_size_query().
283 * The max_new_nr_segs value is computed by the caller and returned.
284 * (It will be (count of all iov_len/ block_size) + 1).
286 static int split_iovecs(unsigned long max_new_nr_segs
, /* IN */
287 unsigned long nr_segs
, /* IN */
288 const struct iovec
*original_iovec
, /* IN */
289 unsigned long *new_nr_segs
, /* OUT */
290 struct iovec
**new_vec
, /* OUT */
291 unsigned long *seg_count
, /* OUT */
292 unsigned long **seg_array
) /* OUT */
295 unsigned long count
= 0;
296 unsigned long begin_seg
;
297 unsigned long tmpnew_nr_segs
= 0;
298 struct iovec
*new_iovec
= NULL
;
299 struct iovec
*orig_iovec
;
300 unsigned long *sizes
= NULL
;
301 unsigned long sizes_count
= 0;
304 original_iovec
== NULL
||
305 new_nr_segs
== NULL
||
309 max_new_nr_segs
<= 0) {
310 gossip_err("Invalid parameters to split_iovecs\n");
317 /* copy the passed in iovec descriptor to a temp structure */
318 orig_iovec
= kmalloc_array(nr_segs
,
320 PVFS2_BUFMAP_GFP_FLAGS
);
321 if (orig_iovec
== NULL
) {
323 "split_iovecs: Could not allocate memory for %lu bytes!\n",
324 (unsigned long)(nr_segs
* sizeof(*orig_iovec
)));
327 new_iovec
= kcalloc(max_new_nr_segs
,
329 PVFS2_BUFMAP_GFP_FLAGS
);
330 if (new_iovec
== NULL
) {
333 "split_iovecs: Could not allocate memory for %lu bytes!\n",
334 (unsigned long)(max_new_nr_segs
* sizeof(*new_iovec
)));
337 sizes
= kcalloc(max_new_nr_segs
,
339 PVFS2_BUFMAP_GFP_FLAGS
);
344 "split_iovecs: Could not allocate memory for %lu bytes!\n",
345 (unsigned long)(max_new_nr_segs
* sizeof(*sizes
)));
348 /* copy the passed in iovec to a temp structure */
349 memcpy(orig_iovec
, original_iovec
, nr_segs
* sizeof(*orig_iovec
));
352 for (seg
= begin_seg
; seg
< nr_segs
; seg
++) {
353 if (tmpnew_nr_segs
>= max_new_nr_segs
||
354 sizes_count
>= max_new_nr_segs
) {
359 ("split_iovecs: exceeded the index limit (%lu)\n",
363 if (count
+ orig_iovec
[seg
].iov_len
<
364 pvfs_bufmap_size_query()) {
365 count
+= orig_iovec
[seg
].iov_len
;
366 memcpy(&new_iovec
[tmpnew_nr_segs
],
370 sizes
[sizes_count
]++;
372 new_iovec
[tmpnew_nr_segs
].iov_base
=
373 orig_iovec
[seg
].iov_base
;
374 new_iovec
[tmpnew_nr_segs
].iov_len
=
375 (pvfs_bufmap_size_query() - count
);
377 sizes
[sizes_count
]++;
380 orig_iovec
[seg
].iov_base
+=
381 (pvfs_bufmap_size_query() - count
);
382 orig_iovec
[seg
].iov_len
-=
383 (pvfs_bufmap_size_query() - count
);
393 *new_nr_segs
= tmpnew_nr_segs
;
394 /* new_iovec is freed by the caller */
395 *new_vec
= new_iovec
;
396 *seg_count
= sizes_count
;
397 /* seg_array is also freed by the caller */
403 static long bound_max_iovecs(const struct iovec
*curr
, unsigned long nr_segs
,
404 ssize_t
*total_count
)
414 for (i
= 0; i
< nr_segs
; i
++) {
415 const struct iovec
*iv
= &curr
[i
];
417 count
+= iv
->iov_len
;
418 if (unlikely((ssize_t
) (count
| iv
->iov_len
) < 0))
420 if (total
+ iv
->iov_len
< pvfs_bufmap_size_query()) {
421 total
+= iv
->iov_len
;
425 (total
+ iv
->iov_len
- pvfs_bufmap_size_query());
426 max_nr_iovecs
+= (total
/ pvfs_bufmap_size_query() + 2);
429 *total_count
= count
;
430 return max_nr_iovecs
;
434 * Common entry point for read/write/readv/writev
435 * This function will dispatch it to either the direct I/O
436 * or buffered I/O path depending on the mount options and/or
437 * augmented/extended metadata attached to the file.
438 * Note: File extended attributes override any mount options.
440 static ssize_t
do_readv_writev(enum PVFS_io_type type
, struct file
*file
,
441 loff_t
*offset
, const struct iovec
*iov
, unsigned long nr_segs
)
443 struct inode
*inode
= file
->f_mapping
->host
;
444 struct pvfs2_inode_s
*pvfs2_inode
= PVFS2_I(inode
);
445 struct pvfs2_khandle
*handle
= &pvfs2_inode
->refn
.khandle
;
448 unsigned int to_free
;
451 unsigned long new_nr_segs
;
452 unsigned long max_new_nr_segs
;
453 unsigned long seg_count
;
454 unsigned long *seg_array
;
455 struct iovec
*iovecptr
;
463 /* Compute total and max number of segments after split */
464 max_new_nr_segs
= bound_max_iovecs(iov
, nr_segs
, &count
);
466 gossip_debug(GOSSIP_FILE_DEBUG
,
467 "%s-BEGIN(%pU): count(%d) after estimate_max_iovecs.\n",
472 if (type
== PVFS_IO_WRITE
) {
473 gossip_debug(GOSSIP_FILE_DEBUG
,
474 "%s(%pU): proceeding with offset : %llu, "
488 * if the total size of data transfer requested is greater than
489 * the kernel-set blocksize of PVFS2, then we split the iovecs
490 * such that no iovec description straddles a block size limit
493 gossip_debug(GOSSIP_FILE_DEBUG
,
494 "%s: pvfs_bufmap_size:%d\n",
496 pvfs_bufmap_size_query());
498 if (count
> pvfs_bufmap_size_query()) {
500 * Split up the given iovec description such that
501 * no iovec descriptor straddles over the block-size limitation.
502 * This makes us our job easier to stage the I/O.
503 * In addition, this function will also compute an array
504 * with seg_count entries that will store the number of
505 * segments that straddle the block-size boundaries.
507 ret
= split_iovecs(max_new_nr_segs
, /* IN */
510 &new_nr_segs
, /* OUT */
512 &seg_count
, /* OUT */
513 &seg_array
); /* OUT */
515 gossip_err("%s: Failed to split iovecs to satisfy larger than blocksize readv/writev request %zd\n",
520 gossip_debug(GOSSIP_FILE_DEBUG
,
521 "%s: Splitting iovecs from %lu to %lu"
527 /* We must free seg_array and iovecptr */
530 new_nr_segs
= nr_segs
;
531 /* use the given iovec description */
532 iovecptr
= (struct iovec
*)iov
;
533 /* There is only 1 element in the seg_array */
535 /* and its value is the number of segments passed in */
536 seg_array
= &nr_segs
;
537 /* We dont have to free up anything */
542 gossip_debug(GOSSIP_FILE_DEBUG
,
543 "%s(%pU) %zd@%llu\n",
548 gossip_debug(GOSSIP_FILE_DEBUG
,
549 "%s(%pU): new_nr_segs: %lu, seg_count: %lu\n",
552 new_nr_segs
, seg_count
);
554 /* PVFS2_KERNEL_DEBUG is a CFLAGS define. */
555 #ifdef PVFS2_KERNEL_DEBUG
556 for (seg
= 0; seg
< new_nr_segs
; seg
++)
557 gossip_debug(GOSSIP_FILE_DEBUG
,
558 "%s: %d) %p to %p [%d bytes]\n",
561 iovecptr
[seg
].iov_base
,
562 iovecptr
[seg
].iov_base
+ iovecptr
[seg
].iov_len
,
563 (int)iovecptr
[seg
].iov_len
);
564 for (seg
= 0; seg
< seg_count
; seg
++)
565 gossip_debug(GOSSIP_FILE_DEBUG
,
572 while (total_count
< count
) {
576 /* how much to transfer in this loop iteration */
578 (((count
- total_count
) > pvfs_bufmap_size_query()) ?
579 pvfs_bufmap_size_query() :
580 (count
- total_count
));
582 gossip_debug(GOSSIP_FILE_DEBUG
,
583 "%s(%pU): size of each_count(%d)\n",
587 gossip_debug(GOSSIP_FILE_DEBUG
,
588 "%s(%pU): BEFORE wait_for_io: offset is %d\n",
593 ret
= wait_for_direct_io(type
, inode
, offset
, ptr
,
594 seg_array
[seg
], each_count
, 0);
595 gossip_debug(GOSSIP_FILE_DEBUG
,
596 "%s(%pU): return from wait_for_io:%d\n",
604 /* advance the iovec pointer */
605 ptr
+= seg_array
[seg
];
611 gossip_debug(GOSSIP_FILE_DEBUG
,
612 "%s(%pU): AFTER wait_for_io: offset is %d\n",
618 * if we got a short I/O operations,
619 * fall out and return what we got so far
621 if (amt_complete
< each_count
)
633 if (type
== PVFS_IO_READ
) {
636 SetMtimeFlag(pvfs2_inode
);
637 inode
->i_mtime
= CURRENT_TIME
;
638 mark_inode_dirty_sync(inode
);
642 gossip_debug(GOSSIP_FILE_DEBUG
,
643 "%s(%pU): Value(%d) returned.\n",
652 * Read data from a specified offset in a file (referenced by inode).
653 * Data may be placed either in a user or kernel buffer.
655 ssize_t
pvfs2_inode_read(struct inode
*inode
,
659 loff_t readahead_size
)
661 struct pvfs2_inode_s
*pvfs2_inode
= PVFS2_I(inode
);
664 ssize_t ret
= -EINVAL
;
666 g_pvfs2_stats
.reads
++;
671 bufmap_size
= pvfs_bufmap_size_query();
672 if (count
> bufmap_size
) {
673 gossip_debug(GOSSIP_FILE_DEBUG
,
674 "%s: count is too large (%zd/%zd)!\n",
675 __func__
, count
, bufmap_size
);
679 gossip_debug(GOSSIP_FILE_DEBUG
,
680 "%s(%pU) %zd@%llu\n",
682 &pvfs2_inode
->refn
.khandle
,
686 ret
= wait_for_direct_io(PVFS_IO_READ
, inode
, offset
, &vec
, 1,
687 count
, readahead_size
);
691 gossip_debug(GOSSIP_FILE_DEBUG
,
692 "%s(%pU): Value(%zd) returned.\n",
694 &pvfs2_inode
->refn
.khandle
,
700 static ssize_t
pvfs2_file_read_iter(struct kiocb
*iocb
, struct iov_iter
*iter
)
702 struct file
*file
= iocb
->ki_filp
;
703 loff_t pos
= *(&iocb
->ki_pos
);
705 unsigned long nr_segs
= iter
->nr_segs
;
707 BUG_ON(iocb
->private);
709 gossip_debug(GOSSIP_FILE_DEBUG
, "pvfs2_file_read_iter\n");
711 g_pvfs2_stats
.reads
++;
713 rc
= do_readv_writev(PVFS_IO_READ
,
723 static ssize_t
pvfs2_file_write_iter(struct kiocb
*iocb
, struct iov_iter
*iter
)
725 struct file
*file
= iocb
->ki_filp
;
726 loff_t pos
= *(&iocb
->ki_pos
);
727 unsigned long nr_segs
= iter
->nr_segs
;
730 BUG_ON(iocb
->private);
732 gossip_debug(GOSSIP_FILE_DEBUG
, "pvfs2_file_write_iter\n");
734 mutex_lock(&file
->f_mapping
->host
->i_mutex
);
736 /* Make sure generic_write_checks sees an up to date inode size. */
737 if (file
->f_flags
& O_APPEND
) {
738 rc
= pvfs2_inode_getattr(file
->f_mapping
->host
,
741 gossip_err("%s: pvfs2_inode_getattr failed, rc:%zd:.\n",
747 if (file
->f_pos
> i_size_read(file
->f_mapping
->host
))
748 pvfs2_i_size_write(file
->f_mapping
->host
, file
->f_pos
);
750 rc
= generic_write_checks(iocb
, iter
);
753 gossip_err("%s: generic_write_checks failed, rc:%zd:.\n",
758 rc
= do_readv_writev(PVFS_IO_WRITE
,
764 gossip_err("%s: do_readv_writev failed, rc:%zd:.\n",
770 g_pvfs2_stats
.writes
++;
774 mutex_unlock(&file
->f_mapping
->host
->i_mutex
);
779 * Perform a miscellaneous operation on a file.
781 static long pvfs2_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
787 gossip_debug(GOSSIP_FILE_DEBUG
,
788 "pvfs2_ioctl: called with cmd %d\n",
792 * we understand some general ioctls on files, such as the immutable
795 if (cmd
== FS_IOC_GETFLAGS
) {
797 ret
= pvfs2_xattr_get_default(file
->f_path
.dentry
,
798 "user.pvfs2.meta_hint",
802 if (ret
< 0 && ret
!= -ENODATA
)
804 else if (ret
== -ENODATA
)
807 gossip_debug(GOSSIP_FILE_DEBUG
,
808 "pvfs2_ioctl: FS_IOC_GETFLAGS: %llu\n",
809 (unsigned long long)uval
);
810 return put_user(uval
, (int __user
*)arg
);
811 } else if (cmd
== FS_IOC_SETFLAGS
) {
813 if (get_user(uval
, (int __user
*)arg
))
816 * PVFS_MIRROR_FL is set internally when the mirroring mode
817 * is turned on for a file. The user is not allowed to turn
818 * on this bit, but the bit is present if the user first gets
819 * the flags and then updates the flags with some new
820 * settings. So, we ignore it in the following edit. bligon.
822 if ((uval
& ~PVFS_MIRROR_FL
) &
823 (~(FS_IMMUTABLE_FL
| FS_APPEND_FL
| FS_NOATIME_FL
))) {
824 gossip_err("pvfs2_ioctl: the FS_IOC_SETFLAGS only supports setting one of FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NOATIME_FL\n");
828 gossip_debug(GOSSIP_FILE_DEBUG
,
829 "pvfs2_ioctl: FS_IOC_SETFLAGS: %llu\n",
830 (unsigned long long)val
);
831 ret
= pvfs2_xattr_set_default(file
->f_path
.dentry
,
832 "user.pvfs2.meta_hint",
843 * Memory map a region of a file.
845 static int pvfs2_file_mmap(struct file
*file
, struct vm_area_struct
*vma
)
847 gossip_debug(GOSSIP_FILE_DEBUG
,
848 "pvfs2_file_mmap: called on %s\n",
850 (char *)file
->f_path
.dentry
->d_name
.name
:
853 /* set the sequential readahead hint */
854 vma
->vm_flags
|= VM_SEQ_READ
;
855 vma
->vm_flags
&= ~VM_RAND_READ
;
857 /* Use readonly mmap since we cannot support writable maps. */
858 return generic_file_readonly_mmap(file
, vma
);
861 #define mapping_nrpages(idata) ((idata)->nrpages)
864 * Called to notify the module that there are no more references to
865 * this file (i.e. no processes have it open).
867 * \note Not called when each file is closed.
869 static int pvfs2_file_release(struct inode
*inode
, struct file
*file
)
871 gossip_debug(GOSSIP_FILE_DEBUG
,
872 "pvfs2_file_release: called on %s\n",
873 file
->f_path
.dentry
->d_name
.name
);
875 pvfs2_flush_inode(inode
);
878 remove all associated inode pages from the page cache and mmap
879 readahead cache (if any); this forces an expensive refresh of
880 data for the next caller of mmap (or 'get_block' accesses)
882 if (file
->f_path
.dentry
->d_inode
&&
883 file
->f_path
.dentry
->d_inode
->i_mapping
&&
884 mapping_nrpages(&file
->f_path
.dentry
->d_inode
->i_data
))
885 truncate_inode_pages(file
->f_path
.dentry
->d_inode
->i_mapping
,
891 * Push all data for a specific file onto permanent storage.
893 static int pvfs2_fsync(struct file
*file
,
899 struct pvfs2_inode_s
*pvfs2_inode
=
900 PVFS2_I(file
->f_path
.dentry
->d_inode
);
901 struct pvfs2_kernel_op_s
*new_op
= NULL
;
904 filemap_write_and_wait_range(file
->f_mapping
, start
, end
);
906 new_op
= op_alloc(PVFS2_VFS_OP_FSYNC
);
909 new_op
->upcall
.req
.fsync
.refn
= pvfs2_inode
->refn
;
911 ret
= service_operation(new_op
,
913 get_interruptible_flag(file
->f_path
.dentry
->d_inode
));
915 gossip_debug(GOSSIP_FILE_DEBUG
,
916 "pvfs2_fsync got return value of %d\n",
921 pvfs2_flush_inode(file
->f_path
.dentry
->d_inode
);
926 * Change the file pointer position for an instance of an open file.
928 * \note If .llseek is overriden, we must acquire lock as described in
929 * Documentation/filesystems/Locking.
931 * Future upgrade could support SEEK_DATA and SEEK_HOLE but would
932 * require much changes to the FS
934 static loff_t
pvfs2_file_llseek(struct file
*file
, loff_t offset
, int origin
)
937 struct inode
*inode
= file
->f_path
.dentry
->d_inode
;
940 gossip_err("pvfs2_file_llseek: invalid inode (NULL)\n");
944 if (origin
== PVFS2_SEEK_END
) {
946 * revalidate the inode's file size.
947 * NOTE: We are only interested in file size here,
948 * so we set mask accordingly.
950 ret
= pvfs2_inode_getattr(inode
, PVFS_ATTR_SYS_SIZE
);
952 gossip_debug(GOSSIP_FILE_DEBUG
,
953 "%s:%s:%d calling make bad inode\n",
957 pvfs2_make_bad_inode(inode
);
962 gossip_debug(GOSSIP_FILE_DEBUG
,
963 "pvfs2_file_llseek: offset is %ld | origin is %d | "
964 "inode size is %lu\n",
967 (unsigned long)file
->f_path
.dentry
->d_inode
->i_size
);
969 return generic_file_llseek(file
, offset
, origin
);
973 * Support local locks (locks that only this kernel knows about)
974 * if Orangefs was mounted -o local_lock.
976 static int pvfs2_lock(struct file
*filp
, int cmd
, struct file_lock
*fl
)
980 if (PVFS2_SB(filp
->f_inode
->i_sb
)->flags
& PVFS2_OPT_LOCAL_LOCK
) {
981 if (cmd
== F_GETLK
) {
983 posix_test_lock(filp
, fl
);
985 rc
= posix_lock_file(filp
, fl
, NULL
);
992 /** PVFS2 implementation of VFS file operations */
993 const struct file_operations pvfs2_file_operations
= {
994 .llseek
= pvfs2_file_llseek
,
995 .read_iter
= pvfs2_file_read_iter
,
996 .write_iter
= pvfs2_file_write_iter
,
998 .unlocked_ioctl
= pvfs2_ioctl
,
999 .mmap
= pvfs2_file_mmap
,
1000 .open
= generic_file_open
,
1001 .release
= pvfs2_file_release
,
1002 .fsync
= pvfs2_fsync
,