lkml.org 
[lkml]   [2009]   [May]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 04/24] sysfs: Normalize removing sysfs directories.
Hello,

Eric W. Biederman wrote:
> @@ -732,12 +732,28 @@ const struct inode_operations sysfs_dir_inode_operations = {
> .setattr = sysfs_setattr,
> };
>
> -static void remove_dir(struct sysfs_dirent *sd)
> +static void remove_dir(struct sysfs_dirent *dir_sd)
> {
> struct sysfs_addrm_cxt acxt;
>
> - sysfs_addrm_start(&acxt, sd->s_parent);
> - sysfs_remove_one(&acxt, sd);
> + pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
> +
> + /* Removing non-empty directories is not valid complain! */
^^^
missing . or ,

> +static struct sysfs_dirent *get_dirent_to_remove(struct sysfs_dirent *dir_sd)
> +{
> + struct sysfs_dirent *sd;
> +
> + mutex_lock(&sysfs_mutex);
> + for (sd = dir_sd->s_dir.children; sd; sd = sd->s_sibling) {
> + /* Directories might be owned by someone else
> + * making recursive directory removal unsafe.
> + */
> + if (sysfs_type(sd) == SYSFS_DIR)
> + continue;
> + break;
> + }
> + sysfs_get(sd);
> + mutex_unlock(&sysfs_mutex);
> +
> + return sd;
> +}
>
> static void __sysfs_remove_dir(struct sysfs_dirent *dir_sd)
> {
> struct sysfs_addrm_cxt acxt;
> - struct sysfs_dirent **pos;
> -
> - if (!dir_sd)
> - return;
> -
> - pr_debug("sysfs %s: removing dir\n", dir_sd->s_name);
> - sysfs_addrm_start(&acxt, dir_sd);
> - pos = &dir_sd->s_dir.children;
> - while (*pos) {
> - struct sysfs_dirent *sd = *pos;
> + struct sysfs_dirent *sd;
>
> - if (sysfs_type(sd) != SYSFS_DIR)
> - sysfs_remove_one(&acxt, sd);
> - else
> - pos = &(*pos)->s_sibling;
> + /* Remove children that we think are safe */
> + while ((sd = get_dirent_to_remove(dir_sd))) {
> + sysfs_addrm_start(&acxt, sd->s_parent);
> + sysfs_remove_one(&acxt, sd);
> + sysfs_addrm_finish(&acxt);
> + sysfs_put(sd);
> }
> - sysfs_addrm_finish(&acxt);

Ummm... Null @dir_sd handling is being removed, which could be fine
but please do it in a separate patch or at least mention it in the
patch description. Also, I'm quite uncomfortable with these things
being done in non-atomic manner. It can be made to work but things
like this can lead to subtle race conditions and with the kind of
layering we put on top of sysfs (kobject, driver model, driver
midlayers and so on), it isn't all that easy to verify what's going
on, so NACK for this one.

Thanks.

--
tejun


\
 
 \ /
  Last update: 2009-05-29 11:17    [W:0.232 / U:1.912 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site