Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / include / linux / lustre_fsfilt.h
index 40e9914..a091f45 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (C) 2001 Cluster File Systems, Inc. <info@clusterfs.com>
+ *  Copyright (C) 2001-2004 Cluster File Systems, Inc. <info@clusterfs.com>
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
  *
  */
 
+#ifndef _LINUX_LUSTRE_FSFILT_H
+#define _LINUX_LUSTRE_FSFILT_H
+
 #ifndef _LUSTRE_FSFILT_H
-#define _LUSTRE_FSFILT_H
+#error Do not #include this file directly. #include <lustre_fsfilt.h> instead
+#endif
 
 #ifdef __KERNEL__
 
-#include <linux/obd.h>
-#include <linux/obd_class.h>
+#include <obd.h>
+#include <obd_class.h>
 
 typedef void (*fsfilt_cb_t)(struct obd_device *obd, __u64 last_rcvd,
                             void *data, int error);
@@ -38,15 +42,22 @@ struct fsfilt_objinfo {
         int fso_bufcnt;
 };
 
+#define XATTR_LUSTRE_MDS_LOV_EA         "lov"
+
+struct lustre_dquot;
 struct fsfilt_operations {
         struct list_head fs_list;
         struct module *fs_owner;
         char   *fs_type;
+        char   *(* fs_getlabel)(struct super_block *sb);
+        int     (* fs_setlabel)(struct super_block *sb, char *label);
+        char   *(* fs_uuid)(struct super_block *sb);
         void   *(* fs_start)(struct inode *inode, int op, void *desc_private,
                              int logs);
         void   *(* fs_brw_start)(int objcount, struct fsfilt_objinfo *fso,
                                  int niocount, struct niobuf_local *nb,
                                  void *desc_private, int logs);
+        int     (* fs_extend)(struct inode *inode, unsigned nblocks, void *h);
         int     (* fs_commit)(struct inode *inode, void *handle,int force_sync);
         int     (* fs_commit_async)(struct inode *inode, void *handle,
                                         void **wait_handle);
@@ -56,8 +67,20 @@ struct fsfilt_operations {
         int     (* fs_iocontrol)(struct inode *inode, struct file *file,
                                  unsigned int cmd, unsigned long arg);
         int     (* fs_set_md)(struct inode *inode, void *handle, void *md,
-                              int size);
-        int     (* fs_get_md)(struct inode *inode, void *md, int size);
+                              int size, const char *name);
+        int     (* fs_get_md)(struct inode *inode, void *md, int size,
+                              const char *name);
+        /*
+         * this method is needed to make IO operation fsfilt nature depend.
+         *
+         * This operation maybe synchronous or asynchronous.
+         *
+         * Return convention: positive number of bytes written (synchronously)
+         * on success. Negative errno value on failure. Zero if asynchronous
+         * IO was submitted successfully.
+         *
+         */
+        int     (* fs_send_bio)(int rw, struct inode *inode,struct kiobuf *bio);
         ssize_t (* fs_readpage)(struct file *file, char *buf, size_t count,
                                 loff_t *offset);
         int     (* fs_add_journal_cb)(struct obd_device *obd, __u64 last_rcvd,
@@ -65,16 +88,27 @@ struct fsfilt_operations {
                                       void *cb_data);
         int     (* fs_statfs)(struct super_block *sb, struct obd_statfs *osfs);
         int     (* fs_sync)(struct super_block *sb);
-        int     (* fs_map_inode_page)(struct inode *inode, struct page *page,
-                                      unsigned long *blocks, int *created,
-                                      int create);
-        int     (* fs_prep_san_write)(struct inode *inode, long *blocks,
-                                      int nblocks, loff_t newsize);
+        int     (* fs_map_inode_pages)(struct inode *inode, struct page **page,
+                                       int pages, unsigned long *blocks,
+                                       int *created, int create,
+                                       struct semaphore *sem);
         int     (* fs_write_record)(struct file *, void *, int size, loff_t *,
                                     int force_sync);
         int     (* fs_read_record)(struct file *, void *, int size, loff_t *);
         int     (* fs_setup)(struct super_block *sb);
         int     (* fs_get_op_len)(int, struct fsfilt_objinfo *, int);
+        int     (* fs_quotactl)(struct super_block *sb,
+                                struct obd_quotactl *oqctl);
+        int     (* fs_quotacheck)(struct super_block *sb,
+                                  struct obd_quotactl *oqctl);
+        __u64   (* fs_get_version) (struct inode *inode);
+        __u64   (* fs_set_version) (struct inode *inode, __u64 new_version);
+        int     (* fs_quotainfo)(struct lustre_quota_info *lqi, int type,
+                                 int cmd);
+        int     (* fs_qids)(struct file *file, struct inode *inode, int type,
+                            struct list_head *list);
+        int     (* fs_dquot)(struct lustre_dquot *dquot, int cmd);
+        lvfs_sbdev_type (* fs_journal_sbdev)(struct super_block *sb);
 };
 
 extern int fsfilt_register_ops(struct fsfilt_operations *fs_ops);
@@ -82,6 +116,41 @@ extern void fsfilt_unregister_ops(struct fsfilt_operations *fs_ops);
 extern struct fsfilt_operations *fsfilt_get_ops(const char *type);
 extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
 
+static inline char *fsfilt_get_label(struct obd_device *obd,
+                                     struct super_block *sb)
+{
+        if (obd->obd_fsops->fs_getlabel == NULL)
+                return NULL;
+        if (obd->obd_fsops->fs_getlabel(sb)[0] == '\0')
+                return NULL;
+
+        return obd->obd_fsops->fs_getlabel(sb);
+}
+
+static inline int fsfilt_set_label(struct obd_device *obd,
+                                   struct super_block *sb, char *label)
+{
+        if (obd->obd_fsops->fs_setlabel == NULL)
+                return -ENOSYS;
+        return (obd->obd_fsops->fs_setlabel(sb, label));
+}
+
+static inline __u8 *fsfilt_uuid(struct obd_device *obd, struct super_block *sb)
+{
+        if (obd->obd_fsops->fs_uuid == NULL)
+                return NULL;
+
+        return obd->obd_fsops->fs_uuid(sb);
+}
+
+static inline lvfs_sbdev_type fsfilt_journal_sbdev(struct obd_device *obd,
+                                                   struct super_block *sb)
+{
+        if (obd && obd->obd_fsops && obd->obd_fsops->fs_journal_sbdev)
+                return obd->obd_fsops->fs_journal_sbdev(sb);
+        return (lvfs_sbdev_type)0;
+}
+
 #define FSFILT_OP_UNLINK         1
 #define FSFILT_OP_RMDIR          2
 #define FSFILT_OP_RENAME         3
@@ -92,6 +161,23 @@ extern void fsfilt_put_ops(struct fsfilt_operations *fs_ops);
 #define FSFILT_OP_SETATTR        8
 #define FSFILT_OP_LINK           9
 #define FSFILT_OP_CANCEL_UNLINK 10
+#define FSFILT_OP_JOIN          11
+#define FSFILT_OP_NOOP          15
+
+#define fsfilt_check_slow(obd, start, timeout, msg)                     \
+do {                                                                    \
+        if (time_before(jiffies, start + 15 * HZ))                      \
+                break;                                                  \
+        else if (time_before(jiffies, start + 30 * HZ))                 \
+                CDEBUG(D_VFSTRACE, "%s: slow %s %lus\n", obd->obd_name, \
+                       msg, (jiffies-start) / HZ);                      \
+        else if (time_before(jiffies, start + timeout / 2 * HZ))        \
+                CWARN("%s: slow %s %lus\n", obd->obd_name, msg,         \
+                      (jiffies - start) / HZ);                          \
+        else                                                            \
+                CERROR("%s: slow %s %lus\n", obd->obd_name, msg,        \
+                       (jiffies - start) / HZ);                         \
+} while (0)
 
 static inline void *fsfilt_start_log(struct obd_device *obd,
                                      struct inode *inode, int op,
@@ -99,8 +185,13 @@ static inline void *fsfilt_start_log(struct obd_device *obd,
 {
         unsigned long now = jiffies;
         void *parent_handle = oti ? oti->oti_handle : NULL;
-        void *handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
-        CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
+        void *handle;
+
+        if (obd->obd_fail)
+                return ERR_PTR(-EROFS);
+
+        handle = obd->obd_fsops->fs_start(inode, op, parent_handle, logs);
+        CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
 
         if (oti != NULL) {
                 if (parent_handle == NULL) {
@@ -111,8 +202,7 @@ static inline void *fsfilt_start_log(struct obd_device *obd,
                         LBUG();
                 }
         }
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
+        fsfilt_check_slow(obd, now, obd_timeout, "journal start");
         return handle;
 }
 
@@ -122,17 +212,21 @@ static inline void *fsfilt_start(struct obd_device *obd, struct inode *inode,
         return fsfilt_start_log(obd, inode, op, oti, 0);
 }
 
-static inline void *fsfilt_brw_start_log(struct obd_device *obd,
-                                         int objcount,
+static inline void *fsfilt_brw_start_log(struct obd_device *obd, int objcount,
                                          struct fsfilt_objinfo *fso,
                                          int niocount, struct niobuf_local *nb,
                                          struct obd_trans_info *oti, int logs)
 {
         unsigned long now = jiffies;
         void *parent_handle = oti ? oti->oti_handle : NULL;
-        void *handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
-                                                    parent_handle, logs);
-        CDEBUG(D_HA, "started handle %p (%p)\n", handle, parent_handle);
+        void *handle;
+
+        if (obd->obd_fail)
+                return ERR_PTR(-EROFS);
+
+        handle = obd->obd_fsops->fs_brw_start(objcount, fso, niocount, nb,
+                                              parent_handle, logs);
+        CDEBUG(D_INFO, "started handle %p (%p)\n", handle, parent_handle);
 
         if (oti != NULL) {
                 if (parent_handle == NULL) {
@@ -143,8 +237,7 @@ static inline void *fsfilt_brw_start_log(struct obd_device *obd,
                         LBUG();
                 }
         }
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
+        fsfilt_check_slow(obd, now, obd_timeout, "journal start");
 
         return handle;
 }
@@ -157,15 +250,26 @@ static inline void *fsfilt_brw_start(struct obd_device *obd, int objcount,
         return fsfilt_brw_start_log(obd, objcount, fso, niocount, nb, oti, 0);
 }
 
+static inline int fsfilt_extend(struct obd_device *obd, struct inode *inode,
+                                unsigned int nblocks, void *handle)
+{
+        unsigned long now = jiffies;
+        int rc = obd->obd_fsops->fs_extend(inode, nblocks, handle);
+        CDEBUG(D_INFO, "extending handle %p with %u blocks\n", handle, nblocks);
+
+        fsfilt_check_slow(obd, now, obd_timeout, "journal extend");
+
+        return rc;
+}
+
 static inline int fsfilt_commit(struct obd_device *obd, struct inode *inode,
                                 void *handle, int force_sync)
 {
         unsigned long now = jiffies;
         int rc = obd->obd_fsops->fs_commit(inode, handle, force_sync);
-        CDEBUG(D_HA, "committing handle %p\n", handle);
+        CDEBUG(D_INFO, "committing handle %p\n", handle);
 
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
+        fsfilt_check_slow(obd, now, obd_timeout, "journal start");
 
         return rc;
 }
@@ -177,9 +281,8 @@ static inline int fsfilt_commit_async(struct obd_device *obd,
         unsigned long now = jiffies;
         int rc = obd->obd_fsops->fs_commit_async(inode, handle, wait_handle);
 
-        CDEBUG(D_HA, "committing handle %p (async)\n", *wait_handle);
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
+        CDEBUG(D_INFO, "committing handle %p (async)\n", *wait_handle);
+        fsfilt_check_slow(obd, now, obd_timeout, "journal start");
 
         return rc;
 }
@@ -189,9 +292,8 @@ static inline int fsfilt_commit_wait(struct obd_device *obd,
 {
         unsigned long now = jiffies;
         int rc = obd->obd_fsops->fs_commit_wait(inode, handle);
-        CDEBUG(D_HA, "waiting for completion %p\n", handle);
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long journal start time %lus\n", (jiffies - now) / HZ);
+        CDEBUG(D_INFO, "waiting for completion %p\n", handle);
+        fsfilt_check_slow(obd, now, obd_timeout, "journal start");
         return rc;
 }
 
@@ -201,8 +303,7 @@ static inline int fsfilt_setattr(struct obd_device *obd, struct dentry *dentry,
         unsigned long now = jiffies;
         int rc;
         rc = obd->obd_fsops->fs_setattr(dentry, handle, iattr, do_trunc);
-        if (time_after(jiffies, now + 15 * HZ))
-                CERROR("long setattr time %lus\n", (jiffies - now) / HZ);
+        fsfilt_check_slow(obd, now, obd_timeout, "setattr");
         return rc;
 }
 
@@ -214,15 +315,26 @@ static inline int fsfilt_iocontrol(struct obd_device *obd, struct inode *inode,
 }
 
 static inline int fsfilt_set_md(struct obd_device *obd, struct inode *inode,
-                                void *handle, void *md, int size)
+                                void *handle, void *md, int size,
+                                const char *name)
 {
-        return obd->obd_fsops->fs_set_md(inode, handle, md, size);
+        return obd->obd_fsops->fs_set_md(inode, handle, md, size, name);
 }
 
 static inline int fsfilt_get_md(struct obd_device *obd, struct inode *inode,
-                                void *md, int size)
+                                void *md, int size, const char *name)
 {
-        return obd->obd_fsops->fs_get_md(inode, md, size);
+        return obd->obd_fsops->fs_get_md(inode, md, size, name);
+}
+
+static inline int fsfilt_send_bio(int rw, struct obd_device *obd,
+                                  struct inode *inode, void *bio)
+{
+        LASSERTF(rw == OBD_BRW_WRITE || rw == OBD_BRW_READ, "%x\n", rw);
+
+        if (rw == OBD_BRW_READ)
+                return obd->obd_fsops->fs_send_bio(READ, inode, bio);
+        return obd->obd_fsops->fs_send_bio(WRITE, inode, bio);
 }
 
 static inline ssize_t fsfilt_readpage(struct obd_device *obd,
@@ -242,15 +354,16 @@ static inline int fsfilt_add_journal_cb(struct obd_device *obd, __u64 last_rcvd,
 
 /* very similar to obd_statfs(), but caller already holds obd_osfs_lock */
 static inline int fsfilt_statfs(struct obd_device *obd, struct super_block *sb,
-                                unsigned long max_age)
+                                __u64 max_age)
 {
         int rc = 0;
 
-        CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
-        if (time_before(obd->obd_osfs_age, max_age)) {
+        CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
+                obd->obd_osfs_age, max_age);
+        if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
                 rc = obd->obd_fsops->fs_statfs(sb, &obd->obd_osfs);
                 if (rc == 0) /* N.B. statfs can't really fail */
-                        obd->obd_osfs_age = jiffies;
+                        obd->obd_osfs_age = cfs_time_current_64();
         } else {
                 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
         }
@@ -263,23 +376,58 @@ static inline int fsfilt_sync(struct obd_device *obd, struct super_block *sb)
         return obd->obd_fsops->fs_sync(sb);
 }
 
-static inline int fsfilt_map_inode_page(struct obd_device *obd,
-                                        struct inode *inode, struct page *page,
-                                        unsigned long *blocks, int *created,
-                                        int create)
+static inline int fsfilt_quotacheck(struct obd_device *obd,
+                                    struct super_block *sb,
+                                    struct obd_quotactl *oqctl)
+{
+        if (obd->obd_fsops->fs_quotacheck)
+                return obd->obd_fsops->fs_quotacheck(sb, oqctl);
+        return -ENOTSUPP;
+}
+
+static inline int fsfilt_quotactl(struct obd_device *obd,
+                                  struct super_block *sb,
+                                  struct obd_quotactl *oqctl)
+{
+        if (obd->obd_fsops->fs_quotactl)
+                return obd->obd_fsops->fs_quotactl(sb, oqctl);
+        return -ENOTSUPP;
+}
+
+static inline int fsfilt_quotainfo(struct obd_device *obd,
+                                   struct lustre_quota_info *lqi,
+                                   int type, int cmd)
 {
-        return obd->obd_fsops->fs_map_inode_page(inode, page, blocks, created,
-                                                 create);
+        if (obd->obd_fsops->fs_quotainfo)
+                return obd->obd_fsops->fs_quotainfo(lqi, type, cmd);
+        return -ENOTSUPP;
 }
 
-static inline int fs_prep_san_write(struct obd_device *obd,
-                                    struct inode *inode,
-                                    long *blocks,
-                                    int nblocks,
-                                    loff_t newsize)
+static inline int fsfilt_qids(struct obd_device *obd, struct file *file,
+                              struct inode *inode, int type, 
+                              struct list_head *list)
 {
-        return obd->obd_fsops->fs_prep_san_write(inode, blocks,
-                                                 nblocks, newsize);
+        if (obd->obd_fsops->fs_qids)
+                return obd->obd_fsops->fs_qids(file, inode, type, list);
+        return -ENOTSUPP;
+}
+
+static inline int fsfilt_dquot(struct obd_device *obd,
+                               struct lustre_dquot *dquot, int cmd)
+{
+        if (obd->obd_fsops->fs_dquot)
+                return obd->obd_fsops->fs_dquot(dquot, cmd);
+        return -ENOTSUPP;
+}
+
+static inline int fsfilt_map_inode_pages(struct obd_device *obd,
+                                         struct inode *inode,
+                                         struct page **page, int pages,
+                                         unsigned long *blocks, int *created,
+                                         int create, struct semaphore *sem)
+{
+        return obd->obd_fsops->fs_map_inode_pages(inode, page, pages, blocks,
+                                                  created, create, sem);
 }
 
 static inline int fsfilt_read_record(struct obd_device *obd, struct file *file,
@@ -302,6 +450,22 @@ static inline int fsfilt_setup(struct obd_device *obd, struct super_block *fs)
         return 0;
 }
 
+static inline __u64 fsfilt_set_version(struct obd_device *obd,
+                                      struct inode *inode, __u64 new_version)
+{
+        if (obd->obd_fsops->fs_set_version)
+                return obd->obd_fsops->fs_set_version(inode, new_version);
+        return -EOPNOTSUPP;
+}
+
+static inline __u64 fsfilt_get_version(struct obd_device *obd,
+                                       struct inode *inode)
+{
+        if (obd->obd_fsops->fs_set_version)
+                return obd->obd_fsops->fs_get_version(inode);
+        return -EOPNOTSUPP;
+}
+
 #endif /* __KERNEL__ */
 
 #endif