From 02af35a98e187020b204c671d53895300fae0855 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Fri, 10 Feb 2017 09:26:55 -0800 Subject: [PATCH] Convert inode since ioctl to the item API The inode since ioctl was the last user of the btree. It doesn't yet work because the item cache doesn't know how to search for items by sequence yet. It's not yet clear exactly how we'll build the data since ioctls. It'll be easy enough to refactor the inode since item walk if they follow a similar pattern again. Signed-off-by: Zach Brown --- kmod/src/inode.c | 16 ++++++++-------- kmod/src/inode.h | 5 +++++ kmod/src/ioctl.c | 27 +++++++++++++++------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/kmod/src/inode.c b/kmod/src/inode.c index b773f0ee..ad1caa79 100644 --- a/kmod/src/inode.c +++ b/kmod/src/inode.c @@ -132,8 +132,8 @@ static void load_inode(struct inode *inode, struct scoutfs_inode *cinode) ci->next_readdir_pos = le64_to_cpu(cinode->next_readdir_pos); } -static void init_inode_key(struct scoutfs_key_buf *key, - struct scoutfs_inode_key *ikey, u64 ino) +void scoutfs_inode_init_key(struct scoutfs_key_buf *key, + struct scoutfs_inode_key *ikey, u64 ino) { ikey->type = SCOUTFS_INODE_KEY; ikey->ino = cpu_to_be64(ino); @@ -150,7 +150,7 @@ static int scoutfs_read_locked_inode(struct inode *inode) SCOUTFS_DECLARE_KVEC(val); int ret; - init_inode_key(&key, &ikey, scoutfs_ino(inode)); + scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); ret = scoutfs_item_lookup_exact(sb, &key, val, sizeof(sinode)); @@ -283,7 +283,7 @@ int scoutfs_dirty_inode_item(struct inode *inode) store_inode(&sinode, inode); - init_inode_key(&key, &ikey, scoutfs_ino(inode)); + scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); ret = scoutfs_item_dirty(sb, &key); if (!ret) @@ -311,7 +311,7 @@ void scoutfs_update_inode_item(struct inode *inode) store_inode(&sinode, inode); - init_inode_key(&key, &ikey, scoutfs_ino(inode)); + scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); err = scoutfs_item_update(sb, &key, val); @@ -426,7 +426,7 @@ struct inode *scoutfs_new_inode(struct super_block *sb, struct inode *dir, set_inode_ops(inode); store_inode(&sinode, inode); - init_inode_key(&key, &ikey, scoutfs_ino(inode)); + scoutfs_inode_init_key(&key, &ikey, scoutfs_ino(inode)); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); ret = scoutfs_item_create(sb, &key, val); @@ -512,7 +512,7 @@ static void delete_inode(struct super_block *sb, u64 ino) int ret; /* sample the inode mode, XXX don't need to copy whole thing here */ - init_inode_key(&key, &ikey, ino); + scoutfs_inode_init_key(&key, &ikey, ino); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); ret = scoutfs_item_lookup_exact(sb, &key, val, sizeof(sinode)); @@ -566,7 +566,7 @@ static int process_orphaned_inode(struct super_block *sb, u64 ino) SCOUTFS_DECLARE_KVEC(val); int ret; - init_inode_key(&key, &ikey, ino); + scoutfs_inode_init_key(&key, &ikey, ino); scoutfs_kvec_init(val, &sinode, sizeof(sinode)); ret = scoutfs_item_lookup_exact(sb, &key, val, sizeof(sinode)); diff --git a/kmod/src/inode.h b/kmod/src/inode.h index 93f6d276..f3badfb4 100644 --- a/kmod/src/inode.h +++ b/kmod/src/inode.h @@ -1,6 +1,8 @@ #ifndef _SCOUTFS_INODE_H_ #define _SCOUTFS_INODE_H_ +#include "key.h" + struct scoutfs_inode_info { u64 ino; u32 salt; @@ -28,6 +30,9 @@ static inline u64 scoutfs_ino(struct inode *inode) return SCOUTFS_I(inode)->ino; } +void scoutfs_inode_init_key(struct scoutfs_key_buf *key, + struct scoutfs_inode_key *ikey, u64 ino); + struct inode *scoutfs_alloc_inode(struct super_block *sb); void scoutfs_destroy_inode(struct inode *inode); int scoutfs_drop_inode(struct inode *inode); diff --git a/kmod/src/ioctl.c b/kmod/src/ioctl.c index 843d82ec..255e167f 100644 --- a/kmod/src/ioctl.c +++ b/kmod/src/ioctl.c @@ -22,7 +22,6 @@ #include #include "format.h" -#include "btree.h" #include "key.h" #include "dir.h" #include "name.h" @@ -51,15 +50,16 @@ static long scoutfs_ioc_inodes_since(struct file *file, unsigned long arg, u8 type) { struct super_block *sb = file_inode(file)->i_sb; - struct scoutfs_btree_root *meta = SCOUTFS_STABLE_META(sb); struct scoutfs_ioctl_inodes_since __user *uargs = (void __user *)arg; struct scoutfs_ioctl_inodes_since args; struct scoutfs_ioctl_ino_seq __user *uiseq; struct scoutfs_ioctl_ino_seq iseq; - struct scoutfs_key key; - struct scoutfs_key last; - u64 seq; + struct scoutfs_inode_key last_ikey; + struct scoutfs_inode_key ikey; + struct scoutfs_key_buf last; + struct scoutfs_key_buf key; long bytes; + u64 seq; int ret; if (copy_from_user(&args, uargs, sizeof(args))) @@ -69,20 +69,23 @@ static long scoutfs_ioc_inodes_since(struct file *file, unsigned long arg, if (args.buf_len < sizeof(iseq) || args.buf_len > INT_MAX) return -EINVAL; - scoutfs_set_key(&key, args.first_ino, type, 0); - scoutfs_set_key(&last, args.last_ino, type, 0); + scoutfs_inode_init_key(&key, &ikey, args.first_ino); + scoutfs_inode_init_key(&last, &last_ikey, args.last_ino); bytes = 0; for (;;) { - ret = scoutfs_btree_since(sb, meta, &key, &last, args.seq, - &key, &seq, NULL); + + /* XXX item cache needs to search by seq */ + seq = !!sb; + ret = WARN_ON_ONCE(-EINVAL); +// ret = scoutfs_item_since(sb, &key, &last, args.seq, &seq, NULL); if (ret < 0) { if (ret == -ENOENT) ret = 0; break; } - iseq.ino = scoutfs_key_inode(&key); + iseq.ino = be64_to_cpu(ikey.ino); iseq.seq = seq; if (copy_to_user(uiseq, &iseq, sizeof(iseq))) { @@ -97,7 +100,7 @@ static long scoutfs_ioc_inodes_since(struct file *file, unsigned long arg, break; } - key.inode = cpu_to_le64(iseq.ino + 1); + last_ikey.ino = cpu_to_be64(iseq.ino + 1); } if (bytes) @@ -418,7 +421,7 @@ long scoutfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case SCOUTFS_IOC_INO_PATH: return scoutfs_ioc_ino_path(file, arg); case SCOUTFS_IOC_INODE_DATA_SINCE: - return scoutfs_ioc_inodes_since(file, arg, SCOUTFS_EXTENT_KEY); + return WARN_ON_ONCE(-EINVAL); case SCOUTFS_IOC_DATA_VERSION: return scoutfs_ioc_data_version(file, arg); case SCOUTFS_IOC_RELEASE: