Whamcloud - gitweb
LU-7446 clio: lov_io_init() should return error code 40/17240/4
authorBobi Jam <bobijam.xu@intel.com>
Fri, 13 Nov 2015 10:48:53 +0000 (18:48 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 10 Dec 2015 17:47:43 +0000 (17:47 +0000)
lov_io_init_empty/release() should returns error code instead of
true on error case.

Fault IO need handle restart in the case of accessing HSM released
file.

Add a test case.

Signed-off-by: Bobi Jam <bobijam.xu@intel.com>
Change-Id: I4953c12c1e9b82a16aed9b8b1e3fe6e38d783b24
Reviewed-on: http://review.whamcloud.com/17240
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/llite/llite_mmap.c
lustre/lov/lov_io.c
lustre/obdclass/cl_io.c
lustre/tests/Makefile.am
lustre/tests/mmap_cat.c [new file with mode: 0644]
lustre/tests/sanity-hsm.sh

index fa3ae01..052ff98 100644 (file)
@@ -127,6 +127,7 @@ ll_fault_io_init(struct vm_area_struct *vma, struct lu_env **env_ret,
 
         *env_ret = env;
 
 
         *env_ret = env;
 
+restart:
        io = vvp_env_thread_io(env);
         io->ci_obj = ll_i2info(inode)->lli_clob;
         LASSERT(io->ci_obj != NULL);
        io = vvp_env_thread_io(env);
         io->ci_obj = ll_i2info(inode)->lli_clob;
         LASSERT(io->ci_obj != NULL);
@@ -162,11 +163,14 @@ ll_fault_io_init(struct vm_area_struct *vma, struct lu_env **env_ret,
        } else {
                LASSERT(rc < 0);
                cl_io_fini(env, io);
        } else {
                LASSERT(rc < 0);
                cl_io_fini(env, io);
+               if (io->ci_need_restart)
+                       goto restart;
+
                cl_env_nested_put(nest, env);
                io = ERR_PTR(rc);
        }
 
                cl_env_nested_put(nest, env);
                io = ERR_PTR(rc);
        }
 
-       return io;
+       RETURN(io);
 }
 
 /* Sharing code of page_mkwrite method for rhel5 and rhel6 */
 }
 
 /* Sharing code of page_mkwrite method for rhel5 and rhel6 */
index 058dc86..4d5b777 100644 (file)
@@ -1070,7 +1070,7 @@ int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
        }
 
        io->ci_result = result < 0 ? result : 0;
        }
 
        io->ci_result = result < 0 ? result : 0;
-       RETURN(result != 0);
+       RETURN(result);
 }
 
 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
 }
 
 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
@@ -1117,6 +1117,6 @@ int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
        }
 
        io->ci_result = result < 0 ? result : 0;
        }
 
        io->ci_result = result < 0 ? result : 0;
-       RETURN(result != 0);
+       RETURN(result);
 }
 /** @} lov */
 }
 /** @} lov */
index 870e506..e2c1a4e 100644 (file)
@@ -132,8 +132,8 @@ void cl_io_fini(const struct lu_env *env, struct cl_io *io)
        case CIT_READ:
        case CIT_WRITE:
        case CIT_DATA_VERSION:
        case CIT_READ:
        case CIT_WRITE:
        case CIT_DATA_VERSION:
-               break;
        case CIT_FAULT:
        case CIT_FAULT:
+               break;
        case CIT_FSYNC:
                LASSERT(!io->ci_need_restart);
                break;
        case CIT_FSYNC:
                LASSERT(!io->ci_need_restart);
                break;
index f9aab93..077c681 100644 (file)
@@ -77,7 +77,7 @@ noinst_PROGRAMS += mmap_sanity writemany reads flocks_test flock_deadlock
 noinst_PROGRAMS += write_time_limit rwv lgetxattr_size_check checkfiemap
 noinst_PROGRAMS += listxattr_size_check check_fhandle_syscalls badarea_io
 noinst_PROGRAMS += llapi_layout_test orphan_linkea_check llapi_hsm_test
 noinst_PROGRAMS += write_time_limit rwv lgetxattr_size_check checkfiemap
 noinst_PROGRAMS += listxattr_size_check check_fhandle_syscalls badarea_io
 noinst_PROGRAMS += llapi_layout_test orphan_linkea_check llapi_hsm_test
