From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753754AbcLIJiL (ORCPT ); Fri, 9 Dec 2016 04:38:11 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:48066 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752376AbcLIJiI (ORCPT ); Fri, 9 Dec 2016 04:38:08 -0500 Date: Fri, 9 Dec 2016 10:35:20 +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: <20161202220702.GA31213@amt.cnet> Message-ID: References: <20161130154809.GA27444@amt.cnet> <20161130220530.GG35583@linux.intel.com> <20161201145541.GA19232@amt.cnet> <20161202220702.GA31213@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 Fri, 2 Dec 2016, Marcelo Tosatti wrote: > Actually, using flock(2) allows one to use LOCK_SH for readers and > this allows consistent writer/reader behaviour (say, a reader > won't see a partially written directory). Indeed. > So the procedure would be: > > /var/lock/resctrl/fs.lock created previously in the filesystem. > > WRITE LOCK: > > A) Take flock(EXCLUSIVE) on /var/lock/resctrl/fs.lock > B) If success, write pid of the program to the file. > C) read/write the directory structure. > D) funlock > > READ LOCK: > > A) Take flock(SHARED) on /var/lock/resctrl/fs.lock > B) If success read the directory structure. > C) funlock > > > How about that? Looks sane. Adding a small example in C and [ba]sh would be nice. Thanks, tglx