Whamcloud - gitweb
landing b_cmobd_merge on HEAD
[fs/lustre-release.git] / lustre / smfs / smfs_internal.h
index 3142bab..32e84ee 100644 (file)
@@ -1,61 +1,81 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  lustre/smfs/smfs_internal.h
+ *  Lustre filesystem abstraction routines
+ *
+ *  Copyright (C) 2004 Cluster File Systems, Inc.
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
 #ifndef __LINUX_SMFS_H
 #define __LINUX_SMFS_H
 
-struct smfs_inode_info {
-       struct inode *smi_inode;
-};
+//#include <linux/lustre_fsfilt.h>
+#define SMFSDEV_NAME "/dev/smfsconf"
+#define SMFS_PSDEV_MINOR 250
+#define SMFS_PSDEV_MAJOR 10
 
-struct smfs_super_info {
-       struct super_block *smsi_sb;
-        struct vfsmount *smsi_mnt;      /* mount the cache kern with kern_do_mount (like MDS) */
-       __u32 flags;                    /* flags*/
-       struct llog_ctxt *kml_llog;     /*smfs kml llog*/ 
-       int ops_check;
+struct option {
+        char *opt;
+        char *value;
+        struct list_head list;
 };
 
-#define I2SMI(inode)  ((struct smfs_inode_info *) (&(inode->u.generic_ip)))
-#define S2SMI(sb)   ((struct smfs_super_info *) (&(sb->u.generic_sbp)))
-#define S2CSB(sb)   (((struct smfs_super_info *) (&(sb->u.generic_sbp)))->smsi_sb) 
-#define I2CI(inode) (((struct smfs_inode_info*) (&(inode->u.generic_ip)))->smi_inode)
-
-#define SB_OPS_CHECK           0x1
-#define INODE_OPS_CHECK        0x2 
-#define FILE_OPS_CHECK                 0x4 
-#define DENTRY_OPS_CHECK       0x8 
-#define DEV_OPS_CHECK          0x10 
-#define SYMLINK_OPS_CHECK      0x20 
-#define DIR_OPS_CHECK          0x40 
-
-#define SM_DO_KML              0x1
-#include "smfs_support.h"
-
-struct journal_operations {
-        void *(*tr_start)(struct inode *, int op);
-        void (*tr_commit)(void *handle);
+struct smfs_control_device {
+        struct list_head smfs_dev_list;
 };
 
-struct sm_ops {
-        /* operations on the file store */
-        struct super_operations sm_sb_ops;
-                                                                                                                                                                                                     
-        struct inode_operations sm_dir_iops;
-        struct inode_operations sm_file_iops;
-        struct inode_operations sm_sym_iops;
-                                                                                                                                                                                                     
-        struct file_operations sm_dir_fops;
-        struct file_operations sm_file_fops;
-        struct file_operations sm_sym_fops;
-                                                                                                                                                                                                     
-        struct dentry_operations sm_dentry_ops;
-       struct journal_operations sm_journal_ops;
+#define SMFS_TYPE                "smfs"
+#define IOC_SMFS_START           _IOWR('s', 41, long)
+#define IOC_SMFS_STOP            _IOWR('s', 42, long)
+#define IOC_SMFS_REINT           _IOWR('s', 43, long)
+#define IOC_SMFS_UNDO            _IOWR('s', 44, long)
 
-};
-struct option {
-       char *opt;
-       char *value;
-       struct list_head list;
-};
+#ifdef __KERNEL__
+
+#define SB_OPS_CHECK             0x1
+#define INODE_OPS_CHECK          0x2
+#define FILE_OPS_CHECK           0x4
+#define DENTRY_OPS_CHECK         0x8
+#define DEV_OPS_CHECK            0x10
+#define SYMLINK_OPS_CHECK        0x20
+#define DIR_OPS_CHECK            0x40
+
+#define KML_LOG_NAME "kml_rec"
+
+#define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
+
+#define SMFS_KML_POST(dir, dentry, data1, data2, op, name, rc, label)   \
+do {                                                                    \
+        if (smfs_do_rec(dir) && !rc) {                                  \
+                CDEBUG(D_INODE, "Do %s kml post for dir %lu \n",        \
+                              name, dir->i_ino);                        \
+                rc = smfs_post_kml_rec(dir, dentry, data1, data2, op);  \
+                if (rc)                                                 \
+                        GOTO(label, rc);                                \
+        }                                                               \
+} while(0)
+
+#define PACK_KML_REC_INIT(buffer, op_code)          \
+do{                                                 \
+        int opcode = op_code;                       \
+        memcpy(buffer, &opcode, sizeof(opcode));    \
+        buffer += sizeof(opcode);                   \
+} while (0)
 
 extern int init_smfs_proc_sys(void);
 /*options.c*/
@@ -63,59 +83,230 @@ extern int get_opt(struct option **option, char **pos);
 extern void cleanup_option(void);
 extern int init_option(char *data);
 /*cache.c*/
-void sm_set_inode_ops(struct inode *cache_inode, struct inode *inode);
-void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
-void init_smfs_cache(void);
-void cleanup_smfs_cache(void);
-void setup_sm_journal_ops(char * cache_type);
+extern void sm_set_inode_ops(struct inode *cache_inode, struct inode *inode);
+extern void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
+extern void init_smfs_cache(void);
+extern void cleanup_smfs_cache(void);
+extern void sm_set_journal_ops(struct super_block *sb, char *cache_type);
+extern int smfs_init_sm_ops(struct smfs_super_info *smb);
+extern void smfs_cleanup_sm_ops(struct smfs_super_info *smb);
+static inline struct super_operations *cache_sops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_sb_ops;
+}
+static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_dir_iops;
+}
+static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_file_iops;
+}
+static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_sym_iops;
+}
+static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_dir_fops;
+}
+static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_file_fops;
+}
+static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_sym_fops;
+}
+static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_dentry_ops;
+}
+static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
+{
+        return &smb->sm_ops->sm_journal_ops;
+}
 /*super.c*/
 extern int init_smfs(void);
 extern int cleanup_smfs(void);
 extern void smfs_put_super(struct super_block *sb);
