From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bombadil.infradead.org ([65.50.211.133]:37677 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751310AbeBHQCd (ORCPT ); Thu, 8 Feb 2018 11:02:33 -0500 Date: Thu, 8 Feb 2018 08:02:28 -0800 From: Matthew Wilcox To: Kirill Tkhai Cc: akpm@linux-foundation.org, jack@suse.cz, amir73il@gmail.com, linux-fsdevel@vger.kernel.org, gorcunov@virtuozzo.com Subject: Re: [PATCH] inotify: Extend ioctl to allow to request id of new watch descriptor Message-ID: <20180208160228.GE15846@bombadil.infradead.org> References: <151810242614.30935.12876744458891870220.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <151810242614.30935.12876744458891870220.stgit@localhost.localdomain> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Thu, Feb 08, 2018 at 06:07:37PM +0300, Kirill Tkhai wrote: > The new code is under CONFIG_CHECKPOINT_RESTORE #define, so small system > may exclude it. The only change in generic inotify part is idr_alloc_cyclic() > end argument. We had 0 there, and idr subsystem replaced it with INT_MAX > in idr_get_free(). So, the max possible id was INT_MAX (see idr_get_free() > again). > > Since I need INOTIFY_IDR_END to check ioctl's third argument, it's better > it's defined as positive number. But when not-zero value is passed > to idr_get_free(), this function decrements it. Also, idr_alloc_cyclic() > defined @end as int argument. So, it's impossible to pass positive @end > argument to idr_alloc_cyclic() to get INT_MAX id. And after this patch > inotify watch descriptors ids will take numbers [1, INT_MAX-1], INT_MAX > will be unavailable. Ummm. Why not just do: +#ifdef CONFIG_CHECKPOINT_RESTORE + case INOTIFY_IOC_SETNEXTWD: + ret = -EINVAL; + if (arg >= 1 && arg <= INT_MAX) { + spin_lock(&data->idr_lock); + idr_set_cursor(&data->idr, (unsigned int)arg); + spin_unlock(&data->idr_lock); + ret = 0; + } + break; +#endif /* CONFIG_CHECKPOINT_RESTORE */