From patchwork Wed Apr 22 03:38:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 6254461 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9DFD19F1C4 for ; Wed, 22 Apr 2015 03:48:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C94C42034F for ; Wed, 22 Apr 2015 03:48:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE7FD20306 for ; Wed, 22 Apr 2015 03:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754439AbbDVDru (ORCPT ); Tue, 21 Apr 2015 23:47:50 -0400 Received: from james.kirk.hungrycats.org ([174.142.39.145]:41650 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1754427AbbDVDru (ORCPT ); Tue, 21 Apr 2015 23:47:50 -0400 X-Greylist: delayed 526 seconds by postgrey-1.27 at vger.kernel.org; Tue, 21 Apr 2015 23:47:49 EDT Received: by james.kirk.hungrycats.org (Postfix, from userid 1002) id 1E518F600F1; Tue, 21 Apr 2015 23:38:58 -0400 (EDT) From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs-progs: report failure when resize ioctl fails Date: Tue, 21 Apr 2015 23:38:47 -0400 Message-Id: <1429673927-3854-1-git-send-email-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 1.7.10.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The BTRFS_IOC_RESIZE ioctl returns 0 on success, negative for POSIX errors, and positive for btrfs-specific errors. If resize fails with a btrfs-specific error, decode the error and report it. If we can't decode the error, report its numeric value so that the userspace tool is not instantly useless when a new error code is defined in the kernel. Exit with non-zero status on any resize error. This is very important for scripts that will shrink the underlying storage when btrfs reports success! --- cmds-filesystem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index f3fc160..85f0406 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -1263,6 +1263,16 @@ static int cmd_resize(int argc, char **argv) fprintf(stderr, "ERROR: unable to resize '%s' - %s\n", path, strerror(e)); return 1; + } else if (res > 0) { + const char *err_str = btrfs_err_str(res); + if (err_str) { + fprintf(stderr, "ERROR: btrfs error resizing '%s' - %s\n", + path, err_str); + } else { + fprintf(stderr, "ERROR: btrfs error resizing '%s' - unknown btrfs_err_code %d\n", + path, res); + } + return 1; } return 0; }