fops.c (a05f7bd9578b17521a9a5f3689f3934c082c6390) fops.c (487c607df790d366e67a7d6a30adf785cdd98e55)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
5 * Copyright (C) 2016 - 2020 Christoph Hellwig
6 */
7#include <linux/init.h>
8#include <linux/mm.h>
9#include <linux/blkdev.h>
10#include <linux/buffer_head.h>
11#include <linux/mpage.h>
12#include <linux/uio.h>
13#include <linux/namei.h>
14#include <linux/task_io_accounting_ops.h>
15#include <linux/falloc.h>
16#include <linux/suspend.h>
17#include <linux/fs.h>
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright (C) 2001 Andrea Arcangeli <andrea@suse.de> SuSE
5 * Copyright (C) 2016 - 2020 Christoph Hellwig
6 */
7#include <linux/init.h>
8#include <linux/mm.h>
9#include <linux/blkdev.h>
10#include <linux/buffer_head.h>
11#include <linux/mpage.h>
12#include <linux/uio.h>
13#include <linux/namei.h>
14#include <linux/task_io_accounting_ops.h>
15#include <linux/falloc.h>
16#include <linux/suspend.h>
17#include <linux/fs.h>
18#include <linux/iomap.h>
18#include <linux/module.h>
19#include "blk.h"
20
21static inline struct inode *bdev_file_inode(struct file *file)
22{
23 return file->f_mapping->host;
24}
25

--- 355 unchanged lines hidden (view full) ---

381 if (likely(nr_pages <= BIO_MAX_VECS)) {
382 if (is_sync_kiocb(iocb))
383 return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
384 return __blkdev_direct_IO_async(iocb, iter, nr_pages);
385 }
386 return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages));
387}
388
19#include <linux/module.h>
20#include "blk.h"
21
22static inline struct inode *bdev_file_inode(struct file *file)
23{
24 return file->f_mapping->host;
25}
26

--- 355 unchanged lines hidden (view full) ---

382 if (likely(nr_pages <= BIO_MAX_VECS)) {
383 if (is_sync_kiocb(iocb))
384 return __blkdev_direct_IO_simple(iocb, iter, nr_pages);
385 return __blkdev_direct_IO_async(iocb, iter, nr_pages);
386 }
387 return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages));
388}
389
390static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
391 unsigned int flags, struct iomap *iomap, struct iomap *srcmap)
392{
393 struct block_device *bdev = I_BDEV(inode);
394 loff_t isize = i_size_read(inode);
395
396 iomap->bdev = bdev;
397 iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev));
398 if (iomap->offset >= isize)
399 return -EIO;
400 iomap->type = IOMAP_MAPPED;
401 iomap->addr = iomap->offset;
402 iomap->length = isize - iomap->offset;
403 iomap->flags |= IOMAP_F_BUFFER_HEAD;
404 return 0;
405}
406
407static const struct iomap_ops blkdev_iomap_ops = {
408 .iomap_begin = blkdev_iomap_begin,
409};
410
389static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
390{
391 return block_write_full_page(page, blkdev_get_block, wbc);
392}
393
394static int blkdev_read_folio(struct file *file, struct folio *folio)
395{
396 return block_read_full_folio(folio, blkdev_get_block);

--- 154 unchanged lines hidden (view full) ---

551 iocb->ki_pos += written;
552 count -= written;
553 }
554 if (written != -EIOCBQUEUED)
555 iov_iter_revert(from, count - iov_iter_count(from));
556 return written;
557}
558
411static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
412{
413 return block_write_full_page(page, blkdev_get_block, wbc);
414}
415
416static int blkdev_read_folio(struct file *file, struct folio *folio)
417{
418 return block_read_full_folio(folio, blkdev_get_block);

--- 154 unchanged lines hidden (view full) ---

573 iocb->ki_pos += written;
574 count -= written;
575 }
576 if (written != -EIOCBQUEUED)
577 iov_iter_revert(from, count - iov_iter_count(from));
578 return written;
579}
580
581static ssize_t blkdev_buffered_write(struct kiocb *iocb, struct iov_iter *from)
582{
583 return iomap_file_buffered_write(iocb, from, &blkdev_iomap_ops);
584}
585
559/*
560 * Write data to the block device. Only intended for the block device itself
561 * and the raw driver which basically is a fake block device.
562 *
563 * Does not take i_mutex for the write and thus is not for general purpose
564 * use.
565 */
566static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)

--- 33 unchanged lines hidden (view full) ---

600 ret = file_update_time(file);
601 if (ret)
602 return ret;
603
604 if (iocb->ki_flags & IOCB_DIRECT) {
605 ret = blkdev_direct_write(iocb, from);
606 if (ret >= 0 && iov_iter_count(from))
607 ret = direct_write_fallback(iocb, from, ret,
586/*
587 * Write data to the block device. Only intended for the block device itself
588 * and the raw driver which basically is a fake block device.
589 *
590 * Does not take i_mutex for the write and thus is not for general purpose
591 * use.
592 */
593static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)

--- 33 unchanged lines hidden (view full) ---

627 ret = file_update_time(file);
628 if (ret)
629 return ret;
630
631 if (iocb->ki_flags & IOCB_DIRECT) {
632 ret = blkdev_direct_write(iocb, from);
633 if (ret >= 0 && iov_iter_count(from))
634 ret = direct_write_fallback(iocb, from, ret,
608 generic_perform_write(iocb, from));
635 blkdev_buffered_write(iocb, from));
609 } else {
636 } else {
610 ret = generic_perform_write(iocb, from);
637 ret = blkdev_buffered_write(iocb, from);
611 }
612
613 if (ret > 0)
614 ret = generic_write_sync(iocb, ret);
615 iov_iter_reexpand(from, iov_iter_count(from) + shorted);
616 return ret;
617}
618

--- 147 unchanged lines hidden ---
638 }
639
640 if (ret > 0)
641 ret = generic_write_sync(iocb, ret);
642 iov_iter_reexpand(from, iov_iter_count(from) + shorted);
643 return ret;
644}
645

--- 147 unchanged lines hidden ---