Whamcloud - gitweb
LU-80 lov: large stripe count support
[fs/lustre-release.git] / lustre / include / dt_object.h
index b1fa210..db232da 100644 (file)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
@@ -66,11 +69,34 @@ struct txn_param;
 struct dt_device;
 struct dt_object;
 struct dt_index_features;
+struct dt_quota_ctxt;
+
+typedef enum {
+        MNTOPT_USERXATTR        = 0x00000001,
+        MNTOPT_ACL              = 0x00000002,
+} mntopt_t;
 
 struct dt_device_param {
         unsigned           ddp_max_name_len;
         unsigned           ddp_max_nlink;
         unsigned           ddp_block_shift;
+        mntopt_t           ddp_mntopts;
+        unsigned           ddp_max_ea_size;
+};
+
+/**
+ * Per-transaction commit callback function
+ */
+struct dt_txn_commit_cb;
+typedef void (*dt_cb_t)(struct lu_env *env, struct thandle *th,
+                        struct dt_txn_commit_cb *cb, int err);
+/**
+ * Special per-transaction callback for cases when just commit callback
+ * is needed and per-device callback are not convenient to use
+ */
+struct dt_txn_commit_cb {
+        cfs_list_t dcb_linkage;
+        dt_cb_t    dcb_func;
 };
 
 /**
@@ -82,11 +108,12 @@ enum dt_txn_op {
         DTO_IDNEX_UPDATE,
         DTO_OBJECT_CREATE,
         DTO_OBJECT_DELETE,
-        DTO_ATTR_SET,
+        DTO_ATTR_SET_BASE,
         DTO_XATTR_SET,
         DTO_LOG_REC, /**< XXX temporary: dt layer knows nothing about llog. */
         DTO_WRITE_BASE,
         DTO_WRITE_BLOCK,
+        DTO_ATTR_SET_CHOWN,
 
         DTO_NR
 };
@@ -99,7 +126,7 @@ struct dt_device_operations {
          * Return device-wide statistics.
          */
         int   (*dt_statfs)(const struct lu_env *env,
-                           struct dt_device *dev, struct kstatfs *sfs);
+                           struct dt_device *dev, cfs_kstatfs_t *sfs);
         /**
          * Start transaction, described by \a param.
          */
