From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759240AbcLBLXs (ORCPT ); Fri, 2 Dec 2016 06:23:48 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:59786 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753159AbcLBLXr (ORCPT ); Fri, 2 Dec 2016 06:23:47 -0500 Date: Fri, 2 Dec 2016 12:20:29 +0100 (CET) From: Thomas Gleixner To: Marcelo Tosatti cc: Fenghua Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] intelrdt: resctrl: recommend locking for resctrlfs In-Reply-To: <20161201145541.GA19232@amt.cnet> Message-ID: References: <20161130154809.GA27444@amt.cnet> <20161130220530.GG35583@linux.intel.com> <20161201145541.GA19232@amt.cnet> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 1 Dec 2016, Marcelo Tosatti wrote: > > There is a locking problem between different applications > reading/writing to resctrlfs directory at the same time (read the patch > below for details). > > Suggest a standard locking scheme for applications to use. .... > +To coordinate atomic operations on resctrl and avoid the problem > +above, the following locking procedure is recommended: > + > +A) open /var/lock/resctrl/fs.lock with O_CREAT|O_EXCL. > +B) if success, write pid of program accessing the directory > + structure to this file. > +C) read/write the directory structure. > +D) remove file. What's wrong with using flock, which works from shell scripts as well? Thanks, tglx