Skip to content
  • Al Viro's avatar
    get rid of the magic around f_count in aio · d7065da0
    Al Viro authored
    
    
    __aio_put_req() plays sick games with file refcount.  What
    it wants is fput() from atomic context; it's almost always
    done with f_count > 1, so they only have to deal with delayed
    work in rare cases when their reference happens to be the
    last one.  Current code decrements f_count and if it hasn't
    hit 0, everything is fine.  Otherwise it keeps a pointer
    to struct file (with zero f_count!) around and has delayed
    work do __fput() on it.
    
    Better way to do it: use atomic_long_add_unless( , -1, 1)
    instead of !atomic_long_dec_and_test().  IOW, decrement it
    only if it's not the last reference, leave refcount alone
    if it was.  And use normal fput() in delayed work.
    
    I've made that atomic_long_add_unless call a new helper -
    fput_atomic().  Drops a reference to file if it's safe to
    do in atomic (i.e. if that's not the last one), tells if
    it had been able to do that.  aio.c converted to it, __fput()
    use is gone.  req->ki_file *always* contributes to refcount
    now.  And __fput() became static.
    
    Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
    d7065da0