Re: [PATCH v2] intelrdt: resctrl: recommend locking for resctrlfs

From: Thomas Gleixner
Date: Fri Dec 09 2016 - 04:38:14 EST


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