X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Ftests%2Fll_dirstripe_verify.c;h=b44c32b58ab7f07e274902175fa1fbc3e4f27833;hb=refs%2Fchanges%2F42%2F8842%2F4;hp=e57206d930a413a0e261b8e6c16de14acca95f2b;hpb=65701b4a30efdb695776bcf690a2b3cabc928da1;p=fs%2Flustre-release.git diff --git a/lustre/tests/ll_dirstripe_verify.c b/lustre/tests/ll_dirstripe_verify.c index e57206d..b44c32b 100644 --- a/lustre/tests/ll_dirstripe_verify.c +++ b/lustre/tests/ll_dirstripe_verify.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -29,7 +27,7 @@ * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, Whamcloud, Inc. + * Copyright (c) 2011, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -53,14 +51,7 @@ #include #include -#include -#include -#include -#include -#include - -#include - +#include #define MAX_LOV_UUID_COUNT 1000 union { @@ -76,32 +67,33 @@ union { */ int read_proc_entry(char *proc_path, char *buf, int len) { - int rc, fd; - - memset(buf, 0, len); - - fd = open(proc_path, O_RDONLY); - if (fd == -1) { - llapi_error(LLAPI_MSG_ERROR, -errno, "open('%s') failed: %s\n", - proc_path); - return -2; - } - - rc = read(fd, buf, len - 1); - if (rc < 0) { - llapi_error(LLAPI_MSG_ERROR, -errno, - "read('%s') failed: %s\n", proc_path); - rc = -3; - } else if (rc == 0) { - llapi_err_noerrno(LLAPI_MSG_ERROR, - "read('%s') zero bytes\n", proc_path); - rc = -4; - } else if (/* rc > 0 && */ buf[rc - 1] == '\n') { - buf[rc - 1] = '\0'; /* Remove trailing newline */ - } - close(fd); - - return (rc); + int rc, fd; + + memset(buf, 0, len); + + fd = open(proc_path, O_RDONLY); + if (fd < 0) { + llapi_error(LLAPI_MSG_ERROR, -errno, "cannot open '%s'", + proc_path); + return -2; + } + + rc = read(fd, buf, len - 1); + if (rc < 0) { + llapi_error(LLAPI_MSG_ERROR, -errno, + "error reading from '%s'", proc_path); + rc = -3; + } else if (rc == 0) { + llapi_err_noerrno(LLAPI_MSG_ERROR, + "read zero bytes from '%s'", proc_path); + rc = -4; + } else if (buf[rc - 1] == '\n') { + buf[rc - 1] = '\0'; /* Remove trailing newline */ + } + + close(fd); + + return rc; } int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1, @@ -117,18 +109,20 @@ int compare(struct lov_user_md *lum_dir, struct lov_user_md *lum_file1, int i; FILE *fp; - fp = popen("\\ls -d /proc/fs/lustre/lov/*clilov* | head -1", "r"); - if (!fp) { - llapi_error(LLAPI_MSG_ERROR, -errno, - "open(lustre/lov/*clilov*) failed: %s\n"); - return 2; - } - if (fscanf(fp, "%s", lov_path) < 1) { - llapi_error(LLAPI_MSG_ERROR, -EINVAL, - "read(lustre/lov/*clilov*) failed: %s\n"); - pclose(fp); - return 3; + fp = popen("\\ls -d /proc/fs/lustre/lov/*clilov* | head -1", "r"); + if (fp == NULL) { + llapi_error(LLAPI_MSG_ERROR, -errno, + "open(lustre/lov/*clilov*) failed"); + return 2; } + + if (fscanf(fp, "%s", lov_path) < 1) { + llapi_error(LLAPI_MSG_ERROR, -EINVAL, + "read(lustre/lov/*clilov*) failed"); + pclose(fp); + return 3; + } + pclose(fp); snprintf(tmp_path, sizeof(tmp_path) - 1, "%s/stripecount", @@ -247,14 +241,15 @@ int main(int argc, char **argv) return rc; } - lum_size = lov_mds_md_size(MAX_LOV_UUID_COUNT, LOV_MAGIC); - if ((lum_dir = (struct lov_user_md *)malloc(lum_size)) == NULL) { - rc = -ENOMEM; - llapi_error(LLAPI_MSG_ERROR, rc, - "error: can't allocate %d bytes " - "for dir EA", lum_size); - goto cleanup; - } + lum_size = lov_user_md_size(MAX_LOV_UUID_COUNT, LOV_USER_MAGIC); + lum_dir = (struct lov_user_md *)malloc(lum_size); + if (lum_dir == NULL) { + rc = -ENOMEM; + llapi_error(LLAPI_MSG_ERROR, rc, + "error: can't allocate %d bytes " + "for dir EA", lum_size); + goto cleanup; + } rc = llapi_file_get_stripe(argv[1], lum_dir); if (rc) {