From patchwork Thu Feb 4 17:44:03 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 77163 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o14HiL1x009474 for ; Thu, 4 Feb 2010 17:44:21 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753926Ab0BDRoT (ORCPT ); Thu, 4 Feb 2010 12:44:19 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:43108 "EHLO e23smtp09.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751350Ab0BDRoR (ORCPT ); Thu, 4 Feb 2010 12:44:17 -0500 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [202.81.31.247]) by e23smtp09.au.ibm.com (8.14.3/8.13.1) with ESMTP id o14HiG21008749 for ; Fri, 5 Feb 2010 04:44:16 +1100 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o14HdBSq1400868 for ; Fri, 5 Feb 2010 04:39:11 +1100 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id o14HiFCn015252 for ; Fri, 5 Feb 2010 04:44:15 +1100 Received: from localhost.localdomain ([9.124.220.136]) by d23av04.au.ibm.com (8.14.3/8.13.1/NCO v10.0 AVin) with ESMTP id o14HiB8O015154; Fri, 5 Feb 2010 04:44:14 +1100 From: "Aneesh Kumar K.V" To: chris.mason@oracle.com Cc: linux-btrfs@vger.kernel.org, "Aneesh Kumar K.V" Subject: [PATCH -V2 2/6] btrfs-progs: Add debug-btrfs command Date: Thu, 4 Feb 2010 23:14:03 +0530 Message-Id: <1265305447-30780-2-git-send-email-aneesh.kumar@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.0.rc0.48.gdace5 In-Reply-To: <1265305447-30780-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> References: <1265305447-30780-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 04 Feb 2010 17:44:21 +0000 (UTC) diff --git a/Makefile b/Makefile index a30c212..3efd405 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,9 @@ bindir = $(prefix)/bin LIBS=-luuid SUBDIRS=lib misc man +ifneq ($(E2FSPRGS_BUILD_DIR),) + SUBDIRS += debugbtrfs +endif # make C=1 to enable sparse ifdef C diff --git a/debugbtrfs/Makefile b/debugbtrfs/Makefile new file mode 100644 index 0000000..348160b --- /dev/null +++ b/debugbtrfs/Makefile @@ -0,0 +1,44 @@ +CC=gcc +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g -Werror -Os -I$(E2FSPRGS_BUILD_DIR)/lib/ -I../lib/ + +# +CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ + -Wuninitialized -Wshadow -Wundef +DEPFLAGS = -Wp,-MMD,$(@D)/.$(@F).d,-MT,$@ + +INSTALL= install +prefix ?= /usr/local +bindir = $(prefix)/bin +LIBS=-L$(E2FSPRGS_BUILD_DIR)/lib/ss -lss -ldl -lcom_err -luuid +TOPDIR=../ + +MK_CMDS= _SS_DIR_OVERRIDE=$(E2FSPRGS_BUILD_DIR)/lib/ss $(E2FSPRGS_BUILD_DIR)/lib/ss/mk_cmds + +progs = debug-btrfs + +# make C=1 to enable sparse +ifdef C + check=sparse $(CHECKFLAGS) +else + check=ls +endif + +.c.o: + $(check) $< + $(CC) $(DEPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c $< + +all: $(progs) + +debug_btrfs_cmds.c: debug_btrfs_cmds.ct + $(MK_CMDS) debug_btrfs_cmds.ct + +debug-btrfs: $(TOPDIR)/lib/libbtrfs.a debug_btrfs.o cmds.o debug_btrfs_cmds.o + $(CC) $(CFLAGS) -o debug-btrfs $^ $(TOPDIR)/lib/libbtrfs.a $(LDFLAGS) $(LIBS) + +clean: + rm -f *.o debug_btrfs_cmds.c + rm -f .*.d + rm -f debug-btrfs + +-include .*.d diff --git a/debugbtrfs/cmds.c b/debugbtrfs/cmds.c new file mode 100644 index 0000000..f5ed877 --- /dev/null +++ b/debugbtrfs/cmds.c @@ -0,0 +1,27 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include "debug_btrfs.h" + +void do_show_debugfs_params(int argc, char *argv[]) +{ + FILE *out = stdout; + fprintf(out, "Filesystem in use: %s\n", current_device); +} diff --git a/debugbtrfs/debug_btrfs.c b/debugbtrfs/debug_btrfs.c new file mode 100644 index 0000000..44d6f64 --- /dev/null +++ b/debugbtrfs/debug_btrfs.c @@ -0,0 +1,59 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#include +#include +#include +#include "debug_btrfs.h" + +extern ss_request_table btrfs_debug_cmds; +const char *current_device; + +void usage(char *prg) +{ + fprintf(stderr, "Usage: %s device\n", prg); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int sci_idx; + int retval; + + if (argc < 2) + usage(argv[0]); + + current_device = argv[1]; + sci_idx = ss_create_invocation("debug-btrfs", "0.0", NULL, + &btrfs_debug_cmds, &retval); + if (retval) { + ss_perror(sci_idx, retval, "create invocation"); + exit(1); + } + ss_get_readline(sci_idx); + (void) ss_add_request_table (sci_idx, &ss_std_requests, 1, &retval); + if (retval) { + ss_perror(sci_idx, retval, "adding standard requests"); + exit (1); + } + ss_listen(sci_idx); + ss_delete_invocation(sci_idx); + + return 0; +} diff --git a/debugbtrfs/debug_btrfs.h b/debugbtrfs/debug_btrfs.h new file mode 100644 index 0000000..55d7b17 --- /dev/null +++ b/debugbtrfs/debug_btrfs.h @@ -0,0 +1,29 @@ +/* + * Copyright IBM Corporation, 2010 + * Author Aneesh Kumar K.V + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef DEBUG_BTRFS_H +#define DEBUG_BTRFS_H +#include + +extern const char *current_device; +static inline void reset_getopt(void) +{ + optind = 0; +} +#endif diff --git a/debugbtrfs/debug_btrfs_cmds.ct b/debugbtrfs/debug_btrfs_cmds.ct new file mode 100644 index 0000000..29095d3 --- /dev/null +++ b/debugbtrfs/debug_btrfs_cmds.ct @@ -0,0 +1,24 @@ +# Copyright IBM Corporation, 2010 +# Author Aneesh Kumar K.V +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License v2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 021110-1307, USA. + +command_table btrfs_debug_cmds; + +request do_show_debugfs_params, "Show btrfs_debug parameters", + show_debugfs_params, params; + +end; +