Whamcloud - gitweb
LU-10344 test: create files on local node in sanity-hsm
[fs/lustre-release.git] / lustre / tests / swap_lock_test.c
index fed55e7..91dee2e 100644 (file)
@@ -43,7 +43,6 @@
 #include <time.h>
 
 #include <lustre/lustreapi.h>
-#include <lustre/lustre_idl.h>
 
 #define ERROR(fmt, ...)                                                        \
        fprintf(stderr, "%s: %s:%d: %s: " fmt "\n",                     \
@@ -437,11 +436,8 @@ static void test15(void)
        ASSERTF(rc == 0,
                "invalid lease type on '%s': %s", filename, strerror(-rc));
 
-#if 0
-       /* BUG! This returns EBUSY but there's no lease. */
        rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
        ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
-#endif
 
        close(fd);
 
@@ -464,11 +460,8 @@ static void test15(void)
        ASSERTF(rc == 0,
                "invalid lease type on '%s': %s", filename, strerror(-rc));
 
-#if 0
-       /* BUG! This returns EBUSY but there's no lease. */
        rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
        ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
-#endif
 
        close(fd);
 
@@ -477,8 +470,6 @@ static void test15(void)
        ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
 
        for (i = 0; i < 1000; i++) {
-#if 0
-               /* BUG! Same as above */
                rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
                ASSERTF(rc == 0, "cannot get lease '%s': %s",
                        filename, strerror(-rc));
@@ -496,11 +487,58 @@ static void test15(void)
                ASSERTF(rc == LL_LEASE_RDLCK,
                        "was not able to put back lease '%s': %s",
                        filename, strerror(-rc));
-#endif
        }
 
        close(fd);
 
+       /* Get a write lease, release and take a read one */
+       fd = open(filename, O_RDWR);
+       ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
+
+       rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+       ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_check(fd);
+       ASSERTF(rc == LL_LEASE_WRLCK,
+               "invalid lease type on '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_put(fd);
+       ASSERTF(rc == LL_LEASE_WRLCK, "was not able to put back lease '%s': %s",
+               filename, strerror(-rc));
+
+       rc = llapi_lease_check(fd);
+       ASSERTF(rc == 0,
+               "invalid lease type on '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+       ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
+
+       close(fd);
+
+       /* Get a read lease, release and take a write one */
+       fd = open(filename, O_RDWR);
+       ASSERTF(fd >= 0, "open failed for '%s': %s", filename, strerror(errno));
+
+       rc = llapi_lease_get(fd, LL_LEASE_RDLCK);
+       ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_check(fd);
+       ASSERTF(rc == LL_LEASE_RDLCK,
+               "invalid lease type on '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_put(fd);
+       ASSERTF(rc == LL_LEASE_RDLCK, "was not able to put back lease '%s': %s",
+               filename, strerror(-rc));
+
+       rc = llapi_lease_check(fd);
+       ASSERTF(rc == 0,
+               "invalid lease type on '%s': %s", filename, strerror(-rc));
+
+       rc = llapi_lease_get(fd, LL_LEASE_WRLCK);
+       ASSERTF(rc == 0, "cannot get lease '%s': %s", filename, strerror(-rc));
+
+       close(fd);
+
        free(filename);
 }
 
@@ -510,7 +548,7 @@ static void test16(void)
        int rc;
        char *filename;
        int fd;
-       lustre_fid fid;
+       struct lu_fid fid;
 
        rc = mkdir(mainpath, 0);
        ASSERTF(rc == 0, "mkdir failed for '%s': %s",