Whamcloud - gitweb
LU-6142 lustre: convert use of container_of0 in include/
[fs/lustre-release.git] / lustre / include / dt_object.h
index 47e2591..752ac11 100644 (file)
@@ -332,19 +332,19 @@ struct dt_index_features {
 };
 
 enum dt_index_flags {
-        /** index supports variable sized keys */
-        DT_IND_VARKEY = 1 << 0,
-        /** index supports variable sized records */
-        DT_IND_VARREC = 1 << 1,
-        /** index can be modified */
-        DT_IND_UPDATE = 1 << 2,
-        /** index supports records with non-unique (duplicate) keys */
-        DT_IND_NONUNQ = 1 << 3,
-        /**
-         * index support fixed-size keys sorted with natural numerical way
-         * and is able to return left-side value if no exact value found
-         */
-        DT_IND_RANGE = 1 << 4,
+       /** index supports variable sized keys */
+       DT_IND_VARKEY = BIT(0),
+       /** index supports variable sized records */
+       DT_IND_VARREC = BIT(1),
+       /** index can be modified */
+       DT_IND_UPDATE = BIT(2),
+       /** index supports records with non-unique (duplicate) keys */
+       DT_IND_NONUNQ = BIT(3),
+       /**
+        * index support fixed-size keys sorted with natural numerical way
+        * and is able to return left-side value if no exact value found
+        */
+       DT_IND_RANGE = BIT(4),
 };
 
 /* for dt_read_lock() and dt_write_lock() object lock rule */
@@ -1317,11 +1317,21 @@ struct dt_body_operations {
         * then the method should maintain space accounting for the given
         * credentials.
         *
+        * user_size parameter is the apparent size of the file, ie the size
+        * of the clear text version of the file. It can differ from the actual
+        * amount of valuable data received when a file is encrypted,
+        * because encrypted pages always contain PAGE_SIZE bytes of data,
+        * even if clear text data is only a few bytes.
+        * In case of encrypted file, apparent size will be stored as the inode
+        * size, so that servers return to clients an object size they can use
+        * to determine clear text size.
+        *
         * \param[in] env       execution environment for this thread
         * \param[in] dt        object
         * \param[in] lb        array of descriptors for the buffers
         * \param[in] nr        size of the array
         * \param[in] th        transaction handle
+        * \param[in] user_size apparent size
         *
         * \retval 0            on success
         * \retval negative     negated errno on error
@@ -1330,7 +1340,8 @@ struct dt_body_operations {
                                struct dt_object *dt,
                                struct niobuf_local *lb,
                                int nr,
-                               struct thandle *th);
+                               struct thandle *th,
+                               __u64 user_size);
 
        /**
         * Return logical to physical block mapping for a given extent
@@ -1413,6 +1424,39 @@ struct dt_body_operations {
                             __u64 start,
                             __u64 end,
                             enum lu_ladvise_type advice);
+
+       /**
+        * Declare intention to preallocate space for an object
+        *
+        * \param[in] env       execution environment for this thread
+        * \param[in] dt        object
+        * \param[in] th        transaction handle
+        *
+        * \retval 0            on success
+        * \retval negative     negated errno on error
+        */
+       int (*dbo_declare_fallocate)(const struct lu_env *env,
+                                   struct dt_object *dt,
+                                   struct thandle *th);
+       /**
+        * Allocate specified region for an object
+        *
+        * \param[in] env       execution environment for this thread
+        * \param[in] dt        object
+        * \param[in] start     the start of the region to allocate
+        * \param[in] end       the end of the region to allocate
+        * \param[in] mode      fallocate mode
+        * \param[in] th        transaction handle
+        *
+        * \retval 0            on success
+        * \retval negative     negated errno on error
+        */
+       int (*dbo_fallocate)(const struct lu_env *env,
+                           struct dt_object *dt,
+                           __u64 start,
+                           __u64 end,
+                           int mode,
+                           struct thandle *th);
 };
 
 /**
@@ -1823,8 +1867,8 @@ static inline int lu_device_is_dt(const struct lu_device *d)
 
 static inline struct dt_device * lu2dt_dev(struct lu_device *l)
 {
-        LASSERT(lu_device_is_dt(l));
-        return container_of0(l, struct dt_device, dd_lu_dev);
+       LASSERT(lu_device_is_dt(l));
+       return container_of_safe(l, struct dt_device, dd_lu_dev);
 }
 
 struct dt_object {
@@ -1859,8 +1903,8 @@ static inline struct lu_device *dt2lu_dev(struct dt_device *d)
 
 static inline struct dt_object *lu2dt(struct lu_object *l)
 {
-        LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
-        return container_of0(l, struct dt_object, do_lu);
+       LASSERT(l == NULL || IS_ERR(l) || lu_device_is_dt(l->lo_dev));
+       return container_of_safe(l, struct dt_object, do_lu);
 }
 
 int  dt_object_init(struct dt_object *obj,
@@ -1881,13 +1925,13 @@ static inline int dt_object_remote(const struct dt_object *dt)
 static inline struct dt_object *lu2dt_obj(struct lu_object *o)
 {
        LASSERT(ergo(o != NULL, lu_device_is_dt(o->lo_dev)));
-       return container_of0(o, struct dt_object, do_lu);
+       return container_of_safe(o, struct dt_object, do_lu);
 }
 
 static inline struct dt_object *dt_object_child(struct dt_object *o)
 {
-       return container_of0(lu_object_next(&(o)->do_lu),
-                            struct dt_object, do_lu);
+       return container_of(lu_object_next(&(o)->do_lu),
+                           struct dt_object, do_lu);
 }
 
 /**
@@ -2115,6 +2159,17 @@ static inline int dt_object_sync(const struct lu_env *env, struct dt_object *o,
        return o->do_ops->do_object_sync(env, o, start, end);
 }
 
+static inline int dt_fid_alloc(const struct lu_env *env,
+                              struct dt_device *d,
+                              struct lu_fid *fid,
+                              struct lu_object *parent,
+                              const struct lu_name *name)
+{
+       struct lu_device *l = dt2lu_dev(d);
+
+       return l->ld_ops->ldo_fid_alloc(env, l, fid, parent, name);
+}
+
 int dt_declare_version_set(const struct lu_env *env, struct dt_object *o,
                            struct thandle *th);
 void dt_version_set(const struct lu_env *env, struct dt_object *o,
@@ -2451,13 +2506,13 @@ static inline int dt_declare_write_commit(const struct lu_env *env,
 
 
 static inline int dt_write_commit(const struct lu_env *env,
-                                  struct dt_object *d, struct niobuf_local *lnb,
-                                  int n, struct thandle *th)
+                                 struct dt_object *d, struct niobuf_local *lnb,
+                                 int n, struct thandle *th, __u64 size)
 {
-        LASSERT(d);
-        LASSERT(d->do_body_ops);
-        LASSERT(d->do_body_ops->dbo_write_commit);
-        return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th);
+       LASSERT(d);
+       LASSERT(d->do_body_ops);
+       LASSERT(d->do_body_ops->dbo_write_commit);
+       return d->do_body_ops->dbo_write_commit(env, d, lnb, n, th, size);
 }
 
 static inline int dt_read_prep(const struct lu_env *env, struct dt_object *d,
@@ -2518,6 +2573,29 @@ static inline int dt_ladvise(const struct lu_env *env, struct dt_object *dt,
        return dt->do_body_ops->dbo_ladvise(env, dt, start, end, advice);
 }
 
+static inline int dt_declare_falloc(const struct lu_env *env,
+                                     struct dt_object *dt, struct thandle *th)
+{
+       LASSERT(dt);
+       if (!dt->do_body_ops)
+               return -EOPNOTSUPP;
+       LASSERT(dt->do_body_ops);
+       LASSERT(dt->do_body_ops->dbo_declare_fallocate);
+       return dt->do_body_ops->dbo_declare_fallocate(env, dt, th);
+}
+
+static inline int dt_falloc(const struct lu_env *env, struct dt_object *dt,
+                             __u64 start, __u64 end, int mode,
+                             struct thandle *th)
+{
+       LASSERT(dt);
+       if (!dt->do_body_ops)
+               return -EOPNOTSUPP;
+       LASSERT(dt->do_body_ops);
+       LASSERT(dt->do_body_ops->dbo_fallocate);
+       return dt->do_body_ops->dbo_fallocate(env, dt, start, end, mode, th);
+}
+
 static inline int dt_fiemap_get(const struct lu_env *env, struct dt_object *d,
                                struct fiemap *fm)
 {