Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\direct-io.c Create Date:2022-07-28 20:15:13
Last Modify:2020-03-12 14:18:49 Copyright©Brick
home page Tree
Annotation kernel can get tool activityDownload SCCTChinese

Name:This is a library function for use by filesystem drivers

Proto:static inline ssize_t do_blockdev_direct_IO(struct kiocb *iocb, struct inode *inode, struct block_device *bdev, struct iov_iter *iter, get_block_t get_block, dio_iodone_t end_io, dio_submit_t submit_io, int flags)

Type:ssize_t

Parameter:

TypeParameterName
struct kiocb *iocb
struct inode *inode
struct block_device *bdev
struct iov_iter *iter
get_block_tget_block
dio_iodone_tend_io
dio_submit_tsubmit_io
intflags
1150  i_blkbits = READ_ONCE(i_blkbits)
1151  blkbits = i_blkbits
1152  blocksize_mask = (1 << blkbits) - 1
1153  retval = -EINVAL
1154  count = iov_iter_count(iter)
1155  offset = The 'ki_filp' pointer is shared in a union for aio
1156  end = offset + count
1158  struct dio_submit sdio = {0, }
1159  struct buffer_head map_bh = {0, }
1161  align = offset | iov_iter_alignment(iter)
1168  If align & blocksize_mask Then
1169  If bdev Then blkbits = assumes size > 256
1171  blocksize_mask = (1 << blkbits) - 1
1172  If align & blocksize_mask Then Go to out
1177  If iov_iter_rw(iter) == generic data direction definitions && Not count Then Return 0
1180  dio = kmem_cache_alloc(dio_cache, GFP_KERNEL)
1181  retval = -ENOMEM
1182  If Not dio Then Go to out
1189  memset(dio, 0, offsetof(structdio, pages))
1191  doesn't change = flags
1192  If doesn't change & DIO_LOCKING Then
1194  mapping = f_mapping
1198  inode_lock(inode)
1202  If retval Then
1205  Go to out
1211  _size when submitted = NOTE: in a 32bit arch with a preemptable kernel and* an UP compile the i_size_read/write must be atomic* with respect to the local cpu (unlike with preempt disabled),* but they don't need to be atomic with respect to other cpus like in* true SMP (so they
1212  If iov_iter_rw(iter) == generic data direction definitions && offset >= _size when submitted Then
1213  If doesn't change & DIO_LOCKING Then inode_unlock(inode)
1215  kmem_cache_free(dio_cache, dio)
1216  retval = 0
1217  Go to out
1226  If is_sync_kiocb(iocb) Then s IO async ? = false
1228  Else if iov_iter_rw(iter) == WRITE && end > NOTE: in a 32bit arch with a preemptable kernel and* an UP compile the i_size_read/write must be atomic* with respect to the local cpu (unlike with preempt disabled),* but they don't need to be atomic with respect to other cpus like in* true SMP (so they Then s IO async ? = false
1230  Else s IO async ? = true
1233  inode = inode
1234  If iov_iter_rw(iter) == WRITE Then
1235  op = REQ_OP_WRITE
1236  op_flags = REQ_SYNC | REQ_IDLE
1237  If ki_flags & IOCB_NOWAIT Then op_flags |= REQ_NOWAIT
1239  Else
1240  op = REQ_OP_READ
1242  If ki_flags & IOCB_HIPRI Then op_flags |= REQ_HIPRI
1249  If s IO async ? && iov_iter_rw(iter) == WRITE Then
1250  retval = 0
1251  If ki_flags & IOCB_DSYNC Then retval = dio_set_defer_completion(dio)
1253  Else if Not s_dio_done_wq Then
1261  If retval Then
1267  Go to out
1274  de_dio_begin - signal start of a direct I/O requests*@inode: inode the direct I/O happens on* This is called once we've finished processing a direct I/O request,* and is used to wake up callers waiting for direct I/O to be quiesced.
1276  retval = 0
1277  doesn't change = blkbits
1278  When we're using an alignment whichis finer than the filesystem's softblocksize, this specifies how muchfiner. blkfactor=2 means 1/4-blockalignment. Does not change = i_blkbits - blkbits
1279  Current offset into the underlyingfile in dio_block units. = offset >> blkbits
1281  lock mapping function = get_block
1282  IO completion function = end_io
1283  IO submition function = submit_io
1284  current final block in bio + 1 = -1
1285  xt block to be put under IO,in dio_blocks units = -1
1287  kiocb = iocb
1289  Process spin lock initialization( & protects BIO fields below )
1290  direct_io_worker() and bios = 1
1292  pages should be dirtied = iter_is_iovec(iter) && iov_iter_rw(iter) == generic data direction definitions
1293  iter = iter
1294  doesn't change = end >> blkbits
1300  If Value for the false possibility is greater at compile time(When we're using an alignment whichis finer than the filesystem's softblocksize, this specifies how muchfiner. blkfactor=2 means 1/4-blockalignment. Does not change ) Then approximate total IO pages = 2
1303  approximate total IO pages += iov_iter_npages(iter, INT_MAX)
1305  blk_start_plug( & plug)
1307  retval = Walk the user pages, and the file, mapping blocks to disk and generating* a sequence of (page,offset,len,block) mappings. These mappings are injected* into submit_page_section(), which takes care of the next stage of submission
1308  If retval Then Release any resources in case of a failure
1311  If retval == -ENOTBLK Then
1316  retval = 0
1322  If we are not writing the entire block and get_block() allocated* the block for us, we need to fill-in the unused portion of the* block with zeros
1324  If The page Then
1327  ret2 = Put cur_page under IO
1328  If retval == 0 Then retval = ret2
1330  Perform a free_page(), also freeing any swap cache associated with* this page if it is the last user of the page.
1331  The page = NULL
1333  If under assembly Then In the AIO read case we speculatively dirty the pages before starting IO.* During IO completion, any of these pages which happen to have been written* back will be redirtied by bio_check_pages_dirty().
1336  blk_finish_plug( & plug)
1342  Release any resources in case of a failure
1349  If iov_iter_rw(iter) == generic data direction definitions && doesn't change & DIO_LOCKING Then inode_unlock(inode)
1359  BUG_ON(retval == - cb queued, will get completion event )
1360  If s IO async ? && retval == 0 && IO result && ( iov_iter_rw(iter) == generic data direction definitions || IO result == count ) Then retval = -cb queued, will get completion event
1363  Else Wait on and process all in-flight BIOs
1366  If drop_refcount(dio) == 0 Then
1367  retval = dio_complete() - called when all DIO BIO I/O has been completed* This drops i_dio_count, lets interested parties know that a DIO operation* has completed, and calculates the resulting return code for the operation
1368  Else BUG_ON(retval != - cb queued, will get completion event )
1371  out :
1372  Return retval
Caller
NameDescribe
__blockdev_direct_IO