From patchwork Thu Oct 14 16:17:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Nicol X-Patchwork-Id: 253381 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9EGHTvJ026248 for ; Thu, 14 Oct 2010 16:17:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755441Ab0JNQR0 (ORCPT ); Thu, 14 Oct 2010 12:17:26 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:44345 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752341Ab0JNQR0 convert rfc822-to-8bit (ORCPT ); Thu, 14 Oct 2010 12:17:26 -0400 Received: by iwn35 with SMTP id 35so148986iwn.19 for ; Thu, 14 Oct 2010 09:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=JBjIJm7CwNfOuYxbg5OAPLGotBZ5028x0xBykSELlco=; b=VcS0Nka+n8aR09+kdLYlrm9wrLEPLxhgPZYgE0rPwf1wfWXVH8ap107r3vjM3aIYHn kZk3DvT7iYbhVw/qgVN89MIOD9cdMaKOJrqQSAvw9DDJP/bZ4lYw4a7m7yfDWJn2c6RS EJ1T8iG+SflA2DEV8VAeZEacw5x60wzJzi7tI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; b=Lo8GwTgLP0iYu+par+dedTk8dzc1OtH7T66He7PC1gm71Dxbqk0YPhJxRBRyFo0bUf H3vs7TgxKUE39nD/d7V9OF5dKQrLXlV5Etmkw+HO9DyHKohdbdt3Vm+Jje9M44gk7dG0 wYeXh1f/6unerj0jExhEkab4zvq8Cdm2WvAzQ= Received: by 10.231.34.139 with SMTP id l11mr8588941ibd.141.1287073045620; Thu, 14 Oct 2010 09:17:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.152.1 with HTTP; Thu, 14 Oct 2010 09:17:04 -0700 (PDT) From: David Nicol Date: Thu, 14 Oct 2010 11:17:04 -0500 Message-ID: Subject: PATCH zeroing ioctl21 flags progs-side To: BTRFS MAILING LIST Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 14 Oct 2010 16:17:30 +0000 (UTC) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index e9bf864..a350b75 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -895,6 +895,7 @@ struct btrfs_fs_info {        struct list_head trans_list;        struct list_head hashers;        struct list_head dead_roots; +       wait_queue_head_t cleaner_notification_registration;        struct list_head caching_block_groups;        spinlock_t delayed_iput_lock; diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 34f7c37..6a35257 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1451,6 +1451,7 @@ static int cleaner_kthread(void *arg)                    mutex_trylock(&root->fs_info->cleaner_mutex)) {                        btrfs_run_delayed_iputs(root);                        btrfs_clean_old_snapshots(root); + wake_up_all(&root->fs_info->cleaner_notification_registration);                        mutex_unlock(&root->fs_info->cleaner_mutex);                } @@ -1581,6 +1582,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,        INIT_RADIX_TREE(&fs_info->fs_roots_radix, GFP_ATOMIC);        INIT_LIST_HEAD(&fs_info->trans_list);        INIT_LIST_HEAD(&fs_info->dead_roots); +       init_waitqueue_head(&fs_info->cleaner_notification_registration);        INIT_LIST_HEAD(&fs_info->delayed_iputs);        INIT_LIST_HEAD(&fs_info->hashers);        INIT_LIST_HEAD(&fs_info->delalloc_inodes); diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9254b3d..ffc86a8 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1212,6 +1212,65 @@ static noinline int btrfs_ioctl_ino_lookup(struct file *file,        return ret;  } +static int btrfs_ioctl_cleaner_wait(struct btrfs_root *root, void __user *arg) +{ +        struct btrfs_ioctl_cleaner_wait_args *bicwa; +        long remainingjiffies; +        int err; + +       bicwa = memdup_user(arg, sizeof(*bicwa)); +       if (IS_ERR(bicwa)) +               return PTR_ERR(bicwa); + +        /* the bicwa flags field is intended to hold bits +           that will be set to 1 to disable a cleanliness +           test.  Currently there is only one test, but +           when there are more (or other things, like +           reprioritizing the cleaner thread because something +           is waiting on it, although that happens already +           because the waiting thing has yielded, so that +           isn't really a hot to-do item) this function +           will of course get modified to implement them. */ + +        if (bicwa->flags > 0x01) /* the highest flag we know about */ +        { +             err = -EINVAL; +             goto done_with_bicwa; +        } + +        if (bicwa->ms > 0) +       { +            remainingjiffies = wait_event_interruptible_timeout( +                 root->fs_info->cleaner_notification_registration, +                 /* && together multiple FLAG OR TEST sequences +                    when there are more than one */ +                 ( bicwa->flags & 0x01 ? 1 : +                   list_empty(&root->fs_info->dead_roots) +                 ), +                 msecs_to_jiffies(bicwa->ms) +            ); +            if (remainingjiffies > 0) +                  err = 0; +            else if (remainingjiffies < 0 ) +                  err = -EAGAIN; +            else +                  err = -ETIME; +        } +       else +       { +            err = wait_event_interruptible( +                 root->fs_info->cleaner_notification_registration, +                 list_empty(&root->fs_info->dead_roots) +            ); +        }; + +        done_with_bicwa: +       kfree(bicwa); +        return err; + +} + +  static noinline int btrfs_ioctl_snap_destroy(struct file *file,                                             void __user *arg)  { @@ -2003,6 +2062,8 @@ long btrfs_ioctl(struct file *file, unsigned int                return btrfs_ioctl_snap_create(file, argp, 1);        case BTRFS_IOC_SNAP_DESTROY:                return btrfs_ioctl_snap_destroy(file, argp); +       case BTRFS_IOC_CLEANER_WAIT: +               return btrfs_ioctl_cleaner_wait(root, argp);        case BTRFS_IOC_DEFAULT_SUBVOL:                return btrfs_ioctl_default_subvol(file, argp);        case BTRFS_IOC_DEFRAG: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index 424694a..18ff143 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -138,6 +138,11 @@ struct btrfs_ioctl_space_args {        struct btrfs_ioctl_space_info spaces[0];  }; +struct btrfs_ioctl_cleaner_wait_args{ +        unsigned long ms; +        unsigned long flags; +}; +  #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \                                   struct btrfs_ioctl_vol_args)  #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ @@ -178,4 +183,6 @@ struct btrfs_ioctl_space_args {  #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)  #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \                                    struct btrfs_ioctl_space_args) +#define BTRFS_IOC_CLEANER_WAIT _IOW(BTRFS_IOCTL_MAGIC, 21, \ +                                   struct btrfs_ioctl_cleaner_wait_args)  #endif