PATCH added flags to cleaner-wait structure kernel-side

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is once again based on
2ebc3464781ad24474abcbd2274e6254689853b5
(Dan Rosenberg July 19 2010)

The delta between this and the previous ioctl#21 kernel patch I posted is that
this one defines the flags field in the arguments structure, and has a
comment about the intended semantics of it, and tests for the low bit
to the effect that if the flags field is set to 1 the ioctl returns
immediately; also if it is set >1 that is an EINVAL because this
version of the kernel doesn't know that flag, and it is better to
safely full-stop instead of ignoring what might be an important flag.

Or is it a better practice to ignore unexpected fields in such things?
I think the proposed flag semantics as described in the introduction
to the latest revision of the prog-side code might make it okay to
ignore unexpected fields instead of refusing.

The scenario where it matters is, running a newer, future ioctl21
invoker that knows about some future flag, against an old (such as
current, after applying this patch) kernel that doesn't.

Fail or ignore? Or, do I revise it again to have two flags, one to
ignore the one defined completion test, and the other to specify
ignore (0) or fail (1) semantics for unrecognized flag bits? Then I'd
have to add a command line arg for that, possibly
"--no-forward-compat" which would set the
fail-on-unrecognized-flag-bit flag.

My crystal ball might need a little adjustment, I don't know.


---------- Forwarded message ----------
Date: Thu, Oct 14, 2010 at 8:58 AM
Subject: added flags to cleaner-wait structure kernel-side
To: davidnicol@xxxxxxxxx


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



-- 
l'Ãgalità des droits pour les ambidextres
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux