Whamcloud - gitweb
LU-3534 mdt: move last_rcvd obj update to LOD
[fs/lustre-release.git] / lustre / lod / lod_object.c
index 61dbede..e7a33af 100644 (file)
@@ -59,6 +59,7 @@ static const char dot[] = ".";
 static const char dotdot[] = "..";
 
 static const struct dt_body_operations lod_body_lnk_ops;
+static const struct dt_body_operations lod_body_ops;
 
 /**
  * Implementation of dt_index_operations::dio_lookup
@@ -3425,6 +3426,8 @@ static int lod_declare_object_create(const struct lu_env *env,
 
        if (dof->dof_type == DFT_SYM)
                dt->do_body_ops = &lod_body_lnk_ops;
+       else if (dof->dof_type == DFT_REGULAR)
+               dt->do_body_ops = &lod_body_ops;
 
        /*
         * it's lod_ah_init() that has decided the object will be striped
@@ -4002,12 +4005,39 @@ static ssize_t lod_write(const struct lu_env *env, struct dt_object *dt,
        return lod_sub_object_write(env, dt_object_child(dt), buf, pos, th, iq);
 }
 
+static int lod_declare_punch(const struct lu_env *env, struct dt_object *dt,
+                            __u64 start, __u64 end, struct thandle *th)
+{
+       if (dt_object_remote(dt))
+               return -ENOTSUPP;
+
+       return lod_sub_object_declare_punch(env, dt_object_child(dt), start,
+                                           end, th);
+}
+
+static int lod_punch(const struct lu_env *env, struct dt_object *dt,
+                    __u64 start, __u64 end, struct thandle *th)
+{
+       if (dt_object_remote(dt))
+               return -ENOTSUPP;
+
+       return lod_sub_object_punch(env, dt_object_child(dt), start, end, th);
+}
+
 static const struct dt_body_operations lod_body_lnk_ops = {
        .dbo_read               = lod_read,
        .dbo_declare_write      = lod_declare_write,
        .dbo_write              = lod_write
 };
 
+static const struct dt_body_operations lod_body_ops = {
+       .dbo_read               = lod_read,
+       .dbo_declare_write      = lod_declare_write,
+       .dbo_write              = lod_write,
+       .dbo_declare_punch      = lod_declare_punch,
+       .dbo_punch              = lod_punch,
+};
+
 /**
  * Implementation of lu_object_operations::loo_object_init.
  *
@@ -4127,8 +4157,16 @@ void lod_object_free_striping(const struct lu_env *env, struct lod_object *lo)
  */
 static int lod_object_start(const struct lu_env *env, struct lu_object *o)
 {
-       if (S_ISLNK(o->lo_header->loh_attr & S_IFMT))
+       if (S_ISLNK(o->lo_header->loh_attr & S_IFMT)) {
                lu2lod_obj(o)->ldo_obj.do_body_ops = &lod_body_lnk_ops;
+       } else if (S_ISREG(o->lo_header->loh_attr & S_IFMT) ||
+                  fid_is_local_file(lu_object_fid(o))) {
+               /* Note: some local file (like last rcvd) is created
+                * through bottom layer (OSD), so the object initialization
+                * comes to lod, it does not set loh_attr yet, so
+                * set do_body_ops for local file anyway */
+               lu2lod_obj(o)->ldo_obj.do_body_ops = &lod_body_ops;
+       }
        return 0;
 }