Whamcloud - gitweb
LU-9771 flr: lfs setstripe to create a new mirror
[fs/lustre-release.git] / lustre / llite / file.c
index f2a7f1d..701b647 100644 (file)
@@ -144,9 +144,10 @@ static int ll_close_inode_openhandle(struct inode *inode,
 
        ll_prepare_close(inode, op_data, och);
        switch (bias) {
+       case MDS_CLOSE_LAYOUT_MERGE:
        case MDS_CLOSE_LAYOUT_SWAP:
                LASSERT(data != NULL);
-               op_data->op_bias |= MDS_CLOSE_LAYOUT_SWAP;
+               op_data->op_bias |= bias;
                op_data->op_data_version = 0;
                op_data->op_lease_handle = och->och_lease_handle;
                op_data->op_fid2 = *ll_inode2fid(data);
@@ -170,8 +171,7 @@ static int ll_close_inode_openhandle(struct inode *inode,
                CERROR("%s: inode "DFID" mdc close failed: rc = %d\n",
                       md_exp->exp_obd->obd_name, PFID(&lli->lli_fid), rc);
 
-       if (rc == 0 &&
-           op_data->op_bias & (MDS_HSM_RELEASE | MDS_CLOSE_LAYOUT_SWAP)) {
+       if (rc == 0 && op_data->op_bias & bias) {
                struct mdt_body *body;
 
                body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
@@ -914,10 +914,12 @@ static int ll_check_swap_layouts_validity(struct inode *inode1,
 }
 
 static int ll_swap_layouts_close(struct obd_client_handle *och,
-                                struct inode *inode, struct inode *inode2)
+                                struct inode *inode, struct inode *inode2,
+                                int intent)
 {
        const struct lu_fid     *fid1 = ll_inode2fid(inode);
        const struct lu_fid     *fid2;
+       enum mds_op_bias         bias;
        int                      rc;
        ENTRY;
 
@@ -935,11 +937,21 @@ static int ll_swap_layouts_close(struct obd_client_handle *och,
        if (rc == 0)
                GOTO(out_free_och, rc = -EINVAL);
 
-       /* Close the file and swap layouts between inode & inode2.
+       switch (intent) {
+       case SWAP_LAYOUTS_CLOSE:
+               bias = MDS_CLOSE_LAYOUT_SWAP;
+               break;
+       case MERGE_LAYOUTS_CLOSE:
+               bias = MDS_CLOSE_LAYOUT_MERGE;
+               break;
+       default:
+               GOTO(out_free_och, rc = -EOPNOTSUPP);
+       }
+
+       /* Close the file and {swap,merge} layouts between inode & inode2.
         * NB: lease lock handle is released in mdc_close_layout_swap_pack()
         * because we still need it to pack l_remote_handle to MDT. */
-       rc = ll_close_inode_openhandle(inode, och, MDS_CLOSE_LAYOUT_SWAP,
-                                      inode2);
+       rc = ll_close_inode_openhandle(inode, och, bias, inode2);
 
        och = NULL; /* freed in ll_close_inode_openhandle() */
 
@@ -2783,6 +2795,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case LL_IOC_LOV_SWAP_LAYOUTS: {
                struct file *file2;
                struct lustre_swap_layouts lsl;
+               __u64 intent;
 
                if (copy_from_user(&lsl, (char __user *)arg,
                                   sizeof(struct lustre_swap_layouts)))
@@ -2799,14 +2812,12 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if ((file2->f_flags & O_ACCMODE) == O_RDONLY)
                        GOTO(out, rc = -EPERM);
 
-               if (lsl.sl_flags & SWAP_LAYOUTS_CLOSE) {
+               intent = lsl.sl_flags & INTENT_LAYOUTS_CLOSE;
+               if (intent) {
                        struct inode                    *inode2;
                        struct ll_inode_info            *lli;
                        struct obd_client_handle        *och = NULL;
 
-                       if (lsl.sl_flags != SWAP_LAYOUTS_CLOSE)
-                               GOTO(out, rc = -EINVAL);
-
                        lli = ll_i2info(inode);
                        mutex_lock(&lli->lli_och_mutex);
                        if (fd->fd_lease_och != NULL) {
@@ -2817,7 +2828,7 @@ ll_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                        if (och == NULL)
                                GOTO(out, rc = -ENOLCK);
                        inode2 = file_inode(file2);
-                       rc = ll_swap_layouts_close(och, inode, inode2);
+                       rc = ll_swap_layouts_close(och, inode, inode2, intent);
                } else {
                        rc = ll_swap_layouts(file, file2, &lsl);
                }