From patchwork Tue May 3 18:21:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaegeuk Kim X-Patchwork-Id: 9007661 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 83FD7BF29F for ; Tue, 3 May 2016 18:24:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B215120320 for ; Tue, 3 May 2016 18:24:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C31E1202F0 for ; Tue, 3 May 2016 18:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934683AbcECSWF (ORCPT ); Tue, 3 May 2016 14:22:05 -0400 Received: from mail.kernel.org ([198.145.29.136]:51330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934676AbcECSWC (ORCPT ); Tue, 3 May 2016 14:22:02 -0400 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 44EF820357; Tue, 3 May 2016 18:22:00 +0000 (UTC) Received: from localhost (107-1-141-74-ip-static.hfc.comcastbusiness.net [107.1.141.74]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 71A2D20351; Tue, 3 May 2016 18:21:59 +0000 (UTC) From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim Subject: [PATCH 06/11] f2fs: inject kmalloc failure Date: Tue, 3 May 2016 11:21:43 -0700 Message-Id: <1462299708-67906-6-git-send-email-jaegeuk@kernel.org> X-Mailer: git-send-email 2.6.3 In-Reply-To: <1462299708-67906-1-git-send-email-jaegeuk@kernel.org> References: <1462299708-67906-1-git-send-email-jaegeuk@kernel.org> X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch injects kmalloc failure given a fault injection rate. Signed-off-by: Jaegeuk Kim --- fs/f2fs/f2fs.h | 29 +++++++++++++++++++++++++++++ fs/f2fs/super.c | 6 ++++++ 2 files changed, 35 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 0684d3e..60098df 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -37,6 +37,31 @@ } while (0) #endif +#ifdef CONFIG_F2FS_FAULT_INJECTION +enum { + FAULT_KMALLOC, + FAULT_MAX, +}; + +extern u32 f2fs_fault_rate; +extern atomic_t f2fs_ops; +extern char *fault_name[FAULT_MAX]; + +static inline bool time_to_inject(int type) +{ + atomic_inc(&f2fs_ops); + if (f2fs_fault_rate && (atomic_read(&f2fs_ops) >= f2fs_fault_rate)) { + atomic_set(&f2fs_ops, 0); + printk("%sF2FS-fs : inject %s in %pF\n", + KERN_INFO, + fault_name[type], + __builtin_return_address(0)); + return true; + } + return false; +} +#endif + /* * For mount options */ @@ -1646,6 +1671,10 @@ static inline bool f2fs_may_extent_tree(struct inode *inode) static inline void *f2fs_kmalloc(size_t size, gfp_t flags) { +#ifdef CONFIG_F2FS_FAULT_INJECTION + if (time_to_inject(FAULT_KMALLOC)) + return NULL; +#endif return kmalloc(size, flags); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index b27febd..76f4d2c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -41,6 +41,11 @@ static struct kset *f2fs_kset; #ifdef CONFIG_F2FS_FAULT_INJECTION u32 f2fs_fault_rate = 0; +atomic_t f2fs_ops; + +char *fault_name[FAULT_MAX] = { + [FAULT_KMALLOC] = "kmalloc", +}; #endif /* f2fs-wide shrinker description */ @@ -444,6 +449,7 @@ static int parse_options(struct super_block *sb, char *options) return -EINVAL; #ifdef CONFIG_F2FS_FAULT_INJECTION f2fs_fault_rate = arg; + atomic_set(&f2fs_ops, 0); #else f2fs_msg(sb, KERN_INFO, "FAULT_INJECTION was not selected");