Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763132AbYJJTSY (ORCPT ); Fri, 10 Oct 2008 15:18:24 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1763538AbYJJTSJ (ORCPT ); Fri, 10 Oct 2008 15:18:09 -0400 Received: from mu-out-0910.google.com ([209.85.134.187]:41071 "EHLO mu-out-0910.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1763118AbYJJTSH convert rfc822-to-8bit (ORCPT ); Fri, 10 Oct 2008 15:18:07 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:x-mailer:mime-version :content-type:content-transfer-encoding; b=mgba9ovkdgW17RzuYAWLmxEj4Get+DOH8jlV1LLxAO9Tln/kX3nhFG2EzH+CxNzond Px845Odho1Xp1YgZrGc216gnGWcQ8P9IjcS627fqNToypc09R4VauiJr2i1eCnP49nEo K3E/GaKMcHQOweuDmoufAFsX8N7k0lokk4eD0= Date: Fri, 10 Oct 2008 21:17:59 +0200 From: dcg To: Nick Piggin Cc: Peter Zijlstra , Hisashi Hifumi , torvalds@linux-foundation.org, Andrew Morton , Andi Kleen , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Aneesh Kumar K.V" , "Theodore Ts'o" Subject: [PATCH] Document file->f_pos as thread-unsafe Message-ID: <20081010211759.630dfb6b@diego-desktop> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.14.3; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1799 Lines: 45 El Fri, 10 Oct 2008 13:25:15 +1100, Nick Piggin escribió: > Note that I don't think we'd want to explicitly guarantee that it is atomic > on 64-bit machines either. It does happen to be, but I don't think we want > anybody to rely on that... Easily fixable. Performance testing of this new version didn't find regressions. Document that it is not safe to play with file->f_pos from multiple processes if they aren't synchronizing themselves. Signed-off-by: Diego Calleja Index: 2.6/include/linux/fs.h =================================================================== --- 2.6.orig/include/linux/fs.h 2008-10-10 21:07:29.000000000 +0200 +++ 2.6/include/linux/fs.h 2008-10-10 21:08:25.000000000 +0200 @@ -821,6 +821,17 @@ atomic_long_t f_count; unsigned int f_flags; mode_t f_mode; + /* + * Linux does NOT guarantee atomic reading/writing to file->f_pos in + * multithreaded apps. There're several reasons for this behaviour: + * - Specifications don't say it must be implemented that way. + * - This behaviour is part of the Linux semantics. + * - Any application that does multithreaded access to file->f_pos + * should be doing its own locking: the processes should synchronize + * themselves when accessing a file descriptor. If an application + * doesn't do that, its file descriptor handling is buggy anyway and + * must be fixed to do its accesses to file->f_pos properly. + */ loff_t f_pos; struct fown_struct f_owner; unsigned int f_uid, f_gid; -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/