-extern void duplicate_sb(struct super_block *csb, struct super_block *sb);
+extern struct super_block *smfs_get_sb_by_path(char *path, int len);
+extern struct vfsmount* get_vfsmount(struct super_block *sb);
 /*sysctl.c*/
 extern int sm_debug_level;
 extern int sm_inodes;
 extern long sm_kmemory;
 extern int sm_stack;
 /*dir.c*/
-extern struct inode_operations smfs_dir_iops; 
-extern struct file_operations smfs_dir_fops; 
-
-extern void d_unalloc(struct dentry *dentry);
-/*inode.c*/
-extern void duplicate_inode(struct inode *cache_inode, struct inode *inode);
+extern struct inode_operations smfs_dir_iops;
+extern struct file_operations smfs_dir_fops;
 /*file.c*/
-extern void smfs_prepare_cachefile(struct inode *inode,
-                                  struct file *file, 
-                                  struct inode *cache_inode,
-                                  struct file *cache_file,
-                                  struct dentry *cache_dentry);
-extern int smfs_ioctl(struct inode * inode, struct file * filp,  unsigned int cmd,
-                      unsigned long arg);
+extern struct inode_operations smfs_file_iops;
+extern struct file_operations  smfs_file_fops;
+extern int smfs_ioctl(struct inode * inode, struct file * filp,
+                      unsigned int cmd, unsigned long arg);
 extern int smfs_fsync(struct file * file, struct dentry *dentry, int datasync);
-extern int smfs_setattr(struct dentry *dentry, struct iattr *attr); 
+extern int smfs_setattr(struct dentry *dentry, struct iattr *attr);
 extern int smfs_setxattr(struct dentry *dentry, const char *name,
-                        const void *value, size_t size, int flags);
-extern int smfs_getxattr(struct dentry *dentry, const char *name,
-                        void *buffer, size_t size);
+                         const void *value, size_t size, int flags);
+extern int smfs_getxattr(struct dentry *dentry, const char *name, void *buffer,
+                         size_t size);
 extern ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
 extern int smfs_removexattr(struct dentry *dentry, const char *name);
-extern void smfs_update_file(struct file *file, struct file *cache_file);
+extern int smfs_open(struct inode * inode, struct file * filp);
+extern int smfs_release(struct inode * inode, struct file * filp);
+/*inode.c*/
+extern struct super_operations smfs_super_ops;
+/*symlink.c*/
+extern struct inode_operations smfs_sym_iops;
+extern struct file_operations smfs_sym_fops;
 /*journal.c */
-extern void *smfs_trans_start(struct inode *inode, int op);
-extern void smfs_trans_commit(void *handle);
-extern int smfs_journal_mkdir(struct dentry *dentry,
-                       struct smfs_version *tgt_dir_ver,
-                       struct smfs_version *new_dir_ver, 
-                      int mode);
-/*journal_ext3.c*/
-extern struct journal_operations smfs_ext3_journal_ops;
+extern void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
+extern void smfs_trans_commit(struct inode *inode, void *handle,
+                              int force_sync);
+extern int  smfs_post_kml_rec(struct inode *dir, struct dentry *dst_dentry,
+                              void   *data1, void *data2, int op);
+
+extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
+                               void   *data1, void *data2);
+extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
+                                 void   *data1, void *data2);
 /*kml.c*/
 extern int smfs_kml_init(struct super_block *sb);