-noinst_PROGRAMS += group_lock_test llapi_fid_test sendfile_grouplock
+noinst_PROGRAMS += group_lock_test llapi_fid_test sendfile_grouplock mmap_cat
 
 bin_PROGRAMS = mcreate munlink
 testdir = $(libdir)/lustre/tests
 
 bin_PROGRAMS = mcreate munlink
 testdir = $(libdir)/lustre/tests
diff --git a/lustre/tests/mmap_cat.c b/lustre/tests/mmap_cat.c
new file mode 100644 (file)
index 0000000..e5aab49
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2015 Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+int save_errno;
+
+char usage[] =
+"Usage: %s <file>\n"
+"       mmap <file> and cat its content\n";
+
+size_t getFilesize(const char *filename)
+{
+       struct stat st;
+
+       if (stat(filename, &st) == -1) {
+               save_errno = errno;
+               perror("stat");
+               exit(save_errno);
+       }
+       return st.st_size;
+}
+
+int main(int argc, char **argv)
+{
+       size_t filesize;
+       int fd;
+       void *mmappedData;
+       int rc;
+
+       if (argc != 2) {
+               fprintf(stderr, usage, argv[0]);
+               exit(1);
+       }
+
+       filesize = getFilesize(argv[1]);
+
+       /* Open file */
+       fd = open(argv[1], O_RDONLY, 0);
+       if (fd == -1) {
+               save_errno = errno;
+               perror("open");
+               exit(save_errno);
+       }
+
+       /* Execute mmap */
+       mmappedData = mmap(NULL, filesize, PROT_READ,
+                          MAP_PRIVATE | MAP_POPULATE, fd, 0);
+       if (mmappedData == MAP_FAILED) {
+               save_errno = errno;
+               perror("mmap");
+               exit(save_errno);
+       }
+
+       /* Write the mmapped data to stdout (= FD #1) */
+       rc = write(1, mmappedData, filesize);
+       if (rc == -1) {
+               save_errno = errno;
+               perror("write");
+               exit(save_errno);
+       }
+
+       rc = munmap(mmappedData, filesize);
+       if (rc == -1) {
+               save_errno = errno;
+               perror("munmap");
+               exit(save_errno);
+       }
+
+       rc = close(fd);
+       if (rc == -1) {
+               save_errno = errno;
+               perror("close");
+               exit(save_errno);
+       }
+
+       return 0;
+}
+
index 183a4d4..e6a4534 100755 (executable)
@@ -24,6 +24,7 @@ init_logging
 
 MULTIOP=${MULTIOP:-multiop}
 OPENFILE=${OPENFILE:-openfile}
 
 MULTIOP=${MULTIOP:-multiop}
 OPENFILE=${OPENFILE:-openfile}
+MMAP_CAT=${MMAP_CAT:-mmap_cat}
 MOUNT_2=${MOUNT_2:-"yes"}
 FAIL_ON_ERROR=false
 
 MOUNT_2=${MOUNT_2:-"yes"}
 FAIL_ON_ERROR=false
 
@@ -846,6 +847,23 @@ test_1() {
 }
 run_test 1 "lfs hsm flags root/non-root access"
 
 }
 run_test 1 "lfs hsm flags root/non-root access"
 
+test_1a() {
+       mkdir -p $DIR/$tdir
+       local f=$DIR/$tdir/$tfile
+       local fid=$(make_small $f)
+
+       $LFS hsm_archive $f || error "could not archive file"
+       wait_request_state $fid ARCHIVE SUCCEED
+
+       # Release and check states
+       $LFS hsm_release $f || error "could not release file"
+       echo -n "Verifying released state: "
+       check_hsm_flags $f "0x0000000d"
+
+       $MMAP_CAT $f > /dev/null || error "failed mmap & cat release file"
+}
+run_test 1a "mmap & cat a HSM released file"
+
 test_2() {
        mkdir -p $DIR/$tdir
        local f=$DIR/$tdir/$tfile
 test_2() {
        mkdir -p $DIR/$tdir
        local f=$DIR/$tdir/$tfile