Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / liblustre / file.c
index 4069827..1d73aeb 100644 (file)
@@ -71,32 +71,37 @@ void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
         }
 }
 
-void llu_prepare_mdc_op_data(struct mdc_op_data *data,
-                             struct inode *i1,
-                             struct inode *i2,
-                             const char *name,
-                             int namelen,
-                             int mode)
+void llu_prep_md_op_data(struct md_op_data *op_data, struct inode *i1,
+                         struct inode *i2, const char *name, int namelen,
+                         int mode, __u32 opc)
 {
         LASSERT(i1 != NULL || i2 != NULL);
+        LASSERT(op_data);
+        memset(op_data, 0, sizeof(*op_data));
 
         if (i1) {
-                ll_i2gids(data->suppgids, i1, i2);
-                ll_inode2fid(&data->fid1, i1);
+                ll_i2gids(op_data->op_suppgids, i1, i2);
+                op_data->op_fid1 = *ll_inode2fid(i1);
         }else {
-                ll_i2gids(data->suppgids, i2, i1);
-                ll_inode2fid(&data->fid1, i2);
+                ll_i2gids(op_data->op_suppgids, i2, i1);
+                op_data->op_fid1 = *ll_inode2fid(i2);
         }
 
         if (i2)
-                ll_inode2fid(&data->fid2, i2);
+                op_data->op_fid2 = *ll_inode2fid(i2);
         else
-                memset(&data->fid2, 0, sizeof(data->fid2));
+                fid_zero(&op_data->op_fid2);
 
-        data->name = name;
-        data->namelen = namelen;
-        data->create_mode = mode;
-        data->mod_time = CURRENT_TIME;
+        op_data->op_opc = opc;
+        op_data->op_name = name;
+        op_data->op_mode = mode;
+        op_data->op_namelen = namelen;
+        op_data->op_mod_time = CURRENT_TIME;
+}
+
+void llu_finish_md_op_data(struct md_op_data *op_data)
+{
+        OBD_FREE_PTR(op_data);
 }
 
 void obdo_refresh_inode(struct inode *dst,
@@ -138,7 +143,7 @@ int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it)
 {
         struct ptlrpc_request *req = it->d.lustre.it_data;
         struct ll_file_data *fd;
-        struct mds_body *body;
+        struct mdt_body *body;
         ENTRY;
 
         body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
@@ -153,14 +158,16 @@ int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it)
 
         OBD_ALLOC(fd, sizeof(*fd));
         /* We can't handle this well without reorganizing ll_file_open and
-         * ll_mdc_close, so don't even try right now. */
+         * ll_md_close, so don't even try right now. */
         LASSERT(fd != NULL);
 
         memcpy(&fd->fd_mds_och.och_fh, &body->handle, sizeof(body->handle));
         fd->fd_mds_och.och_magic = OBD_CLIENT_HANDLE_MAGIC;
+        fd->fd_mds_och.och_fid   = lli->lli_fid;
         lli->lli_file_data = fd;
 
-        mdc_set_open_replay_data(&fd->fd_mds_och, it->d.lustre.it_data);
+        md_set_open_replay_data(lli->lli_sbi->ll_md_exp,
+                                &fd->fd_mds_och, it->d.lustre.it_data);
 
         RETURN(0);
 }
@@ -240,7 +247,7 @@ int llu_iop_open(struct pnode *pnode, int flags, mode_t mode)
 
 int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
 {
-        struct mds_body *body;
+        struct mdt_body *body;
         struct lov_mds_md *eadata;
         struct lov_stripe_md *lsm = NULL;
         struct obd_trans_info oti = { 0 };
@@ -278,13 +285,14 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
         }
         LASSERT(rc >= sizeof(*lsm));
 
-        oa = obdo_alloc();
+        OBDO_ALLOC(oa);
         if (oa == NULL)
                 GOTO(out_free_memmd, rc = -ENOMEM);
 
         oa->o_id = lsm->lsm_object_id;
+        oa->o_gr = lsm->lsm_object_gr;
         oa->o_mode = body->mode & S_IFMT;
-        oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE;
+        oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
 
         if (body->valid & OBD_MD_FLCOOKIE) {
                 oa->o_valid |= OBD_MD_FLCOOKIE;
@@ -299,7 +307,7 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
         }
 
         rc = obd_destroy(llu_i2obdexp(dir), oa, lsm, &oti, NULL);
-        obdo_free(oa);
+        OBDO_FREE(oa);
         if (rc)
                 CERROR("obd destroy objid 0x"LPX64" error %d\n",
                        lsm->lsm_object_id, rc);
@@ -309,15 +317,46 @@ int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
         return rc;
 }
 
