From patchwork Wed Sep 25 21:40:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11161591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB62C76 for ; Wed, 25 Sep 2019 21:40:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF18720872 for ; Wed, 25 Sep 2019 21:40:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="bIDuEple" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726452AbfIYVkN (ORCPT ); Wed, 25 Sep 2019 17:40:13 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:48904 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725837AbfIYVkN (ORCPT ); Wed, 25 Sep 2019 17:40:13 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8PLdPju013264; Wed, 25 Sep 2019 21:40:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=t/ON9kf0sEc1BiUZn6FpkojKcRXIDSPbMEt+nuOl1Pg=; b=bIDuEpleChXUUYMTNl0go0lTIEfIP+wxGa5Sg2uwuKLQ1OlDPVSRY7uCZHzwBz+UgF94 nt44+VS1ZVIRw4SrbKnZGePgQxjjt+gxRhpDvpESSWU8Ttzd1DGfPYxmJ3moQVZKx2/J yFPrNhQsOrHaMsngZsbV8+A9vNA9cg5hsXTPGjBqdtlO2+nE+2MAmQ2o1AgTylU2EHwM qOwwE8gkuCyxJdC171Rt8I6I2YcWeTapMSCx4dNBFDUYFhYHxAg3xP5rawYTn4N6v9TG sWAjnPJJXSnrc0zxKlKTUIJwZAS6HNcAEhJ9T8aqOTy7VZc1wh9+/UBNHpMwudZJ7zaB PQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2v5btq7jch-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Sep 2019 21:40:10 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x8PLdLeh107800; Wed, 25 Sep 2019 21:40:10 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2v82qam23x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Sep 2019 21:40:10 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x8PLe9wO018291; Wed, 25 Sep 2019 21:40:09 GMT Received: from localhost (/10.145.178.55) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 25 Sep 2019 14:40:09 -0700 Subject: [PATCH 1/7] libfrog: print library errors From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Wed, 25 Sep 2019 14:40:07 -0700 Message-ID: <156944760784.302827.3061460651592524999.stgit@magnolia> In-Reply-To: <156944760161.302827.4342305147521200999.stgit@magnolia> References: <156944760161.302827.4342305147521200999.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9391 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909250175 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9391 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1908290000 definitions=main-1909250175 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add a libfrog library function that will print tagged error messages. This will eliminate the need for a lot of open-coded: errno = ret; perror("..."); Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- io/bulkstat.c | 19 +++++++------------ io/imap.c | 4 ++-- io/open.c | 13 +++++-------- io/stat.c | 4 ++-- io/swapext.c | 7 +++---- libfrog/Makefile | 2 ++ libfrog/logging.c | 18 ++++++++++++++++++ libfrog/logging.h | 11 +++++++++++ quota/free.c | 4 ++-- quota/quot.c | 10 ++++------ spaceman/file.c | 7 +++---- spaceman/health.c | 13 +++++-------- 12 files changed, 64 insertions(+), 48 deletions(-) create mode 100644 libfrog/logging.c create mode 100644 libfrog/logging.h diff --git a/io/bulkstat.c b/io/bulkstat.c index 625f0abe..0ea21584 100644 --- a/io/bulkstat.c +++ b/io/bulkstat.c @@ -7,6 +7,7 @@ #include "platform_defs.h" #include "command.h" #include "init.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" #include "libfrog/paths.h" @@ -165,8 +166,7 @@ bulkstat_f( ret = xfd_prepare_geometry(&xfd); if (ret) { - errno = ret; - perror("xfd_prepare_geometry"); + xfrog_perror(ret, "xfd_prepare_geometry"); exitcode = 1; return 0; } @@ -203,8 +203,7 @@ _("bulkstat: startino=%lld flags=0x%x agno=%u ret=%d icount=%u ocount=%u\n"), } } if (ret) { - errno = ret; - perror("xfrog_bulkstat"); + xfrog_perror(ret, "xfrog_bulkstat"); exitcode = 1; return 0; } @@ -269,8 +268,7 @@ bulkstat_single_f( ret = xfd_prepare_geometry(&xfd); if (ret) { - errno = ret; - perror("xfd_prepare_geometry"); + xfrog_perror(ret, "xfd_prepare_geometry"); exitcode = 1; return 0; } @@ -313,8 +311,7 @@ bulkstat_single_f( ret = xfrog_bulkstat_single(&xfd, ino, flags, &bulkstat); if (ret) { - errno = ret; - perror("xfrog_bulkstat_single"); + xfrog_perror(ret, "xfrog_bulkstat_single"); continue; } @@ -427,8 +424,7 @@ inumbers_f( ret = xfd_prepare_geometry(&xfd); if (ret) { - errno = ret; - perror("xfd_prepare_geometry"); + xfrog_perror(ret, "xfd_prepare_geometry"); exitcode = 1; return 0; } @@ -465,8 +461,7 @@ _("bulkstat: startino=%"PRIu64" flags=0x%"PRIx32" agno=%"PRIu32" ret=%d icount=% } } if (ret) { - errno = ret; - perror("xfrog_inumbers"); + xfrog_perror(ret, "xfrog_inumbers"); exitcode = 1; return 0; } diff --git a/io/imap.c b/io/imap.c index fa69676e..6b338640 100644 --- a/io/imap.c +++ b/io/imap.c @@ -8,6 +8,7 @@ #include "input.h" #include "init.h" #include "io.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" @@ -44,8 +45,7 @@ imap_f(int argc, char **argv) } if (error) { - errno = error; - perror("xfsctl(XFS_IOC_FSINUMBERS)"); + xfrog_perror(error, "xfsctl(XFS_IOC_FSINUMBERS)"); exitcode = 1; } free(ireq); diff --git a/io/open.c b/io/open.c index 3c6113a1..c07ecb04 100644 --- a/io/open.c +++ b/io/open.c @@ -9,6 +9,7 @@ #include "init.h" #include "io.h" #include "libxfs.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" @@ -125,8 +126,7 @@ openfile( ret = xfrog_geometry(fd, geom); if (ret) { - errno = ret; - perror("XFS_IOC_FSGEOMETRY"); + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); close(fd); return -1; } @@ -696,8 +696,7 @@ get_last_inode(void) ret = xfrog_inumbers(&xfd, ireq); if (ret) { - errno = ret; - perror("XFS_IOC_FSINUMBERS"); + xfrog_perror(ret, "XFS_IOC_FSINUMBERS"); free(ireq); goto out; } @@ -798,8 +797,7 @@ inode_f( /* get next inode */ ret = xfrog_bulkstat(&xfd, breq); if (ret) { - errno = ret; - perror("bulkstat"); + xfrog_perror(ret, "bulkstat"); free(breq); exitcode = 1; return 0; @@ -820,8 +818,7 @@ inode_f( /* Not in use */ result_ino = 0; } else if (ret) { - errno = ret; - perror("bulkstat_single"); + xfrog_perror(ret, "bulkstat_single"); exitcode = 1; return 0; } else { diff --git a/io/stat.c b/io/stat.c index 6c666146..db335780 100644 --- a/io/stat.c +++ b/io/stat.c @@ -12,6 +12,7 @@ #include "io.h" #include "statx.h" #include "libxfs.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include @@ -198,8 +199,7 @@ statfs_f( return 0; ret = xfrog_geometry(file->fd, &fsgeo); if (ret) { - errno = ret; - perror("XFS_IOC_FSGEOMETRY"); + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); } else { printf(_("geom.bsize = %u\n"), fsgeo.blocksize); printf(_("geom.agcount = %u\n"), fsgeo.agcount); diff --git a/io/swapext.c b/io/swapext.c index 1139cf21..dc4e418f 100644 --- a/io/swapext.c +++ b/io/swapext.c @@ -8,6 +8,7 @@ #include "input.h" #include "init.h" #include "io.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" @@ -51,14 +52,12 @@ swapext_f( error = xfrog_bulkstat_single(&fxfd, stat.st_ino, 0, &bulkstat); if (error) { - errno = error; - perror("bulkstat"); + xfrog_perror(error, "bulkstat"); goto out; } error = xfrog_bulkstat_v5_to_v1(&fxfd, &sx.sx_stat, &bulkstat); if (error) { - errno = error; - perror("bulkstat conversion"); + xfrog_perror(error, "bulkstat conversion"); goto out; } sx.sx_version = XFS_SX_VERSION; diff --git a/libfrog/Makefile b/libfrog/Makefile index de67bf00..780600cd 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -19,6 +19,7 @@ crc32.c \ fsgeom.c \ list_sort.c \ linux.c \ +logging.c \ paths.c \ projects.c \ ptvar.c \ @@ -38,6 +39,7 @@ crc32cselftest.h \ crc32defs.h \ crc32table.h \ fsgeom.h \ +logging.h \ paths.h \ projects.h \ ptvar.h \ diff --git a/libfrog/logging.c b/libfrog/logging.c new file mode 100644 index 00000000..91ea4537 --- /dev/null +++ b/libfrog/logging.c @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2019 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#include +#include +#include "logging.h" + +/* Print an error. */ +void +xfrog_perror( + int error, + const char *s) +{ + errno = error < 0 ? -error : error; + perror(s); +} diff --git a/libfrog/logging.h b/libfrog/logging.h new file mode 100644 index 00000000..8b125bfd --- /dev/null +++ b/libfrog/logging.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2019 Oracle, Inc. + * All Rights Reserved. + */ +#ifndef __LIBFROG_LOGGING_H__ +#define __LIBFROG_LOGGING_H__ + +void xfrog_perror(int error, const char *s); + +#endif /* __LIBFROG_LOGGING_H__ */ diff --git a/quota/free.c b/quota/free.c index 73aeb459..45ce2ceb 100644 --- a/quota/free.c +++ b/quota/free.c @@ -8,6 +8,7 @@ #include "command.h" #include "init.h" #include "quota.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" static cmdinfo_t free_cmd; @@ -70,8 +71,7 @@ mount_free_space_data( if (!(mount->fs_flags & FS_FOREIGN)) { ret = xfrog_geometry(fd, &fsgeo); if (ret) { - errno = ret; - perror("XFS_IOC_FSGEOMETRY"); + xfrog_perror(ret, "XFS_IOC_FSGEOMETRY"); close(fd); return 0; } diff --git a/quota/quot.c b/quota/quot.c index 7edfad16..0f69fabd 100644 --- a/quota/quot.c +++ b/quota/quot.c @@ -11,6 +11,7 @@ #include #include "init.h" #include "quota.h" +#include "libfrog/logging.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" @@ -147,8 +148,7 @@ quot_bulkstat_mount( ret = xfd_open(&fsxfd, fsdir, O_RDONLY); if (ret) { - errno = ret; - perror(fsdir); + xfrog_perror(ret, fsdir); return; } @@ -165,10 +165,8 @@ quot_bulkstat_mount( for (i = 0; i < breq->hdr.ocount; i++) quot_bulkstat_add(&breq->bulkstat[i], flags); } - if (sts < 0) { - errno = sts; - perror("XFS_IOC_FSBULKSTAT"); - } + if (sts < 0) + xfrog_perror(sts, "XFS_IOC_FSBULKSTAT"); free(breq); xfd_close(&fsxfd); } diff --git a/spaceman/file.c b/spaceman/file.c index 43b87e14..b7794328 100644 --- a/spaceman/file.c +++ b/spaceman/file.c @@ -10,6 +10,7 @@ #include "command.h" #include "input.h" #include "init.h" +#include "libfrog/logging.h" #include "libfrog/paths.h" #include "libfrog/fsgeom.h" #include "space.h" @@ -57,10 +58,8 @@ openfile( fprintf(stderr, _("%s: Not on a mounted XFS filesystem.\n"), path); - else { - errno = ret; - perror(path); - } + else + xfrog_perror(ret, path); return -1; } diff --git a/spaceman/health.c b/spaceman/health.c index 8fd985a2..c3b89e8f 100644 --- a/spaceman/health.c +++ b/spaceman/health.c @@ -8,6 +8,7 @@ #include "command.h" #include "init.h" #include "input.h" +#include "libfrog/logging.h" #include "libfrog/paths.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" @@ -193,8 +194,7 @@ report_ag_sick( ret = xfrog_ag_geometry(file->xfd.fd, agno, &ageo); if (ret) { - errno = ret; - perror("ag_geometry"); + xfrog_perror(ret, "ag_geometry"); return 1; } snprintf(descr, sizeof(descr) - 1, _("AG %u"), agno); @@ -219,8 +219,7 @@ report_inode_health( ret = xfrog_bulkstat_single(&file->xfd, ino, 0, &bs); if (ret) { - errno = ret; - perror(descr); + xfrog_perror(ret, descr); return 1; } @@ -294,10 +293,8 @@ report_bulkstat_health( } } while (breq->hdr.ocount > 0); - if (error) { - errno = error; - perror("bulkstat"); - } + if (error) + xfrog_perror(error, "bulkstat"); free(breq); return error;