From patchwork Mon May 9 16:41:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Amir G." X-Patchwork-Id: 94816 X-Patchwork-Delegate: tytso@mit.edu Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3B833B6F1E for ; Tue, 10 May 2011 02:44:43 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753791Ab1EIQo3 (ORCPT ); Mon, 9 May 2011 12:44:29 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:35313 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753684Ab1EIQo2 (ORCPT ); Mon, 9 May 2011 12:44:28 -0400 Received: by mail-ww0-f44.google.com with SMTP id 36so5955868wwa.1 for ; Mon, 09 May 2011 09:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:cc:subject:date:message-id :x-mailer:in-reply-to:references; bh=eg+t6Q3VhTRQTXNiLMOEvnxrAkYMwibaaOzEfl38JSo=; b=g4jbOsLu4b5Z5ATzSx1gGkzM6KxvvjIiXTaFTofufKODVeEDF8ngtjO74urlUgLjSQ El3Dwkft2qWRFmi5fR+eS1MM8yaehck25NcWEdKKJgKNTSkfCC/nrFd3SRtVJKEFNngm tl6vb8ZdqmSd22Qi9VqgoNDPF1vhxoxt+teoU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; b=f2Qp3Mm9G0K/2BtPl7xWwxM1rFczc+ydUjzaObvvH8kBk7lMaNZpSG5YyHIZ1LJ8sm jYzu0u4v0pABbrUAxNKvarItTHJpKV9xVBA911b7t11uwqdnpGW7oMgOKlpe/1XYjYG4 k+Y3Od3oqshXkCPWDWQVOmnPmkjpcxrc91WvE= Received: by 10.227.199.80 with SMTP id er16mr7177085wbb.78.1304959467541; Mon, 09 May 2011 09:44:27 -0700 (PDT) Received: from localhost.localdomain (bzq-79-179-43-50.red.bezeqint.net [79.179.43.50]) by mx.google.com with ESMTPS id o23sm2034877wbc.27.2011.05.09.09.44.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 May 2011 09:44:26 -0700 (PDT) From: amir73il@users.sourceforge.net To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Amir Goldstein , Yongqiang Yang Subject: [PATCH RFC 26/30] ext4: snapshot race conditions - tracked reads Date: Mon, 9 May 2011 19:41:44 +0300 Message-Id: <1304959308-11122-27-git-send-email-amir73il@users.sourceforge.net> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1304959308-11122-1-git-send-email-amir73il@users.sourceforge.net> References: <1304959308-11122-1-git-send-email-amir73il@users.sourceforge.net> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Amir Goldstein Wait for pending read I/O requests to complete. When a snapshot file readpage reads through to the block device, the reading task increments the block tracked readers count. Upon completion of the async read I/O request of the snapshot page, the tracked readers count is decremented. When a task is COWing a block with non-zero tracked readers count, that task has to wait (in msleep(1) loop), until the block's tracked readers count drops to zero, before the COW operation is completed. After a pending COW operation has started, reader tasks have to wait (again, in msleep(1) loop), until the pending COW operation is completed, so the COWing task cannot be starved by reader tasks. The sleep loop method was copied from LVM snapshot code, which does the same thing to deal with these (rare) races without wait queues. Signed-off-by: Amir Goldstein Signed-off-by: Yongqiang Yang --- fs/ext4/ext4.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a7bb8ed..bf5aa4d 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2249,12 +2249,18 @@ enum ext4_state_bits { * now used by snapshot to do mow */ BH_Partial_Write, /* Buffer should be uptodate before write */ + BH_Tracked_Read, /* Buffer read I/O is being tracked, + * to serialize write I/O to block device. + * that is, don't write over this block + * until I finished reading it. + */ }; BUFFER_FNS(Uninit, uninit) TAS_BUFFER_FNS(Uninit, uninit) BUFFER_FNS(Remap, remap) BUFFER_FNS(Partial_Write, partial_write) +BUFFER_FNS(Tracked_Read, tracked_read) /* * Add new method to test wether block and inode bitmaps are properly