Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:aio_setup_ring

Proto:static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events)

Type:int

Parameter:

TypeParameterName
struct kioctx *ctx
unsigned intnr_events
463  mm = mm
470  nr_events += 2
472  size = sizeof(structaio_ring)
473  size += sizeof(structio_event) * nr_events
475  nr_pages = PFN_UP(size)
476  If nr_pages < 0 Then Return -EINVAL
479  file = aio_private_file(ctx, nr_pages)
480  If IS_ERR(file) Then
481  aio_ring_file = NULL
482  Return -ENOMEM
485  aio_ring_file = file
486  nr_events = ( PAGE_SIZE * nr_pages - sizeof(structaio_ring)) / sizeof(structio_event)
489  ring_pages = internal_pages
490  If nr_pages > AIO_RING_PAGES Then
491  ring_pages = kcalloc - allocate memory for an array. The memory is set to zero.*@n: number of elements.*@size: element size.*@flags: the type of memory to allocate (see kmalloc).
493  If Not ring_pages Then
495  Return -ENOMEM
499  When i < nr_pages cycle
501  page = d_or_create_page - locate or add a pagecache page*@mapping: the page's address_space*@index: the page's index into the mapping*@gfp_mask: page allocation mode* Looks up the page cache slot at @mapping & @offset
503  If Not page Then Break
505  pr_debug("pid(%d) page[%d]->count=%d\n", pid, i, page_count(page))
507  SetPageUptodate(page)
508  lock_page - unlock a locked page*@page: the page* Unlocks the page and wakes up sleepers in ___wait_on_page_locked().* Also wakes sleepers in wait_on_page_writeback() because the wakeup* mechanism between PageLocked pages and PageWriteback pages is shared.
510  ring_pages[i] = page
512  nr_pages = i
514  If Value for the false possibility is greater at compile time(i != nr_pages) Then
515  aio_free_ring(ctx)
516  Return -ENOMEM
519  mmap_size = nr_pages * PAGE_SIZE
520  pr_debug("attempting mmap of %lu bytes\n", mmap_size)
522  If lock for writing Then
523  mmap_size = 0
524  aio_free_ring(ctx)
525  Return -EINTR
528  mmap_base = do_mmap_pgoff(aio_ring_file, 0, mmap_size, page can be read | page can be written , Share changes , 0, & unused, NULL)
531  lease a write lock
532  If IS_ERR((void * )mmap_base) Then
533  mmap_size = 0
534  aio_free_ring(ctx)
535  Return -ENOMEM
538  pr_debug("mmap address: 0x%08lx\n", mmap_base)
540  user_id = mmap_base
541  Size of ringbuffer, in units of struct io_event = nr_events
543  ring = kmap_atomic(ring_pages[0])
544  number of io_events = nr_events
545  kernel internal index number = ~0U
546  Written to by userland or under ring_lock * mutex by aio_read_events_ring(). = tail = 0
547  magic = AIO_RING_MAGIC
548  compat_features = AIO_RING_COMPAT_FEATURES
549  incompat_features = AIO_RING_INCOMPAT_FEATURES
550  size of aio_ring = sizeof(structaio_ring)
551  Prevent people trying to call kunmap_atomic() as if it were kunmap()* kunmap_atomic() should get the return value of kmap_atomic, not the page.(ring)
552  flush_dcache_page(ring_pages[0])
554  Return 0
Caller
NameDescribe
ioctx_allocx_alloc* Allocates and initializes an ioctx. Returns an ERR_PTR if it failed.