@@ -112,6 +139,11 @@ struct dt_device_operations {
         void  (*dt_trans_stop)(const struct lu_env *env,
                                struct thandle *th);
         /**
+         * Add commit callback to the transaction.
+         */
+        int   (*dt_trans_cb_add)(struct thandle *th,
+                                 struct dt_txn_commit_cb *dcb);
+        /**
          * Return fid of root index object.
          */
         int   (*dt_root_get)(const struct lu_env *env,
@@ -144,6 +176,12 @@ struct dt_device_operations {
                                    struct dt_device *dev,
                                    int mode, unsigned long timeout,
                                    __u32 alg, struct lustre_capa_key *keys);
+        /**
+         * Initialize quota context.
+         */
+        void (*dt_init_quota_ctxt)(const struct lu_env *env,
+                                   struct dt_device *dev,
+                                   struct dt_quota_ctxt *ctxt, void *data);
 
         /**
          *  get transaction credits for given \a op.
@@ -163,6 +201,8 @@ struct dt_index_features {
         size_t dif_recsize_min;
         /** maximal required record size, 0 if no limit */
         size_t dif_recsize_max;
+        /** pointer size for record */
+        size_t dif_ptrsize;
 };
 
 enum dt_index_flags {
@@ -184,15 +224,58 @@ extern const struct dt_index_features dt_directory_features;
 
 /**
  * This is a general purpose dt allocation hint.
- * It now contains the parent object. 
+ * It now contains the parent object.
  * It can contain any allocation hint in the future.
  */
 struct dt_allocation_hint {
-        struct dt_object *dah_parent;
-        __u32             dah_mode;
+        struct dt_object           *dah_parent;
+        __u32                       dah_mode;
+};
+
+/**
+ * object type specifier.
+ */
+
+enum dt_format_type {
+        DFT_REGULAR,
+        DFT_DIR,
+        /** for mknod */
+        DFT_NODE,
+        /** for special index */
+        DFT_INDEX,
+        /** for symbolic link */
+        DFT_SYM,
 };
 
 /**
+ * object format specifier.
+ */
+struct dt_object_format {
+        /** type for dt object */
+        enum dt_format_type dof_type;
+        union {
+                struct dof_regular {
+                } dof_reg;
+                struct dof_dir {
+                } dof_dir;
+                struct dof_node {
+                } dof_node;
+                /**
+                 * special index need feature as parameter to create
+                 * special idx
+                 */
+                struct dof_index {
+                        const struct dt_index_features *di_feat;
+                } dof_idx;
+        } u;
+};
+
+enum dt_format_type dt_mode_to_dft(__u32 mode);
+
+/** Version type. May differ in DMU and ldiskfs */
+typedef __u64 dt_obj_version_t;
+
+/**
  * Per-dt-object operations.
  */
 struct dt_object_operations {
@@ -204,6 +287,8 @@ struct dt_object_operations {
                                 struct dt_object *dt);
         void  (*do_write_unlock)(const struct lu_env *env,
                                  struct dt_object *dt);
+        int  (*do_write_locked)(const struct lu_env *env,
+                                struct dt_object *dt);
         /**
          * Note: following ->do_{x,}attr_{set,get}() operations are very
          * similar to ->moo_{x,}attr_{set,get}() operations in struct
@@ -279,7 +364,7 @@ struct dt_object_operations {
         void  (*do_ah_init)(const struct lu_env *env,
                             struct dt_allocation_hint *ah,
                             struct dt_object *parent,
-                            umode_t child_mode);
+                            cfs_umode_t child_mode);
         /**
          * Create new object on this device.
          *
@@ -287,8 +372,9 @@ struct dt_object_operations {
          * postcondition: ergo(result == 0, dt_object_exists(dt));
          */
         int   (*do_create)(const struct lu_env *env, struct dt_object *dt,
-                           struct lu_attr *attr, 
+                           struct lu_attr *attr,
                            struct dt_allocation_hint *hint,
+                           struct dt_object_format *dof,
                            struct thandle *th);
 
         /**
@@ -320,6 +406,17 @@ struct dt_object_operations {
                                         struct lustre_capa *old,
                                         __u64 opc);
         int (*do_object_sync)(const struct lu_env *, struct dt_object *);
+        dt_obj_version_t (*do_version_get)(const struct lu_env *env,
+                                           struct dt_object *dt);
+        void (*do_version_set)(const struct lu_env *env, struct dt_object *dt,
+                               dt_obj_version_t new_version);
+        /**
+         * Get object info of next level. Currently, only get inode from osd.
+         * This is only used by quota b=16542
+         * precondition: dt_object_exists(dt);
+         */
+        int (*do_data_get)(const struct lu_env *env, struct dt_object *dt,
+                           void **data);
 };
 
 /**
@@ -337,7 +434,8 @@ struct dt_body_operations {
          */
         ssize_t (*dbo_write)(const struct lu_env *env, struct dt_object *dt,
                              const struct lu_buf *buf, loff_t *pos,
-                             struct thandle *handle, struct lustre_capa *capa);
+                             struct thandle *handle, struct lustre_capa *capa,
+                             int ignore_quota);
 };
 
 /**
@@ -370,7 +468,8 @@ struct dt_index_operations {
          */
         int (*dio_insert)(const struct lu_env *env, struct dt_object *dt,
                           const struct dt_rec *rec, const struct dt_key *key,
-                          struct thandle *handle, struct lustre_capa *capa);
+                          struct thandle *handle, struct lustre_capa *capa,
+                          int ignore_quota);
         /**
          * precondition: dt_object_exists(dt);
          */
