On (21/03/22 08:34), Matthew Wilcox wrote:
> > +++ b/fs/cifsd/mgmt/ksmbd_ida.c
> > @@ -0,0 +1,69 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +/*
> > + *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
> > + */
> > +
> > +#include "ksmbd_ida.h"
> > +
> > +struct ksmbd_ida *ksmbd_ida_alloc(void)
> > +{
> > +   struct ksmbd_ida *ida;
> > +
> > +   ida = kmalloc(sizeof(struct ksmbd_ida), GFP_KERNEL);
> > +   if (!ida)
> > +           return NULL;
> > +
> > +   ida_init(&ida->map);
> > +   return ida;
> > +}
>
> ... why?  Everywhere that you call ksmbd_ida_alloc(), you would
> be better off just embedding the struct ida into the struct that
> currently has a pointer to it.  Or declaring it statically.  Then
> you can even initialise it statically using DEFINE_IDA() and
> eliminate the initialiser functions.

IIRC this ida is per SMB session, so it probably cannot be static.
And Windows, IIRC, doesn't like "just any IDs". Some versions of Windows
would fail the session login if server would return the first id == 0,
instead of 1. Or vice versa. I don't remember all the details, the last
time I looked into this was in 2019.

[..]
> > +struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session 
> > *sess,
> > +                                             unsigned int id)
> > +{
> > +   struct ksmbd_tree_connect *tree_conn;
> > +   struct list_head *tmp;
> > +
> > +   list_for_each(tmp, &sess->tree_conn_list) {
> > +           tree_conn = list_entry(tmp, struct ksmbd_tree_connect, list);
> > +           if (tree_conn->id == id)
> > +                   return tree_conn;
> > +   }
>
> ... walk the linked list looking for an ID match.  You'd be much better
> off using an allocating XArray:
> https://www.kernel.org/doc/html/latest/core-api/xarray.html

I think cifsd code predates XArray ;)

> Then you could lookup tree connections in O(log(n)) time instead of
> O(n) time.

Agreed. Not sure I remember why the code does list traversal here.

Reply via email to