函数逻辑报告

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

Source Code:fs\aio.c Create Date:2022-07-29 10:53:23
Last Modify:2020-03-12 14:18:49 Copyright©Brick
首页 函数Tree
注解内核,赢得工具下载SCCTEnglish

函数名称:x_alloc* Allocates and initializes an ioctx. Returns an ERR_PTR if it failed.

函数原型:static struct kioctx *ioctx_alloc(unsigned nr_events)

返回类型:struct kioctx

参数:

类型参数名称
unsignednr_events
703  mm等于mm
705  err等于负ENOMEM
711  max_reqs等于nr_events
722  nr_events等于两数取大(nr_events, num_possible_cpus() * 4)
723  nr_events乘等于2
726  如果nr_events大于0x10000000U除sizeof(structio_event)则
727  pr_debug("ENOMEM: nr_events too high\n")
728  返回:错误号
731  如果非nr_eventsmax_reqs大于system wide maximum number of aio requests 则返回:错误号
734  ctx等于Shortcuts
735  如果非ctx则返回:错误号
738  * This is what userspace passed to io_setup(), it's not used for * anything but counting against the global max_reqs quota. * The real limit is nr_events - 1, which will be larger (see * aio_setup_ring())等于max_reqs
740  spin_lock_init( & ctx_lock)
741  spin_lock_init( & completion_lock)
742  mutex_init - initialize the mutex*@mutex: the mutex to be initialized* Initialize the mutex to unlocked state.* It is not allowed to initialize an already locked mutex.( & ring_lock)
745  mutex_lock( & ring_lock)
746  init_waitqueue_head( & wait)
748  初始化链表头
750  如果percpu_ref_init - initialize a percpu refcount*@ref: percpu_ref to initialize*@release: function which will be called when refcount hits 0*@flags: PERCPU_REF_INIT_* flags*@gfp: allocation mask to use* Initializes @ref则转到:err
753  如果percpu_ref_init - initialize a percpu refcount*@ref: percpu_ref to initialize*@release: function which will be called when refcount hits 0*@flags: PERCPU_REF_INIT_* flags*@gfp: allocation mask to use* Initializes @ref则转到:err
756  cpu等于alloc_percpu(structkioctx_cpu)
757  如果非cpu则转到:err
760  err等于aio_setup_ring(ctx, nr_events)
761  如果err小于0则转到:err
764  atomic_set( & * This counts the number of available slots in the ringbuffer, * so we avoid overflowing it: it's decremented (if positive) * when allocating a kiocb and incremented when the resulting * io_event is pulled off the ringbuffer. * We batch accesses to it with, Size of ringbuffer, in units of struct io_event - 1)
765  * For percpu reqs_available, number of slots we move to/from global * counter at a time:等于 Size of ringbuffer, in units of struct io_event 减1的差除num_possible_cpus()乘4
766  如果* For percpu reqs_available, number of slots we move to/from global * counter at a time:小于1则* For percpu reqs_available, number of slots we move to/from global * counter at a time:等于1
770  加自旋锁
771  如果current system wide number of aio requests * This is what userspace passed to io_setup(), it's not used for * anything but counting against the global max_reqs quota. * The real limit is nr_events - 1, which will be larger (see * aio_setup_ring())大于system wide maximum number of aio requests current system wide number of aio requests * This is what userspace passed to io_setup(), it's not used for * anything but counting against the global max_reqs quota. * The real limit is nr_events - 1, which will be larger (see * aio_setup_ring())小于current system wide number of aio requests
773  自旋锁解锁
774  err等于负EAGAIN
775  转到:err_ctx
777  current system wide number of aio requests 加等于* This is what userspace passed to io_setup(), it's not used for * anything but counting against the global max_reqs quota. * The real limit is nr_events - 1, which will be larger (see * aio_setup_ring())
778  自旋锁解锁
780  percpu计数引用增
781  percpu计数引用增
783  err等于ioctx_add_table(ctx, mm)
784  如果err则转到:err_cleanup
788  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
790  pr_debug("allocated ioctx %p[%ld]: mm=%p mask=0x%x\n", ctx, user_id, mm, Size of ringbuffer, in units of struct io_event )
792  返回:ctx
794  err_cleanup :
795  aio_nr_sub(* This is what userspace passed to io_setup(), it's not used for * anything but counting against the global max_reqs quota. * The real limit is nr_events - 1, which will be larger (see * aio_setup_ring()))
796  err_ctx :
797  atomic_set( & dead, 1)
798  如果mmap_sizevm_munmap(mmap_base, mmap_size)
800  aio_free_ring(ctx)
801  err :
802  mutex_unlock - release the mutex*@lock: the mutex to be released* Unlock a mutex that has been locked by this task previously.* This function must not be used in interrupt context. Unlocking* of a not locked mutex is not allowed.
803  释放内存
804  percpu_ref_exit - undo percpu_ref_init()*@ref: percpu_ref to exit* This function exits @ref
805  percpu_ref_exit - undo percpu_ref_init()*@ref: percpu_ref to exit* This function exits @ref
806  kmem_cache_free(kioctx_cachep, ctx)
807  pr_debug("error allocating ioctx %d\n", err)
808  返回:错误号
调用者
名称描述
SYSCALL_DEFINE2sys_io_setup:* Create an aio_context capable of receiving at least nr_events
COMPAT_SYSCALL_DEFINE2