Whamcloud - gitweb
LU-3938 osd-zfs: Account for ZAP when shrinking an xattr
[fs/lustre-release.git] / lustre / lov / lov_io.c
index 76b0901..c163cfa 100644 (file)
@@ -197,6 +197,7 @@ static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
                 sub_io->ci_lockreq = io->ci_lockreq;
                 sub_io->ci_type    = io->ci_type;
                 sub_io->ci_no_srvlock = io->ci_no_srvlock;
+               sub_io->ci_noatime = io->ci_noatime;
 
                 lov_sub_enter(sub);
                 result = cl_io_sub_init(sub->sub_env, sub_io,
@@ -278,11 +279,12 @@ struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
                              struct cl_io *io)
 {
-       struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
+       struct lov_stripe_md *lsm;
        int result;
+       ENTRY;
 
-        LASSERT(lio->lis_object != NULL);
-        ENTRY;
+       LASSERT(lio->lis_object != NULL);
+       lsm = lio->lis_object->lo_lsm;
 
         /*
          * Need to be optimized, we can't afford to allocate a piece of memory
@@ -374,7 +376,7 @@ static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
 
        LASSERT(cfs_atomic_read(&lov->lo_active_ios) > 0);
        if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
-               cfs_waitq_broadcast(&lov->lo_waitq);
+               wake_up_all(&lov->lo_waitq);
        EXIT;
 }
 
@@ -846,7 +848,7 @@ static void lov_empty_io_fini(const struct lu_env *env,
         ENTRY;
 
        if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
-               cfs_waitq_broadcast(&lov->lo_waitq);
+               wake_up_all(&lov->lo_waitq);
         EXIT;
 }
 
@@ -968,4 +970,47 @@ int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
        RETURN(result != 0);
 }
 
+int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
+                       struct cl_io *io)
+{
+       struct lov_object *lov = cl2lov(obj);
+       struct lov_io *lio = lov_env_io(env);
+       int result;
+       ENTRY;
+
+       LASSERT(lov->lo_lsm != NULL);
+       lio->lis_object = lov;
+
+       switch (io->ci_type) {
+       default:
+               LASSERTF(0, "invalid type %d\n", io->ci_type);
+       case CIT_MISC:
+       case CIT_FSYNC:
+               result = 1;
+               break;
+       case CIT_SETATTR:
+               /* the truncate to 0 is managed by MDT:
+                * - in open, for open O_TRUNC
+                * - in setattr, for truncate
+                */
+               /* the truncate is for size > 0 so triggers a restore */
+               if (cl_io_is_trunc(io))
+                       io->ci_restore_needed = 1;
+               result = -ENODATA;
+               break;
+       case CIT_READ:
+       case CIT_WRITE:
+       case CIT_FAULT:
+               io->ci_restore_needed = 1;
+               result = -ENODATA;
+               break;
+       }
+       if (result == 0) {
+               cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
+               cfs_atomic_inc(&lov->lo_active_ios);
+       }
+
+       io->ci_result = result < 0 ? result : 0;
+       RETURN(result != 0);
+}
 /** @} lov */