-extern int smfs_do_kml(struct inode *dir);
-extern void smfs_getversion(struct smfs_version * smfs_version, struct inode * inode); 
-extern int post_kml_mkdir(struct inode *dir, struct dentry *dentry);
+extern int smfs_do_rec(struct inode *inode);
+extern int smfs_rec_cleanup(struct super_block *sb);
+extern int smfs_rec_init(struct super_block *sb);
+extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
+                           char **pbuf, int *opcode);
+extern int smfs_process_rec(struct super_block *sb, int count,
+                            char *dir, int flags);
+extern void smfs_rec_pack(struct update_record *rec,
+                          struct inode *dst, void* data, int op);
+
+extern smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb);
+
+extern int ost_rec_pack_init(struct super_block *sb);
+/*ost_kml.c*/
+extern int mds_rec_pack_init(struct super_block *sb);
+
 /*smfs_llog.c*/
-extern int smfs_llog_setup(struct llog_ctxt **ctxt);
+extern int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt);
+extern int smfs_llog_cleanup(struct super_block *sb);
+extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
+                             int data_size);
+/*ioctl.c*/
+extern int init_smfs_psdev(void);
+extern void smfs_cleanup_psdev(void);
+
+/* cache_space.c */
+extern int do_cache_manage;
+struct cache_purge_queue {
+        wait_queue_head_t       cpq_waitq;
+        struct super_block     *cpq_sb;
+        struct llog_handle     *cpq_loghandle;
+        __u32                   cpq_flags;
+        struct completion       cpq_comp;
+};
+/* opcodes */
+#define CACHE_SPACE_INSERT 0x1
+#define CACHE_SPACE_DELETE 0x2
+#define CACHE_SPACE_COMMIT 0x4
+
+#define CACHE_LRU_LOG "CACHE_LRU_LIST"
+
+extern int smfs_cache_hook(struct inode *inode);
+extern void cache_space_pre(struct inode *inode, int op);
+extern int cache_space_post(int op, void *handle, struct inode *old_dir,
+                            struct dentry *old_dentry, struct inode *new_dir,
+                            struct dentry *new_dentry);
+
+extern int cache_space_hook_setup(struct super_block *);
+extern int cache_space_hook_cleanup(void);
+extern int cache_space_hook_init(struct super_block *);
+extern int cache_space_hook_exit(struct super_block *);
+
+#define XATTR_SMFS_HOARD_MARK           "hoard"
+#define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
+#define XATTR_SMFS_ACTIVE_ENTRY         "entry"
+
+
+static inline int set_hoard_priority(struct inode *inode, void *handle,
+                                     __u32 *hoard)
+{
+        struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
+        int rc;
+
+        rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
+                                 hoard, sizeof(__u32));
+        RETURN(rc);
+}
+
+static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
+{
+        struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
+        int rc;
+
+        rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
+                                 hoard, sizeof(__u32));
+        RETURN(rc);
+}
+
+static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
+                                   void *handle)
+{
+        struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
+        int rc;
+        *active_entry = cpu_to_le64(*active_entry);
+        rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
+                                 active_entry, sizeof(__u64));
+        RETURN(rc);
+}
+static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
+{
+        struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
+        int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
+                                     active_entry, sizeof(__u64));
+        *active_entry = le64_to_cpu(*active_entry);
+        if (rc >= 0)
+                rc = 0;
+        RETURN(rc);
+}
+
+#define CACHE_HOOK_CREATE       1
+#define CACHE_HOOK_LOOKUP       2
+#define CACHE_HOOK_LINK         3
+#define CACHE_HOOK_UNLINK       4
+#define CACHE_HOOK_SYMLINK      5
+#define CACHE_HOOK_MKDIR        6
+#define CACHE_HOOK_RMDIR        7
+#define CACHE_HOOK_MKNOD        8
+#define CACHE_HOOK_RENAME       9
+
+#define CACHE_HOOK_MAX          9
+
+#define SMFS_CACHE_HOOK_PRE(op, handle, dir)                            \
+{                                                                       \
+        if (smfs_cache_hook(dir)) {                                     \
+                LASSERT(handle != NULL);                                \
+                CDEBUG(D_INODE, "cache hook pre: op %d, dir %lu\n",     \
+                       op, dir->i_ino);                                 \
+                cache_space_pre(dir, op);                               \
+        }                                                               \
+}
+
+#define SMFS_CACHE_HOOK_POST(op, handle, old_dir, old_dentry,           \
+                             new_dir, new_dentry, rc, label)            \
+{                                                                       \
+        if (!rc && smfs_cache_hook(old_dir)) {                          \
+                LASSERT(handle != NULL);                                \
+                CDEBUG(D_INODE, "cache hook post: op %d, dir %lu\n",    \
+                       op, old_dir->i_ino);                             \
+                rc = cache_space_post(op, handle, old_dir, old_dentry,  \
+                                         new_dir, new_dentry);          \
+                if (rc)                                                 \
+                        GOTO(label, rc);                                \
+        }                                                               \
+}
+
+#endif /*__KERNEL*/
 #endif /* __LINUX_SMFS_H */