Function report

Linux Kernel

v5.5.9

Brick Technologies Co., Ltd

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

Name:When a process calls fcntl to attach a dnotify watch to a directory it ends* up here. Allocate both a mark for fsnotify to add and a dnotify_struct to be* attached to the fsnotify_mark.

Proto:int fcntl_dirnotify(int fd, struct file *filp, unsigned long arg)

Type:int

Parameter:

TypeParameterName
intfd
struct file *filp
unsigned longarg
255  id = files
257  destroy = 0 , error = 0
261  new_fsn_mark = NULL
262  dn = NULL
264  If Not dir_notify_enable Then
265  error = -EINVAL
266  Go to out_err
270  If (arg & ~Don't remove notifier ) == 0 Then
271  Called every time a file is closed. Looks first for a dnotify mark on the* inode. If one is found run all of the ->dn structures attached to that* mark for one relevant to this process closing the file and remove that* dnotify_struct
272  error = 0
273  Go to out_err
277  inode = file_inode(filp)
278  If Not S_ISDIR(i_mode) Then
279  error = -ENOTDIR
280  Go to out_err
287  mask = his conversion is done only at watch creation
289  error = security_path_notify( & f_path, mask, FSNOTIFY_OBJ_TYPE_INODE)
291  If error Then Go to out_err
295  dn = kmem_cache_alloc(dnotify_struct_cache, GFP_KERNEL)
296  If Not dn Then
297  error = -ENOMEM
298  Go to out_err
302  new_dn_mark = kmem_cache_alloc(dnotify_mark_cache, GFP_KERNEL)
303  If Not new_dn_mark Then
304  error = -ENOMEM
305  Go to out_err
309  new_fsn_mark = fsn_mark
310  Nothing fancy, just initialize lists and locks and counters.
311  Mask this mark is for [mark->lock, group->mark_mutex] = mask
312  dn = NULL
315  mutex_lock( & protect marks_list )
318  fsn_mark = Given a list of marks, find the mark associated with given group. If found* take a reference to that mark and return it, else return NULL.
319  If fsn_mark Then
320  dn_mark = container_of - cast a member of a structure out to the containing structure*@ptr: the pointer to the member.*@type: the type of the container struct this is embedded in.*@member: the name of the member within the struct.(fsn_mark, structdnotify_mark, fsn_mark)
321  spin_lock( & Protects inode / mnt pointers, flags, masks )
322  Else
323  error = fsnotify_add_inode_mark_locked(new_fsn_mark, inode, 0)
324  If error Then
326  Go to out_err
328  spin_lock( & Protects inode / mnt pointers, flags, masks )
329  fsn_mark = new_fsn_mark
330  dn_mark = new_dn_mark
332  new_fsn_mark = NULL
335  _read_lock() - mark the beginning of an RCU read-side critical section* When synchronize_rcu() is invoked on one CPU while other CPUs* are within RCU read-side critical sections, then the* synchronize_rcu() is guaranteed to block until after all the other
336  f = Check whether the specified fd has an open file.(fd)
337  _read_unlock() - marks the end of an RCU read-side critical section.* In most situations, rcu_read_unlock() is immune from deadlock.* However, in kernels built with CONFIG_RCU_BOOST, rcu_read_unlock()
344  If f != filp Then
351  If dn_mark == new_dn_mark Then destroy = 1
353  error = 0
354  Go to out
357  __f_setown(filp, task_pid(current process), PIDTYPE_TGID, 0)
359  error = If multiple processes watch the same inode with dnotify there is only one* dnotify mark in inode->i_fsnotify_marks but we chain a dnotify_struct* onto that mark. This function either attaches the new dnotify_struct onto
361  If Not error Then dn = NULL
365  Else if error == -EEXIST Then error = 0
368  When a process starts or stops watching an inode the set of events which* dnotify cares about for that inode may change. This function runs the* list of everything receiving dnotify events about this directory and calculates* the set of all those events
369  out :
370  spin_unlock( & Protects inode / mnt pointers, flags, masks )
372  If destroy Then Mark mark as detached, remove it from group list
374  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.
375  If destroy Then Free fsnotify mark
377  fsnotify_put_mark(fsn_mark)
378  out_err :
379  If new_fsn_mark Then fsnotify_put_mark(new_fsn_mark)
381  If dn Then kmem_cache_free(dnotify_struct_cache, dn)
383  Return error
Caller
NameDescribe
do_fcntl