static void rmdir_file(void) { int rv; if (create_testfile()<0) { return; } rv = rmdir(TESTFILE); report_test(rv, errno, ENOTDIR, "rmdir a file"); remove(TESTFILE); }
static void rmdir_file(void) { int rv; report_begin("rmdir a file"); if (create_testfile()<0) { report_aborted(); return; } rv = rmdir(TESTFILE); report_check(rv, errno, ENOTDIR); remove(TESTFILE); }
static void setup(void) { tst_require_root(NULL); tst_tmpdir(); TEST_PAUSE; has_file(drop_caches_fname, 1); has_file(meminfo_fname, 1); /* check if readahead is supported */ ltp_syscall(__NR_readahead, 0, 0, 0); pagesize = getpagesize(); create_testfile(); }
/* Test llapi_hsm_current_action */ void test52(void) { int rc; int fd; struct hsm_current_action hca; /* No fd equivalent, so close it. */ fd = create_testfile(100); close(fd); rc = llapi_hsm_current_action(testfile, &hca); ASSERTF(rc == 0, "llapi_hsm_current_action failed: %s", strerror(-rc)); ASSERTF(hca.hca_state, "hca_state=%u", hca.hca_state); ASSERTF(hca.hca_action, "hca_state=%u", hca.hca_action); rc = llapi_hsm_current_action(testfile, NULL); ASSERTF(rc == -EFAULT, "llapi_hsm_current_action failed: %s", strerror(-rc)); }
static void common_badpath(int (*func)(const char *path), int mk, int rm, const char *path, const char *call, const char *pathdesc) { char mydesc[128]; int rv; if (mk) { if (create_testfile()<0) { return; } } snprintf(mydesc, sizeof(mydesc), "%s with %s path", call, pathdesc); rv = func(path); report_test(rv, errno, EFAULT, mydesc); if (mk || rm) { remove(TESTFILE); } }
/* Test llapi_hsm_state_get. */ void test50(void) { struct hsm_user_state hus; int rc; int fd; fd = create_testfile(100); /* With fd variant */ rc = llapi_hsm_state_get_fd(fd, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get_fd failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); rc = llapi_hsm_state_get_fd(fd, NULL); ASSERTF(rc == -EFAULT, "llapi_hsm_state_get_fd error: %s", strerror(-rc)); rc = close(fd); ASSERTF(rc == 0, "close failed: %s", strerror(errno)); /* Without fd */ rc = llapi_hsm_state_get(testfile, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); rc = llapi_hsm_state_get(testfile, NULL); ASSERTF(rc == -EFAULT, "llapi_hsm_state_get error: %s", strerror(-rc)); memset(&hus, 0xaa, sizeof(hus)); rc = llapi_hsm_state_get(testfile, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == 0, "state=%u", hus.hus_states); ASSERTF(hus.hus_archive_id == 0, "archive_id=%u", hus.hus_archive_id); ASSERTF(hus.hus_in_progress_state == 0, "hus_in_progress_state=%u", hus.hus_in_progress_state); ASSERTF(hus.hus_in_progress_action == 0, "hus_in_progress_action=%u", hus.hus_in_progress_action); }
void create_large_testfile(const char* name) { create_testfile(name, 1e6); }
void create_small_testfile(const char* name) { create_testfile(name, 10); }
static int client(apr_pool_t *p, client_socket_mode_t socket_mode, const char *host, int start_server) { apr_status_t rv, tmprv; apr_socket_t *sock; char buf[120]; apr_file_t *f = NULL; apr_size_t len; apr_size_t expected_len; apr_off_t current_file_offset; apr_hdtr_t hdtr; struct iovec headers[3]; struct iovec trailers[3]; apr_size_t bytes_read; apr_pollset_t *pset; apr_int32_t nsocks; int connect_tries = 1; int i; int family; apr_sockaddr_t *destsa; apr_proc_t server; apr_interval_time_t connect_retry_interval = apr_time_from_msec(50); if (start_server) { spawn_server(p, &server); connect_tries = 5; /* give it a chance to start up */ } create_testfile(p, TESTFILE); rv = apr_file_open(&f, TESTFILE, APR_FOPEN_READ, 0, p); if (rv != APR_SUCCESS) { aprerr("apr_file_open()", rv); } if (!host) { host = "127.0.0.1"; } family = APR_INET; rv = apr_sockaddr_info_get(&destsa, host, family, TESTSF_PORT, 0, p); if (rv != APR_SUCCESS) { aprerr("apr_sockaddr_info_get()", rv); } while (connect_tries--) { apr_setup(p, &sock, &family); rv = apr_socket_connect(sock, destsa); if (connect_tries && APR_STATUS_IS_ECONNREFUSED(rv)) { apr_status_t tmprv = apr_socket_close(sock); if (tmprv != APR_SUCCESS) { aprerr("apr_socket_close()", tmprv); } apr_sleep(connect_retry_interval); connect_retry_interval *= 2; } else { break; } } if (rv != APR_SUCCESS) { aprerr("apr_socket_connect()", rv); } switch(socket_mode) { case BLK: /* leave it blocking */ break; case NONBLK: /* set it non-blocking */ rv = apr_socket_opt_set(sock, APR_SO_NONBLOCK, 1); if (rv != APR_SUCCESS) { aprerr("apr_socket_opt_set(APR_SO_NONBLOCK)", rv); } break; case TIMEOUT: /* set a timeout */ rv = apr_socket_timeout_set(sock, 100 * APR_USEC_PER_SEC); if (rv != APR_SUCCESS) { aprerr("apr_socket_opt_set(APR_SO_NONBLOCK)", rv); exit(1); } break; default: assert(1 != 1); } printf("Sending the file...\n"); hdtr.headers = headers; hdtr.numheaders = 3; hdtr.headers[0].iov_base = HDR1; hdtr.headers[0].iov_len = strlen(hdtr.headers[0].iov_base); hdtr.headers[1].iov_base = HDR2; hdtr.headers[1].iov_len = strlen(hdtr.headers[1].iov_base); hdtr.headers[2].iov_base = malloc(HDR3_LEN); assert(hdtr.headers[2].iov_base); memset(hdtr.headers[2].iov_base, HDR3_CHAR, HDR3_LEN); hdtr.headers[2].iov_len = HDR3_LEN; hdtr.trailers = trailers; hdtr.numtrailers = 3; hdtr.trailers[0].iov_base = TRL1; hdtr.trailers[0].iov_len = strlen(hdtr.trailers[0].iov_base); hdtr.trailers[1].iov_base = TRL2; hdtr.trailers[1].iov_len = strlen(hdtr.trailers[1].iov_base); hdtr.trailers[2].iov_base = malloc(TRL3_LEN); memset(hdtr.trailers[2].iov_base, TRL3_CHAR, TRL3_LEN); assert(hdtr.trailers[2].iov_base); hdtr.trailers[2].iov_len = TRL3_LEN; expected_len = strlen(HDR1) + strlen(HDR2) + HDR3_LEN + strlen(TRL1) + strlen(TRL2) + TRL3_LEN + FILE_LENGTH; if (socket_mode == BLK) { current_file_offset = 0; len = FILE_LENGTH; rv = apr_socket_sendfile(sock, f, &hdtr, ¤t_file_offset, &len, 0); if (rv != APR_SUCCESS) { aprerr("apr_socket_sendfile()", rv); } printf("apr_socket_sendfile() updated offset with %ld\n", (long int)current_file_offset); printf("apr_socket_sendfile() updated len with %ld\n", (long int)len); printf("bytes really sent: %" APR_SIZE_T_FMT "\n", expected_len); if (len != expected_len) { fprintf(stderr, "apr_socket_sendfile() didn't report the correct " "number of bytes sent!\n"); exit(1); } } else { /* non-blocking... wooooooo */ apr_size_t total_bytes_sent; apr_pollfd_t pfd; pset = NULL; rv = apr_pollset_create(&pset, 1, p, 0); assert(!rv); pfd.p = p; pfd.desc_type = APR_POLL_SOCKET; pfd.reqevents = APR_POLLOUT; pfd.rtnevents = 0; pfd.desc.s = sock; pfd.client_data = NULL; rv = apr_pollset_add(pset, &pfd); assert(!rv); total_bytes_sent = 0; current_file_offset = 0; len = FILE_LENGTH; do { apr_size_t tmplen; tmplen = len; /* bytes remaining to send from the file */ printf("Calling apr_socket_sendfile()...\n"); printf("Headers (%d):\n", hdtr.numheaders); for (i = 0; i < hdtr.numheaders; i++) { printf("\t%ld bytes (%c)\n", (long)hdtr.headers[i].iov_len, *(char *)hdtr.headers[i].iov_base); } printf("File: %ld bytes from offset %ld\n", (long)tmplen, (long)current_file_offset); printf("Trailers (%d):\n", hdtr.numtrailers); for (i = 0; i < hdtr.numtrailers; i++) { printf("\t%ld bytes\n", (long)hdtr.trailers[i].iov_len); } rv = apr_socket_sendfile(sock, f, &hdtr, ¤t_file_offset, &tmplen, 0); printf("apr_socket_sendfile()->%d, sent %ld bytes\n", rv, (long)tmplen); if (rv) { if (APR_STATUS_IS_EAGAIN(rv)) { assert(tmplen == 0); nsocks = 1; tmprv = apr_pollset_poll(pset, -1, &nsocks, NULL); assert(!tmprv); assert(nsocks == 1); /* continue; */ } } total_bytes_sent += tmplen; /* Adjust hdtr to compensate for partially-written * data. */ /* First, skip over any header data which might have * been written. */ while (tmplen && hdtr.numheaders) { if (tmplen >= hdtr.headers[0].iov_len) { tmplen -= hdtr.headers[0].iov_len; --hdtr.numheaders; ++hdtr.headers; } else { hdtr.headers[0].iov_len -= tmplen; hdtr.headers[0].iov_base = (char*) hdtr.headers[0].iov_base + tmplen; tmplen = 0; } } /* Now, skip over any file data which might have been * written. */ if (tmplen <= len) { current_file_offset += tmplen; len -= tmplen; tmplen = 0; } else { tmplen -= len; len = 0; current_file_offset = 0; } /* Last, skip over any trailer data which might have * been written. */ while (tmplen && hdtr.numtrailers) { if (tmplen >= hdtr.trailers[0].iov_len) { tmplen -= hdtr.trailers[0].iov_len; --hdtr.numtrailers; ++hdtr.trailers; } else { hdtr.trailers[0].iov_len -= tmplen; hdtr.trailers[0].iov_base = (char *)hdtr.trailers[0].iov_base + tmplen; tmplen = 0; } } } while (total_bytes_sent < expected_len && (rv == APR_SUCCESS || (APR_STATUS_IS_EAGAIN(rv) && socket_mode != TIMEOUT))); if (total_bytes_sent != expected_len) { fprintf(stderr, "client problem: sent %ld of %ld bytes\n", (long)total_bytes_sent, (long)expected_len); exit(1); } if (rv) { fprintf(stderr, "client problem: rv %d\n", rv); exit(1); } } current_file_offset = 0; rv = apr_file_seek(f, APR_CUR, ¤t_file_offset); if (rv != APR_SUCCESS) { aprerr("apr_file_seek()", rv); } printf("After apr_socket_sendfile(), the kernel file pointer is " "at offset %ld.\n", (long int)current_file_offset); rv = apr_socket_shutdown(sock, APR_SHUTDOWN_WRITE); if (rv != APR_SUCCESS) { aprerr("apr_socket_shutdown()", rv); } /* in case this is the non-blocking test, set socket timeout; * we're just waiting for EOF */ rv = apr_socket_timeout_set(sock, apr_time_from_sec(3)); if (rv != APR_SUCCESS) { aprerr("apr_socket_timeout_set()", rv); } bytes_read = 1; rv = apr_socket_recv(sock, buf, &bytes_read); if (rv != APR_EOF) { aprerr("apr_socket_recv() (expected APR_EOF)", rv); } if (bytes_read != 0) { fprintf(stderr, "We expected to get 0 bytes read with APR_EOF\n" "but instead we read %ld bytes.\n", (long int)bytes_read); exit(1); } printf("client: apr_socket_sendfile() worked as expected!\n"); rv = apr_file_remove(TESTFILE, p); if (rv != APR_SUCCESS) { aprerr("apr_file_remove()", rv); } if (start_server) { apr_exit_why_e exitwhy; apr_size_t nbytes; char responsebuf[1024]; int exitcode; rv = apr_file_pipe_timeout_set(server.out, apr_time_from_sec(2)); if (rv != APR_SUCCESS) { aprerr("apr_file_pipe_timeout_set()", rv); } nbytes = sizeof(responsebuf); rv = apr_file_read(server.out, responsebuf, &nbytes); if (rv != APR_SUCCESS) { aprerr("apr_file_read() messages from server", rv); } printf("%.*s", (int)nbytes, responsebuf); rv = apr_proc_wait(&server, &exitcode, &exitwhy, APR_WAIT); if (rv != APR_CHILD_DONE) { aprerr("apr_proc_wait() (expected APR_CHILD_DONE)", rv); } if (exitcode != 0) { fprintf(stderr, "sendfile server returned %d\n", exitcode); exit(1); } } return 0; }
/* Helper to simulate archiving a file. No actual data movement * happens. */ void helper_archiving(void (*progress) (struct hsm_copyaction_private *hcp, size_t length), const size_t length) { int rc; int fd; struct hsm_copytool_private *ctdata; struct hsm_user_request *hur; struct hsm_action_list *hal; struct hsm_action_item *hai; int msgsize; struct hsm_copyaction_private *hcp; struct hsm_user_state hus; fd = create_testfile(length); rc = llapi_hsm_copytool_register(&ctdata, fsmountdir, 0, NULL, 0); ASSERTF(rc == 0, "llapi_hsm_copytool_register failed: %s", strerror(-rc)); /* Create and send the archive request. */ hur = llapi_hsm_user_request_alloc(1, 0); ASSERTF(hur != NULL, "llapi_hsm_user_request_alloc returned NULL"); hur->hur_request.hr_action = HUA_ARCHIVE; hur->hur_request.hr_archive_id = 1; hur->hur_request.hr_flags = 0; hur->hur_request.hr_itemcount = 1; hur->hur_request.hr_data_len = 0; hur->hur_user_item[0].hui_extent.offset = 0; hur->hur_user_item[0].hui_extent.length = -1; rc = llapi_fd2fid(fd, &hur->hur_user_item[0].hui_fid); ASSERTF(rc == 0, "llapi_fd2fid failed: %s", strerror(-rc)); close(fd); rc = llapi_hsm_request(testfile, hur); ASSERTF(rc == 0, "llapi_hsm_request failed: %s", strerror(-rc)); free(hur); /* Read the request */ rc = llapi_hsm_copytool_recv(ctdata, &hal, &msgsize); ASSERTF(rc == 0, "llapi_hsm_copytool_recv failed: %s", strerror(-rc)); ASSERTF(hal->hal_count == 1, "hal_count=%d", hal->hal_count); hai = hai_first(hal); ASSERTF(hai != NULL, "hai_first returned NULL"); ASSERTF(hai->hai_action == HSMA_ARCHIVE, "hai_action=%d", hai->hai_action); /* "Begin" archiving */ hcp = NULL; rc = llapi_hsm_action_begin(&hcp, ctdata, hai, -1, 0, false); ASSERTF(rc == 0, "llapi_hsm_action_begin failed: %s", strerror(-rc)); ASSERTF(hcp != NULL, "hcp is NULL"); if (progress) progress(hcp, length); /* Done archiving */ rc = llapi_hsm_action_end(&hcp, &hai->hai_extent, 0, 0); ASSERTF(rc == 0, "llapi_hsm_action_end failed: %s", strerror(-rc)); ASSERTF(hcp == NULL, "hcp is NULL"); /* Close HSM client */ rc = llapi_hsm_copytool_unregister(&ctdata); ASSERTF(rc == 0, "llapi_hsm_copytool_unregister failed: %s", strerror(-rc)); /* Final check */ rc = llapi_hsm_state_get(testfile, &hus); ASSERTF(rc == 0, "llapi_hsm_state_get failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == (HS_EXISTS | HS_ARCHIVED), "state=%u", hus.hus_states); }
/* Test llapi_hsm_state_set. */ void test51(void) { int rc; int fd; int i; struct hsm_user_state hus; fd = create_testfile(100); rc = llapi_hsm_state_set_fd(fd, 0, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); /* Set archive id */ for (i = 0; i <= 32; i++) { rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, i); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_get_fd(fd, &hus); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); ASSERTF(hus.hus_states == HS_EXISTS, "state=%u", hus.hus_states); ASSERTF(hus.hus_archive_id == i, "archive_id=%u, i=%d", hus.hus_archive_id, i); } /* Invalid archive numbers */ rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 33); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, 151); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_EXISTS, 0, -1789); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc)); /* Settable flags, with respect of the HSM file state transition rules: * DIRTY without EXISTS: no dirty if no archive was created * DIRTY and RELEASED: a dirty file could not be released * RELEASED without ARCHIVED: do not release a non-archived file * LOST without ARCHIVED: cannot lost a non-archived file. */ rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_DIRTY, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_EXISTS, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_DIRTY, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_ARCHIVED, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_RELEASED, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_LOST, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_RELEASED, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_DIRTY|HS_EXISTS, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_LOST, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_ARCHIVED, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_NORELEASE, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_NORELEASE, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, HS_NOARCHIVE, 0, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0, HS_NOARCHIVE, 0); ASSERTF(rc == 0, "llapi_hsm_state_set_fd failed: %s", strerror(-rc)); /* Bogus flags for good measure. */ rc = llapi_hsm_state_set_fd(fd, 0x00080000, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc)); rc = llapi_hsm_state_set_fd(fd, 0x80000000, 0, 0); ASSERTF(rc == -EINVAL, "llapi_hsm_state_set_fd: %s", strerror(-rc)); close(fd); }
static void test_readahead(unsigned int n) { unsigned long read_bytes, read_bytes_ra; long long usec, usec_ra; unsigned long cached_high, cached_low, cached, cached_ra; int ret; struct tcase *tc = &tcases[n]; tst_res(TINFO, "Test #%d: %s", n, tc->tname); if (tc->use_overlay && !ovl_mounted) { tst_res(TCONF, "overlayfs is not configured in this kernel."); return; } create_testfile(tc->use_overlay); /* find out how much can cache hold if we read whole file */ read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, &cached); cached_high = get_cached_size(); sync(); drop_caches(); cached_low = get_cached_size(); cached_max = MAX(cached_max, cached_high - cached_low); tst_res(TINFO, "read_testfile(0)"); read_testfile(tc, 0, testfile, testfile_size, &read_bytes, &usec, &cached); if (cached > cached_low) cached = cached - cached_low; else cached = 0; sync(); drop_caches(); cached_low = get_cached_size(); tst_res(TINFO, "read_testfile(1)"); ret = read_testfile(tc, 1, testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra); if (ret == EINVAL) { if (tc->use_fadvise && (!tc->use_overlay || !fadvise_supported)) { fadvise_supported = 0; tst_res(TCONF, "CONFIG_ADVISE_SYSCALLS not configured " "in kernel?"); return; } if (!tc->use_overlay || !readahead_supported) { readahead_supported = 0; tst_res(TCONF, "readahead not supported on %s", tst_device->fs_type); return; } } if (ret) { tst_res(TFAIL | TTERRNO, "%s failed on %s", tc->use_fadvise ? "fadvise" : "readahead", tc->use_overlay ? "overlayfs" : tst_device->fs_type); return; } if (cached_ra > cached_low) cached_ra = cached_ra - cached_low; else cached_ra = 0; tst_res(TINFO, "read_testfile(0) took: %lli usec", usec); tst_res(TINFO, "read_testfile(1) took: %lli usec", usec_ra); if (has_file(PROC_IO_FNAME, 0)) { tst_res(TINFO, "read_testfile(0) read: %ld bytes", read_bytes); tst_res(TINFO, "read_testfile(1) read: %ld bytes", read_bytes_ra); /* actual number of read bytes depends on total RAM */ if (read_bytes_ra < read_bytes) tst_res(TPASS, "readahead saved some I/O"); else tst_res(TFAIL, "readahead failed to save any I/O"); } else { tst_res(TCONF, "Your system doesn't have /proc/self/io," " unable to determine read bytes during test"); } tst_res(TINFO, "cache can hold at least: %ld kB", cached_max); tst_res(TINFO, "read_testfile(0) used cache: %ld kB", cached); tst_res(TINFO, "read_testfile(1) used cache: %ld kB", cached_ra); if (cached_max * 1024 >= testfile_size) { /* * if cache can hold ~testfile_size then cache increase * for readahead should be at least testfile_size/2 */ if (cached_ra * 1024 > testfile_size / 2) tst_res(TPASS, "using cache as expected"); else if (!cached_ra) tst_res(TFAIL, "readahead failed to use any cache"); else tst_res(TWARN, "using less cache than expected"); } else { tst_res(TCONF, "Page cache on your system is too small " "to hold whole testfile."); } }