Whamcloud - gitweb
b=11673
[fs/lustre-release.git] / lustre / liblustre / super.c
index 60c109b..00621f1 100644 (file)
 # include <sys/statfs.h>
 #endif
 
+#include <sysio.h>
 #ifdef HAVE_XTIO_H
 #include <xtio.h>
 #endif
-#include <sysio.h>
 #include <fs.h>
 #include <mount.h>
 #include <inode.h>
@@ -594,7 +594,8 @@ static int inode_setattr(struct inode * inode, struct iattr * attr)
         return error;
 }
 
-int llu_md_setattr(struct inode *inode, struct md_op_data *op_data)
+int llu_md_setattr(struct inode *inode, struct md_op_data *op_data,
+                   struct md_open_data **mod)
 {
         struct lustre_md md;
         struct llu_sb_info *sbi = llu_i2sbi(inode);
@@ -603,7 +604,8 @@ int llu_md_setattr(struct inode *inode, struct md_op_data *op_data)
         ENTRY;
 
         llu_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0, LUSTRE_OPC_ANY);
-        rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0, &request);
+        rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL,
+                        0, &request, mod);
 
         if (rc) {
                 ptlrpc_req_finished(request);
@@ -633,7 +635,8 @@ int llu_md_setattr(struct inode *inode, struct md_op_data *op_data)
 
 /* Close IO epoch and send Size-on-MDS attribute update. */
 static int llu_setattr_done_writing(struct inode *inode,
-                                    struct md_op_data *op_data)
+                                    struct md_op_data *op_data,
+                                    struct md_open_data *mod)
 {
         struct llu_inode_info *lli = llu_i2info(inode);
         struct intnl_stat *st = llu_i2stat(inode);
@@ -649,11 +652,11 @@ static int llu_setattr_done_writing(struct inode *inode,
                op_data->op_ioepoch, PFID(&lli->lli_fid));
 
         op_data->op_flags = MF_EPOCH_CLOSE | MF_SOM_CHANGE;
-        rc = md_done_writing(llu_i2sbi(inode)->ll_md_exp, op_data, NULL);
+        rc = md_done_writing(llu_i2sbi(inode)->ll_md_exp, op_data, mod);
         if (rc == -EAGAIN) {
                 /* MDS has instructed us to obtain Size-on-MDS attribute
                  * from OSTs and send setattr to back to MDS. */
-                rc = llu_sizeonmds_update(inode, &op_data->op_handle,
+                rc = llu_sizeonmds_update(inode, mod, &op_data->op_handle,
                                           op_data->op_ioepoch);
         } else if (rc) {
                 CERROR("inode %llu mdc truncate failed: rc = %d\n",
@@ -682,7 +685,8 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr)
         struct intnl_stat *st = llu_i2stat(inode);
         int ia_valid = attr->ia_valid;
         struct md_op_data op_data = { { 0 } };
-        int rc = 0;
+        struct md_open_data *mod = NULL;
+        int rc = 0, rc1 = 0;
         ENTRY;
 
         CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu\n", (long long)st->st_ino);
@@ -741,15 +745,18 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr)
                 /* Open epoch for truncate. */
                 if (ia_valid & ATTR_SIZE)
                         op_data.op_flags = MF_EPOCH_OPEN;
-                rc = llu_md_setattr(inode, &op_data);
+                rc = llu_md_setattr(inode, &op_data, &mod);
                 if (rc)
                         RETURN(rc);
 
+                if (op_data.op_ioepoch)
+                        CDEBUG(D_INODE, "Epoch "LPU64" opened on "DFID" for "
+                               "truncate\n", op_data.op_ioepoch,
+                               PFID(&llu_i2info(inode)->lli_fid));
+
                 if (!lsm || !S_ISREG(st->st_mode)) {
                         CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
-                        if (op_data.op_ioepoch)
-                                rc = llu_setattr_done_writing(inode, &op_data);
-                        RETURN(rc);
+                        GOTO(out, rc);
                 }
         } else {
                 /* The OST doesn't check permissions, but the alternative is
@@ -810,10 +817,9 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr)
                                      &lockh, flags);
                 if (rc != ELDLM_OK) {
                         if (rc > 0)
-                                RETURN(-ENOLCK);
-                        RETURN(rc);
+                                GOTO(out, rc = -ENOLCK);
+                        GOTO(out, rc);
                 }
-
                 rc = llu_vmtruncate(inode, attr->ia_size, obd_flags);
 
                 /* unlock now as we don't mind others file lockers racing with
@@ -824,9 +830,6 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr)
                         if (!rc)
                                 rc = err;
                 }
-
-                if (op_data.op_ioepoch)
-                        rc = llu_setattr_done_writing(inode, &op_data);
         } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
                 struct obd_info oinfo = { { { 0 } } };
                 struct obdo oa;
@@ -846,7 +849,11 @@ int llu_setattr_raw(struct inode *inode, struct iattr *attr)
                 if (rc)
                         CERROR("obd_setattr_async fails: rc=%d\n", rc);
         }
-        RETURN(rc);
+        EXIT;
+out:
+        if (op_data.op_ioepoch)
+                rc1 = llu_setattr_done_writing(inode, &op_data, mod);
+        return rc ? rc : rc1;
 }
 
 /* here we simply act as a thin layer to glue it with
@@ -1338,9 +1345,11 @@ static int llu_file_flock(struct inode *ino,
                            fid_oid(&lli->lli_fid),
                            fid_ver(&lli->lli_fid),
                            LDLM_FLOCK} };
+        struct ldlm_enqueue_info einfo = { LDLM_FLOCK, 0, NULL,
+                ldlm_flock_completion_ast, NULL, file_lock };
+
         struct lustre_handle lockh = {0};
         ldlm_policy_data_t flock;
-        ldlm_mode_t mode = 0;
         int flags = 0;
         int rc;
 
@@ -1353,13 +1362,13 @@ static int llu_file_flock(struct inode *ino,
 
         switch (file_lock->fl_type) {
         case F_RDLCK:
-                mode = LCK_PR;
+                einfo.ei_mode = LCK_PR;
                 break;
         case F_UNLCK:
-                mode = LCK_NL;
+                einfo.ei_mode = LCK_NL;
                 break;
         case F_WRLCK:
-                mode = LCK_PW;
+                einfo.ei_mode = LCK_PW;
                 break;
         default:
                 CERROR("unknown fcntl lock type: %d\n", file_lock->fl_type);
@@ -1390,7 +1399,7 @@ static int llu_file_flock(struct inode *ino,
 #endif
 #endif
                 flags = LDLM_FL_TEST_LOCK;
-                file_lock->fl_type = mode;
+                file_lock->fl_type = einfo.ei_mode;
                 break;
         default:
                 CERROR("unknown fcntl cmd: %d\n", cmd);
@@ -1399,13 +1408,11 @@ static int llu_file_flock(struct inode *ino,
 
         CDEBUG(D_DLMTRACE, "inode=%llu, pid=%u, flags=%#x, mode=%u, "
                "start="LPU64", end="LPU64"\n", (unsigned long long)st->st_ino,
-               flock.l_flock.pid, flags, mode, flock.l_flock.start,
+               flock.l_flock.pid, flags, einfo.ei_mode, flock.l_flock.start,
                flock.l_flock.end);
 
-        rc = ldlm_cli_enqueue(llu_i2mdcexp(ino), NULL, &res_id,
-                              LDLM_FLOCK, &flock, mode, &flags, NULL,
-                              ldlm_flock_completion_ast, NULL,
-                              file_lock, NULL, 0, NULL, &lockh, 0);
+        rc = ldlm_cli_enqueue(llu_i2mdcexp(ino), NULL, &einfo, &res_id, 
+                              &flock, &flags, NULL, 0, NULL, &lockh, 0);
         RETURN(rc);
 }
 
@@ -1671,7 +1678,7 @@ static int llu_lov_dir_setstripe(struct inode *ino, unsigned long arg)
 
         /* swabbing is done in lov_setstripe() on server side */
         rc = md_setattr(sbi->ll_md_exp, &op_data, &lum,
-                        sizeof(lum), NULL, 0, &request);
+                        sizeof(lum), NULL, 0, &request, NULL);
         if (rc) {
                 ptlrpc_req_finished(request);
                 if (rc != -EPERM && rc != -EACCES)
@@ -1691,6 +1698,9 @@ static int llu_lov_setstripe_ea_info(struct inode *ino, int flags,
         struct llu_inode_info *lli2 = NULL;
         struct lov_stripe_md *lsm;
         struct lookup_intent oit = {.it_op = IT_OPEN, .it_flags = flags};
+        struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_CR,
+                llu_md_blocking_ast, ldlm_completion_ast, NULL, NULL };
+
         struct ptlrpc_request *req = NULL;
         struct lustre_md md;
         struct md_op_data data;
@@ -1720,9 +1730,8 @@ static int llu_lov_setstripe_ea_info(struct inode *ino, int flags,
         llu_prep_md_op_data(&data, NULL, ino, NULL, 0, O_RDWR, 
                             LUSTRE_OPC_ANY);
 
-        rc = md_enqueue(sbi->ll_md_exp, LDLM_IBITS, &oit, LCK_CR, &data,
-                        &lockh, lum, lum_size, ldlm_completion_ast,
-                        llu_md_blocking_ast, NULL, LDLM_FL_INTENT_ONLY);
+        rc = md_enqueue(sbi->ll_md_exp, &einfo, &oit, &data,
+                        &lockh, lum, lum_size, LDLM_FL_INTENT_ONLY);
         if (rc)
                 GOTO(out, rc);