Whamcloud - gitweb
b=22168 Ignore EINTR returned from write
[fs/lustre-release.git] / lustre / lclient / lcommon_cl.c
index a8322e1..21a52e7 100644 (file)
@@ -26,7 +26,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
 #include <sys/stat.h>
 #include <sys/queue.h>
 #include <fcntl.h>
-# include <sysio.h>
-# ifdef HAVE_XTIO_H
-#  include <xtio.h>
-# endif
-# include <fs.h>
-# include <mount.h>
-# include <inode.h>
-# ifdef HAVE_FILE_H
-#  include <file.h>
-# endif
 # include <liblustre.h>
 #endif
 
@@ -962,11 +952,13 @@ void ccc_req_completion(const struct lu_env *env,
  *
  *    - o_mode
  *
- *    - o_fid (filled with inode number?!)
+ *    - o_parent_seq
  *
  *    - o_[ug]id
  *
- *    - o_generation
+ *    - o_parent_oid
+ *
+ *    - o_parent_ver
  *
  *    - o_ioepoch,
  *
@@ -998,11 +990,11 @@ void ccc_req_attr_set(const struct lu_env *env,
                         oa->o_valid |= OBD_MD_FLEPOCH;
                         oa->o_ioepoch = cl_i2info(inode)->lli_ioepoch;
                         valid_flags |= OBD_MD_FLMTIME|OBD_MD_FLCTIME|
-                                OBD_MD_FLUID|OBD_MD_FLGID|
-                                OBD_MD_FLFID|OBD_MD_FLGENER;
+                                OBD_MD_FLUID|OBD_MD_FLGID;
                 }
         }
-        obdo_from_inode(oa, inode, valid_flags & flags);
+        obdo_from_inode(oa, inode, &cl_i2info(inode)->lli_fid,
+                        valid_flags & flags);
 }
 
 const struct cl_req_operations ccc_req_ops = {
@@ -1010,9 +1002,8 @@ const struct cl_req_operations ccc_req_ops = {
         .cro_completion = ccc_req_completion
 };
 
-/* Setattr helpers */
-int cl_setattr_do_truncate(struct inode *inode, loff_t size,
-                           struct obd_capa *capa)
+int cl_setattr_ost(struct inode *inode, const struct iattr *attr,
+                   struct obd_capa *capa)
 {
         struct lu_env *env;
         struct cl_io  *io;
@@ -1027,9 +1018,15 @@ int cl_setattr_do_truncate(struct inode *inode, loff_t size,
 
         io = &ccc_env_info(env)->cti_io;
         io->ci_obj = cl_i2info(inode)->lli_clob;
-        io->u.ci_truncate.tr_size = size;
-        io->u.ci_truncate.tr_capa = capa;
-        if (cl_io_init(env, io, CIT_TRUNC, io->ci_obj) == 0)
+
+        io->u.ci_setattr.sa_attr.lvb_atime = LTIME_S(attr->ia_atime);
+        io->u.ci_setattr.sa_attr.lvb_mtime = LTIME_S(attr->ia_mtime);
+        io->u.ci_setattr.sa_attr.lvb_ctime = LTIME_S(attr->ia_ctime);
+        io->u.ci_setattr.sa_attr.lvb_size = attr->ia_size;
+        io->u.ci_setattr.sa_valid = attr->ia_valid;
+        io->u.ci_setattr.sa_capa = capa;
+
+        if (cl_io_init(env, io, CIT_SETATTR, io->ci_obj) == 0)
                 result = cl_io_loop(env, io);
         else
                 result = io->ci_result;
@@ -1038,45 +1035,6 @@ int cl_setattr_do_truncate(struct inode *inode, loff_t size,
         RETURN(result);
 }
 
-int cl_setattr_ost(struct inode *inode, struct obd_capa *capa)
-{
-        struct cl_inode_info *lli = cl_i2info(inode);
-        struct lov_stripe_md *lsm = lli->lli_smd;
-        int rc;
-        obd_flag flags;
-        struct obd_info oinfo = { { { 0 } } };
-        struct obdo *oa;
-
-        OBDO_ALLOC(oa);
-        if (oa) {
-                oa->o_id = lsm->lsm_object_id;
-                oa->o_gr = lsm->lsm_object_gr;
-                oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
-
-                flags = OBD_MD_FLTYPE | OBD_MD_FLATIME |
-                        OBD_MD_FLMTIME | OBD_MD_FLCTIME |
-                        OBD_MD_FLFID | OBD_MD_FLGENER |
-                        OBD_MD_FLGROUP;
-
-                obdo_from_inode(oa, inode, flags);
-
-                oinfo.oi_oa = oa;
-                oinfo.oi_md = lsm;
-                oinfo.oi_capa = capa;
-
-                /* XXX: this looks unnecessary now. */
-                rc = obd_setattr_rqset(cl_i2sbi(inode)->ll_dt_exp, &oinfo,
-                                       NULL);
-                if (rc)
-                        CERROR("obd_setattr_async fails: rc=%d\n", rc);
-                OBDO_FREE(oa);
-        } else {
-                rc = -ENOMEM;
-        }
-        return rc;
-}
-
-
 /*****************************************************************************
  *
  * Type conversions.
@@ -1231,6 +1189,41 @@ int cl_inode_init(struct inode *inode, struct lustre_md *md)
         return result;
 }
 
+/**
+ * Wait for others drop their references of the object at first, then we drop
+ * the last one, which will lead to the object be destroyed immediately.
+ * Must be called after cl_object_kill() against this object.
+ *
+ * The reason we want to do this is: destroying top object will wait for sub
+ * objects being destroyed first, so we can't let bottom layer (e.g. from ASTs)
+ * to initiate top object destroying which may deadlock. See bz22520.
+ */
+static void cl_object_put_last(struct lu_env *env, struct cl_object *obj)
+{
+        struct lu_object_header *header = obj->co_lu.lo_header;
+        struct lu_site          *site;
+        cfs_waitlink_t           waiter;
+
+        if (unlikely(cfs_atomic_read(&header->loh_ref) != 1)) {
+                site = obj->co_lu.lo_dev->ld_site;
+
+                cfs_waitlink_init(&waiter);
+                cfs_waitq_add(&site->ls_marche_funebre, &waiter);
+
+                while (1) {
+                        cfs_set_current_state(CFS_TASK_UNINT);
+                        if (cfs_atomic_read(&header->loh_ref) == 1)
+                                break;
+                        cfs_waitq_wait(&waiter, CFS_TASK_UNINT);
+                }
+
+                cfs_set_current_state(CFS_TASK_RUNNING);
+                cfs_waitq_del(&site->ls_marche_funebre, &waiter);
+        }
+
+        cl_object_put(env, obj);
+}
+
 void cl_inode_fini(struct inode *inode)
 {
         struct lu_env           *env;
@@ -1258,7 +1251,7 @@ void cl_inode_fini(struct inode *inode)
                  */
                 cl_object_kill(env, clob);
                 lu_object_ref_del(&clob->co_lu, "inode", inode);
-                cl_object_put(env, clob);
+                cl_object_put_last(env, clob);
                 lli->lli_clob = NULL;
                 if (emergency) {
                         cl_env_unplant(ccc_inode_fini_env, &refcheck);