From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Paul Moore <paul@paul-moore.com>,
Miklos Szeredi <miklos@szeredi.hu>
Subject: Re: [PATCH 09/22] fsnotify: Detach mark from object list when last reference is dropped
Date: Tue, 10 Jan 2017 14:47:39 +0100 [thread overview]
Message-ID: <20170110134739.GP4991@quack2.suse.cz> (raw)
In-Reply-To: <CAOQ4uxj5dbLXx333j0X3hviFrFSM8S-WWYonzQj8zHRgFwfKvw@mail.gmail.com>
On Sun 08-01-17 14:10:42, Amir Goldstein wrote:
> > +void fsnotify_put_mark(struct fsnotify_mark *mark)
> > +{
> > + /* Catch marks that were actually never attached to object */
> > + if (!mark->connector && atomic_dec_and_test(&mark->refcnt)) {
> > + fsnotify_final_mark_destroy(mark);
> > + return;
> > + }
> > +
> > + /*
> > + * We have to be careful so that traversals of obj_list under lock can
> > + * safely grab mark reference.
> > + */
> > + if (atomic_dec_and_lock(&mark->refcnt, &mark->connector->lock)) {
>
> Style nit: maybe if (!atomic_dec_and_lock(...)) return; ?
OK, done.
> > /*
> > - * Remove mark from inode / vfsmount list, group list, drop inode reference
> > - * if we got one.
> > + * Mark mark as dead, remove it from group list. Mark still stays in object
>
> Nit: marking mark as "dead" would imply
> mark->flags &= ~FSNOTIFY_MARK_FLAG_ALIVE
> which does not happen here. need to be careful with wording...
>
> You probably meant to write "Mark mark as detached...".
Yeah, good catch. Thanks.
> > @@ -613,23 +637,39 @@ void fsnotify_detach_group_marks(struct fsnotify_group *group)
> > void fsnotify_destroy_marks(struct fsnotify_mark_connector **connp)
> > {
> > struct fsnotify_mark_connector *conn;
> > - struct fsnotify_mark *mark;
> > + struct fsnotify_mark *mark, *old_mark = NULL;
> > + struct inode *inode;
> >
> > - while ((conn = fsnotify_grab_connector(connp))) {
> > - /*
> > - * We have to be careful since we can race with e.g.
> > - * fsnotify_clear_marks_by_group() and once we drop the list
> > - * lock, mark can get removed from the obj_list and destroyed.
> > - * But we are holding mark reference so mark cannot be freed
> > - * and calling fsnotify_destroy_mark() more than once is fine.
> > - */
> > - mark = hlist_entry(conn->list.first, struct fsnotify_mark,
> > - obj_list);
> > + conn = fsnotify_grab_connector(connp);
> > + if (!conn)
> > + return;
> > + /*
> > + * We have to be careful since we can race with e.g.
> > + * fsnotify_clear_marks_by_group() and once we drop the conn->lock, the
> > + * list can get modified. However we are holding mark reference and
> > + * thus our mark cannot be removed from obj_list so we can continue
> > + * iteration after regaining conn->lock.
> > + */
> > + hlist_for_each_entry(mark, &conn->list, obj_list) {
> > fsnotify_get_mark(mark);
> > - fsnotify_put_connector(conn);
> > + spin_unlock(&conn->lock);
> > + if (old_mark)
> > + fsnotify_put_mark(old_mark);
> > + old_mark = mark;
> > fsnotify_destroy_mark(mark, mark->group);
> > - fsnotify_put_mark(mark);
> > + spin_lock(&conn->lock);
> > }
> > + /*
> > + * Detach list from object now so that we don't pin inode until all
> > + * mark references get dropped. It would lead to strange results such
> > + * as delaying inode deletion or blocking unmount.
> > + */
> > + inode = fsnotify_detach_connector_from_object(conn);
> > + fsnotify_put_connector(conn);
>
> In this code, it is extra dissonant that spin_unlock(&conn->lock);
> is obfuscated by fsnotify_put_connector(conn);
> since you (rightfully) used spin_unlock() inside the for loop.
> As I suggested in earlier patch - get rid of fsnotify_put_connector()
> helper is the easy road.
Done.
> > + if (inode)
> > + iput(inode);
> > + if (old_mark)
> > + fsnotify_put_mark(old_mark);
>
> It is not clear to me from the comment above if the order of
> iput(inode) and fsnotify_put_mark(old_mark) is meaningful
> or arbitrary, because af far as I understand "until all mark
> references get dropped" does not refer to "old_mark".
>
> If the order is arbitrary, to me it would have looked better
> to see the snippet missing from within the for loop here:
>
> spin_unlock(&conn->lock);
> if (old_mark)
> fsnotify_put_mark(old_mark);
>
> And iput(inode) as the final chord of this function.
>
> But if order is not arbitrary, please elaborate in comment.
The order is arbitrary. Frankly, I can see reasons for any ordering - my
original thinking was to have iput() closer to where we get inode pointer.
But whatever. Reordered.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2017-01-10 13:47 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-06 10:43 [PATCH 0/22 v2] fsnotify: Avoid SRCU stalls with fanotify permission events Jan Kara
2017-01-06 10:43 ` [PATCH 01/22] fsnotify: Remove unnecessary tests when showing fdinfo Jan Kara
2017-01-06 10:43 ` [PATCH 02/22] inotify: Remove inode pointers from debug messages Jan Kara
2017-01-06 10:43 ` [PATCH 03/22] fanotify: Move recalculation of inode / vfsmount mask under mark_mutex Jan Kara
2017-01-06 10:43 ` [PATCH 04/22] audit: Abstract hash key handling Jan Kara
2017-01-06 10:43 ` [PATCH 05/22] fsnotify: Update comments Jan Kara
2017-01-06 10:43 ` [PATCH 06/22] fsnotify: Attach marks to object via dedicated head structure Jan Kara
2017-01-06 13:12 ` Amir Goldstein
2017-01-08 10:18 ` Amir Goldstein
2017-01-10 13:30 ` Jan Kara
2017-01-06 10:43 ` [PATCH 07/22] inotify: Do not drop mark reference under idr_lock Jan Kara
2017-01-06 10:43 ` [PATCH 08/22] fsnotify: Move queueing of mark for destruction into fsnotify_put_mark() Jan Kara
2017-01-08 11:15 ` Amir Goldstein
2017-01-06 10:43 ` [PATCH 09/22] fsnotify: Detach mark from object list when last reference is dropped Jan Kara
2017-01-08 12:10 ` Amir Goldstein
2017-01-10 13:47 ` Jan Kara [this message]
2017-01-06 10:43 ` [PATCH 10/22] fsnotify: Remove special handling of mark destruction on group shutdown Jan Kara
2017-01-06 10:43 ` [PATCH 11/22] fsnotify: Provide framework for dropping SRCU lock in ->handle_event Jan Kara
2017-01-08 9:02 ` Amir Goldstein
2017-01-10 13:00 ` Jan Kara
2017-01-06 10:43 ` [PATCH 12/22] fsnotify: Pass SRCU index into handle_event handler Jan Kara
2017-01-06 10:43 ` [PATCH 13/22] fanotify: Release SRCU lock when waiting for userspace response Jan Kara
2017-01-06 10:43 ` [PATCH 14/22] fsnotify: Remove fsnotify_set_mark_{,ignored_}mask_locked() Jan Kara
2017-01-06 10:43 ` [PATCH 15/22] fsnotify: Remove fsnotify_recalc_{inode|vfsmount}_mask() Jan Kara
2017-01-06 10:43 ` [PATCH 16/22] fsnotify: Inline fsnotify_clear_{inode|vfsmount}_mark_group() Jan Kara
2017-01-06 10:43 ` [PATCH 17/22] fsnotify: Rename fsnotify_clear_marks_by_group_flags() Jan Kara
2017-01-08 12:17 ` Amir Goldstein
2017-01-06 10:43 ` [PATCH 18/22] fsnotify: Remove fsnotify_detach_group_marks() Jan Kara
2017-01-08 12:26 ` Amir Goldstein
2017-01-06 10:43 ` [PATCH 19/22] fsnotify: Remove fsnotify_find_{inode|vfsmount}_mark() Jan Kara
2017-01-06 10:43 ` [PATCH 20/22] fsnotify: Drop inode_mark.c Jan Kara
2017-01-06 10:44 ` [PATCH 21/22] fsnotify: Add group pointer in fsnotify_init_mark() Jan Kara
2017-01-08 12:35 ` Amir Goldstein
2017-01-10 13:48 ` Jan Kara
2017-01-06 10:44 ` [PATCH 22/22] fsnotify: Move ->free_mark callback to fsnotify_ops Jan Kara
2017-01-08 12:50 ` [PATCH 0/22 v2] fsnotify: Avoid SRCU stalls with fanotify permission events Amir Goldstein
-- strict thread matches above, loose matches on Subject: below --
2017-01-20 13:21 [PATCH 0/22 v3] " Jan Kara
2017-01-20 13:21 ` [PATCH 09/22] fsnotify: Detach mark from object list when last reference is dropped Jan Kara
2017-01-21 15:50 ` Amir Goldstein
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170110134739.GP4991@quack2.suse.cz \
--to=jack@suse.cz \
--cc=amir73il@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=paul@paul-moore.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.