Re: [PATCH v2 7/8] smb: client: allow nolease option to be reconfigured on remount
Namjae Jeon <[email protected]>
| Newsgroups | org.kernel.vger.linux-cifs |
|---|---|
| Message-ID | <CAKYAXd-qNcPcg=NUEUz_DUfL4QCv14PHgG-=aCXsBWYg3vOp3Q@mail.gmail.com> |
> +/*
> + * Invalidate cached directory entries across all tcons under a
> + * superblock. Count the tcons first so the pointer array can be
> + * allocated with GFP_KERNEL outside tlink_tree_lock: allocating
> + * per-tcon under the spinlock would force GFP_ATOMIC and, on failure,
> + * silently leave some tcons with stale leases after a nolease remount.
> + * References are then taken under tlink_tree_lock and the cached dirs
> + * closed outside the spinlock since that can sleep. Holding a tc_count
> + * reference prevents the tcon from being freed by tlink_expire_delayed()
> + * between dropping the spinlock and the call.
> + *
> + * Called on remount while the connection is live (e.g. switching to
> + * nolease), so pass close_handles=true to actually release the
> + * server-side directory handles and their leases.
> + */
> +void invalidate_all_cached_dirs_sb(struct cifs_sb_info *cifs_sb)
> +{
> + struct rb_root *root = &cifs_sb->tlink_tree;
> + struct rb_node *node;
> + struct cifs_tcon *tcon;
> + struct tcon_link *tlink;
> + struct cifs_tcon **tcons;
> + unsigned int i, n = 0, count = 0;
> +
> + spin_lock(&cifs_sb->tlink_tree_lock);
> + for (node = rb_first(root); node; node = rb_next(node)) {
> + tlink = rb_entry(node, struct tcon_link, tl_rbnode);
> + if (!IS_ERR(tlink_tcon(tlink)))
> + count++;
> + }
> + spin_unlock(&cifs_sb->tlink_tree_lock);
> +
> + if (!count)
> + return;
> +
> + /*
> + * Best effort: if the snapshot array can't be allocated, skip the
> + * eviction. New opens still honor the updated nolease via the
> + * tcon->no_lease propagation done by the caller.
> + */
> + tcons = kcalloc(count, sizeof(*tcons), GFP_KERNEL);
> + if (!tcons)
> + return;
If this allocation fails, the function silently skips evicting cached
directory FIDs while the remount still succeeds. Such a FID may then
be reused after nolease is enabled. So please do not silently return
here.