@@ -387,7 +486,8 @@ struct dt_index_operations {
                  * precondition: dt_object_exists(dt);
                  */
                 struct dt_it *(*init)(const struct lu_env *env,
-                                      struct dt_object *dt, int writable,
+                                      struct dt_object *dt,
+                                      __u32 attr,
                                       struct lustre_capa *capa);
                 void          (*fini)(const struct lu_env *env,
                                       struct dt_it *di);
@@ -396,16 +496,16 @@ struct dt_index_operations {
                                       const struct dt_key *key);
                 void           (*put)(const struct lu_env *env,
                                       struct dt_it *di);
-                int            (*del)(const struct lu_env *env,
-                                      struct dt_it *di, struct thandle *th);
                 int           (*next)(const struct lu_env *env,
                                       struct dt_it *di);
                 struct dt_key *(*key)(const struct lu_env *env,
                                       const struct dt_it *di);
                 int       (*key_size)(const struct lu_env *env,
                                       const struct dt_it *di);
-                struct dt_rec *(*rec)(const struct lu_env *env,
-                                      const struct dt_it *di);
+                int            (*rec)(const struct lu_env *env,
+                                      const struct dt_it *di,
+                                      struct lu_dirent *lde,
+                                      __u32 attr);
                 __u64        (*store)(const struct lu_env *env,
                                       const struct dt_it *di);
                 int           (*load)(const struct lu_env *env,
@@ -414,7 +514,7 @@ struct dt_index_operations {
 };
 
 struct dt_device {
-        struct lu_device             dd_lu_dev;
+        struct lu_device                   dd_lu_dev;
         const struct dt_device_operations *dd_ops;
 
         /**
@@ -422,7 +522,7 @@ struct dt_device {
          * way, because callbacks are supposed to be added/deleted only during
          * single-threaded start-up shut-down procedures.
          */
-        struct list_head             dd_txn_callbacks;
+        cfs_list_t                         dd_txn_callbacks;
 };
 
 int  dt_device_init(struct dt_device *dev, struct lu_device_type *t);
@@ -440,7 +540,7 @@ static inline struct dt_device * lu2dt_dev(struct lu_device *l)
 }
 
 struct dt_object {
-        struct lu_object             do_lu;
+        struct lu_object                   do_lu;
         const struct dt_object_operations *do_ops;
         const struct dt_body_operations   *do_body_ops;
         const struct dt_index_operations  *do_index_ops;
@@ -459,8 +559,6 @@ static inline int dt_object_exists(const struct dt_object *dt)
 struct txn_param {
         /** number of blocks this transaction will modify */
         unsigned int tp_credits;
-        /** sync transaction is needed */
-        __u32        tp_sync:1;
 };
 
 static inline void txn_param_init(struct txn_param *p, unsigned int credits)
@@ -469,6 +567,12 @@ static inline void txn_param_init(struct txn_param *p, unsigned int credits)
         p->tp_credits = credits;
 }
 
+static inline void txn_param_credit_add(struct txn_param *p,
+                                        unsigned int credits)
+{
+        p->tp_credits += credits;
+}
+
 /**
  * This is the general purpose transaction handle.
  * 1. Transaction Life Cycle
@@ -493,6 +597,8 @@ struct thandle {
         /** the last operation result in this transaction.
          * this value is used in recovery */
         __s32             th_result;
+        /** whether we need sync commit */
+        int               th_sync;
 };
 
 /**
@@ -511,10 +617,10 @@ struct dt_txn_callback {
                              struct txn_param *param, void *cookie);
         int (*dtc_txn_stop)(const struct lu_env *env,
                             struct thandle *txn, void *cookie);
-        int (*dtc_txn_commit)(const struct lu_env *env,
-                              struct thandle *txn, void *cookie);
-        void            *dtc_cookie;
-        struct list_head dtc_linkage;
+        void (*dtc_txn_commit)(struct thandle *txn, void *cookie);
+        void                *dtc_cookie;
+        __u32                dtc_tag;
+        cfs_list_t           dtc_linkage;
 };
 
 void dt_txn_callback_add(struct dt_device *dev, struct dt_txn_callback *cb);
@@ -523,13 +629,74 @@ void dt_txn_callback_del(struct dt_device *dev, struct dt_txn_callback *cb);
 int dt_txn_hook_start(const struct lu_env *env,
                       struct dt_device *dev, struct txn_param *param);
 int dt_txn_hook_stop(const struct lu_env *env, struct thandle *txn);
-int dt_txn_hook_commit(const struct lu_env *env, struct thandle *txn);
+void dt_txn_hook_commit(struct thandle *txn);
 
 int dt_try_as_dir(const struct lu_env *env, struct dt_object *obj);
+
+/**
+ * Callback function used for parsing path.
+ * \see llo_store_resolve
+ */
+typedef int (*dt_entry_func_t)(const struct lu_env *env,
+                            const char *name,
+                            void *pvt);
+
+#define DT_MAX_PATH 1024
+
+int dt_path_parser(const struct lu_env *env,
+                   char *local, dt_entry_func_t entry_func,
+                   void *data);
+
 struct dt_object *dt_store_open(const struct lu_env *env,
-                                struct dt_device *dt, const char *name,
+                                struct dt_device *dt,
+                                const char *dirname,
+                                const char *filename,
                                 struct lu_fid *fid);
 
-/** @} dt */
+struct dt_object *dt_locate(const struct lu_env *env,
+                            struct dt_device *dev,
+                            const struct lu_fid *fid);
+
+static inline dt_obj_version_t do_version_get(const struct lu_env *env,
+                                              struct dt_object *o)
+{
+        LASSERT(o->do_ops->do_version_get);
+        return o->do_ops->do_version_get(env, o);
+}
 
+static inline void do_version_set(const struct lu_env *env,
+                                  struct dt_object *o, dt_obj_version_t v)
+{
+        LASSERT(o->do_ops->do_version_set);
+        return o->do_ops->do_version_set(env, o, v);
+}
+
+int dt_record_read(const struct lu_env *env, struct dt_object *dt,
+                   struct lu_buf *buf, loff_t *pos);
+int dt_record_write(const struct lu_env *env, struct dt_object *dt,
+                    const struct lu_buf *buf, loff_t *pos, struct thandle *th);
+
+
+static inline struct thandle *dt_trans_start(const struct lu_env *env,
+                                             struct dt_device *d,
+                                             struct txn_param *p)
+{
+        LASSERT(d->dd_ops->dt_trans_start);
+        return d->dd_ops->dt_trans_start(env, d, p);
+}
+
+static inline void dt_trans_stop(const struct lu_env *env,
+                                 struct dt_device *d, struct thandle *th)
+{
+        LASSERT(d->dd_ops->dt_trans_stop);
+        return d->dd_ops->dt_trans_stop(env, th);
+}
+
+static inline int dt_trans_cb_add(struct thandle *th,
+                                  struct dt_txn_commit_cb *dcb)
+{
+        LASSERT(th->th_dev->dd_ops->dt_trans_cb_add);
+        return th->th_dev->dd_ops->dt_trans_cb_add(th, dcb);
+}
+/** @} dt */
 #endif /* __LUSTRE_DT_OBJECT_H */