-int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode)
+int llu_sizeonmds_update(struct inode *inode, struct lustre_handle *fh,
+                         __u64 ioepoch)
+{
+        struct llu_inode_info *lli = llu_i2info(inode);
+        struct llu_sb_info *sbi = llu_i2sbi(inode);
+        struct md_op_data op_data;
+        struct obdo oa;
+        int rc;
+        ENTRY;
+        
+        LASSERT(!(lli->lli_flags & LLIF_MDS_SIZE_LOCK));
+        LASSERT(sbi->ll_lco.lco_flags & OBD_CONNECT_SOM);
+        
+        rc = llu_inode_getattr(inode, &oa);
+        if (rc) {
+                CERROR("inode_getattr failed (%d): unable to send a "
+                       "Size-on-MDS attribute update for inode %llu/%lu\n",
+                       rc, (long long)llu_i2stat(inode)->st_ino,
+                       lli->lli_st_generation);
+                RETURN(rc);
+        }
+        
+        md_from_obdo(&op_data, &oa, oa.o_valid);
+        memcpy(&op_data.op_handle, fh, sizeof(*fh));
+        op_data.op_ioepoch = ioepoch;
+        op_data.op_flags |= MF_SOM_CHANGE;
+
+        rc = llu_md_setattr(inode, &op_data);
+        RETURN(rc);
+}
+
+int llu_md_close(struct obd_export *md_exp, struct inode *inode)
 {
         struct llu_inode_info *lli = llu_i2info(inode);
-        struct intnl_stat *st = llu_i2stat(inode);
         struct ll_file_data *fd = lli->lli_file_data;
         struct ptlrpc_request *req = NULL;
         struct obd_client_handle *och = &fd->fd_mds_och;
-        struct obdo obdo;
-        int rc, valid;
+        struct intnl_stat *st = llu_i2stat(inode);
+        struct md_op_data op_data = { { 0 } };
+        int rc;
         ENTRY;
 
         /* clear group lock, if present */
@@ -328,25 +367,51 @@ int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode)
                                        &fd->fd_cwlockh);
         }
 
-        obdo.o_id = st->st_ino;
-        obdo.o_valid = OBD_MD_FLID;
-        valid = OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLSIZE |OBD_MD_FLBLOCKS |
-                OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME;
-        if (test_bit(LLI_F_HAVE_OST_SIZE_LOCK, &lli->lli_flags))
-                valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
-
-        obdo_from_inode(&obdo, inode, valid);
-
-        if (0 /* ll_is_inode_dirty(inode) */) {
-                obdo.o_flags = MDS_BFLAG_UNCOMMITTED_WRITES;
-                obdo.o_valid |= OBD_MD_FLFLAGS;
+        op_data.op_attr.ia_valid = ATTR_MODE | ATTR_ATIME_SET |
+                                ATTR_MTIME_SET | ATTR_CTIME_SET;
+        
+        if (fd->fd_flags & FMODE_WRITE) {
+                struct llu_sb_info *sbi = llu_i2sbi(inode);
+                if (!(sbi->ll_lco.lco_flags & OBD_CONNECT_SOM) ||
+                    !S_ISREG(llu_i2stat(inode)->st_mode)) {
+                        op_data.op_attr.ia_valid |= ATTR_SIZE | ATTR_BLOCKS;
+                } else {
+                        /* Inode cannot be dirty. Close the epoch. */
+                        op_data.op_flags |= MF_EPOCH_CLOSE;
+                        /* XXX: Send CHANGE flag only if Size-on-MDS inode attributes
+                         * are really changed.  */
+                        op_data.op_flags |= MF_SOM_CHANGE;
+
+                        /* Pack Size-on-MDS attributes if we are in IO epoch and 
+                         * attributes are valid. */
+                        LASSERT(!(lli->lli_flags & LLIF_MDS_SIZE_LOCK));
+                        if (!llu_local_size(inode))
+                                op_data.op_attr.ia_valid |= 
+                                        OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
+                }
         }
-        rc = mdc_close(mdc_exp, &obdo, och, &req);
-        if (rc == EAGAIN) {
+        op_data.op_fid1 = lli->lli_fid;
+        op_data.op_attr.ia_atime = st->st_atime;
+        op_data.op_attr.ia_mtime = st->st_mtime;
+        op_data.op_attr.ia_ctime = st->st_ctime;
+        op_data.op_attr.ia_size = st->st_size;
+        op_data.op_attr_blocks = st->st_blocks;
+        op_data.op_attr.ia_attr_flags = lli->lli_st_flags;
+        op_data.op_ioepoch = lli->lli_ioepoch;
+        memcpy(&op_data.op_handle, &och->och_fh, sizeof(op_data.op_handle));
+
+        rc = md_close(md_exp, &op_data, och, &req);
+        if (rc == -EAGAIN) {
                 /* We are the last writer, so the MDS has instructed us to get
                  * the file size and any write cookies, then close again. */
-                //ll_queue_done_writing(inode);
-                rc = 0;
+                LASSERT(fd->fd_flags & FMODE_WRITE);
+                rc = llu_sizeonmds_update(inode, &och->och_fh,
+                                          op_data.op_ioepoch);
+                if (rc) {
+                        CERROR("inode %llu mdc Size-on-MDS update failed: "
+                               "rc = %d\n", (long long)st->st_ino, rc);
+                        rc = 0;
+                }
         } else if (rc) {
                 CERROR("inode %llu close failed: rc %d\n",
                        (long long)st->st_ino, rc);
@@ -357,7 +422,7 @@ int llu_mdc_close(struct obd_export *mdc_exp, struct inode *inode)
                                (long long)st->st_ino, rc);
         }
 
-        mdc_clear_open_replay_data(och);
+        md_clear_open_replay_data(md_exp, och);
         ptlrpc_req_finished(req);
         och->och_fh.cookie = DEAD_HANDLE_MAGIC;
         lli->lli_file_data = NULL;
@@ -388,7 +453,7 @@ int llu_file_release(struct inode *inode)
         if (!fd) /* no process opened the file after an mcreate */
                 RETURN(0);
 
-        rc2 = llu_mdc_close(sbi->ll_mdc_exp, inode);
+        rc2 = llu_md_close(sbi->ll_md_exp, inode);
         if (rc2 && !rc)
                 rc = rc2;