Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2953881imm; Thu, 24 May 2018 19:48:43 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpirw/MGk+ESNY18uPOATUhzMB7L3y8kBqhVtQeGbKwwuWAh4FDPaoepIXOk3rzTVBD07EC X-Received: by 2002:a63:9d8e:: with SMTP id i136-v6mr481932pgd.288.1527216523000; Thu, 24 May 2018 19:48:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216522; cv=none; d=google.com; s=arc-20160816; b=NLAyEayp/WIjKQAoLjmL1lVgPilAW355cLZrlpWP2b536+UcYM9cUp72qOwY4jjDhj mNeNobxfth8hCBQWWxLNxgnPwCBi+b1s6FqijdSKSFwAxX2lZ7N3ifvs/YjbqScaBwTI 0s9O14Hdmt7mZioL/jnlwxTtUN8u+kOJBxlevGPXpCLw+skA2frXCQBwPCO6DDFNtrIv By43WkX29s1mvf9uMFY+NpagrrJD2XBeqDgAfTsI1x4Oa8sS+IMRCD+Va5w8UDb+Gtgo nSqXbrIO9sFIwb0ww9KBc7FwwXWYQ0fiDBxRw70xnmxCr1KwKLShwEI2etanVrsP8F86 KudQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=d9k/VhlUlpv37o/huAY+7P5+5snf3LhyWR/2ZNPG6IM=; b=U+CP334upbYeasL4IM0dtas6KumCcUQ9eEpFijWj5Awt08xf+eByvbGhWOZOfaMlzI ITjlMdcxe9CDR7cngy8nmqnmCr8ruRwMNt8OQv0Tc52CvfP5Y7dj1HCijzSxkaJWpNPX KXY+sQ73KJqZwxSVoJJLusB1X30xvMfeOwXnGgIBIthpQjbsK5D8W/dZyAvNWpfgq1CK NADkmOGAL+jf2Nb+nnrZNAgJ0klvbvheIZAky0KknLf4XHtEYnqc71VBwfsOCCacj34p 6AEX83K5XALIKmKfFWIhwp9/tmThjuH7nj1PHOhesvZVEx4v9H343K/NA2kef9AkYNr5 WoTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x14-v6si17904988pgq.512.2018.05.24.19.48.28; Thu, 24 May 2018 19:48:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971909AbeEYAIY (ORCPT + 99 others); Thu, 24 May 2018 20:08:24 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:59702 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965178AbeEYAIU (ORCPT ); Thu, 24 May 2018 20:08:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 182D8859A9; Fri, 25 May 2018 00:08:20 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-255.rdu2.redhat.com [10.10.120.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id 567382026E0E; Fri, 25 May 2018 00:08:19 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 27/32] vfs: Use a 'struct fd_cookie *' type for light fd handling [ver #8] From: David Howells To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org Date: Fri, 25 May 2018 01:08:18 +0100 Message-ID: <152720689885.9073.2472504465486115237.stgit@warthog.procyon.org.uk> In-Reply-To: <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> References: <152720672288.9073.9868393448836301272.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 25 May 2018 00:08:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 25 May 2018 00:08:20 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use a 'struct fd_cookie *' type for light fd handling rather than an unsigned long so that confusion doesn't arise with integer fd numbers. I have a use case where I want to store this in struct nameidata, but don't want to expand it to a struct fd to save space. Signed-off-by: David Howells --- fs/file.c | 20 +++++++++++--------- include/linux/file.h | 31 ++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/fs/file.c b/fs/file.c index 7ffd6e9d103d..8b0012ddadad 100644 --- a/fs/file.c +++ b/fs/file.c @@ -727,7 +727,7 @@ EXPORT_SYMBOL(fget_raw); * The fput_needed flag returned by fget_light should be passed to the * corresponding fput_light. */ -static unsigned long __fget_light(unsigned int fd, fmode_t mask) +static struct fd_cookie *__fget_light(unsigned int fd, fmode_t mask) { struct files_struct *files = current->files; struct file *file; @@ -736,33 +736,35 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask) file = __fcheck_files(files, fd); if (!file || unlikely(file->f_mode & mask)) return 0; - return (unsigned long)file; + return (struct fd_cookie *)file; } else { file = __fget(fd, mask); if (!file) return 0; - return FDPUT_FPUT | (unsigned long)file; + return (struct fd_cookie *)(FDPUT_FPUT | (unsigned long)file); } } -unsigned long __fdget(unsigned int fd) + +struct fd_cookie *__fdget(unsigned int fd) { return __fget_light(fd, FMODE_PATH); } EXPORT_SYMBOL(__fdget); -unsigned long __fdget_raw(unsigned int fd) +struct fd_cookie *__fdget_raw(unsigned int fd) { return __fget_light(fd, 0); } -unsigned long __fdget_pos(unsigned int fd) +struct fd_cookie *__fdget_pos(unsigned int fd) { - unsigned long v = __fdget(fd); - struct file *file = (struct file *)(v & ~3); + struct fd_cookie *v = __fdget(fd); + struct file *file = __fdfile(v); if (file && (file->f_mode & FMODE_ATOMIC_POS)) { if (file_count(file) > 1) { - v |= FDPUT_POS_UNLOCK; + v = (struct fd_cookie *) + ((unsigned long)v | FDPUT_POS_UNLOCK); mutex_lock(&file->f_pos_lock); } } diff --git a/include/linux/file.h b/include/linux/file.h index 279720db984a..3fce1c92b576 100644 --- a/include/linux/file.h +++ b/include/linux/file.h @@ -11,6 +11,7 @@ #include struct file; +struct fd_cookie; /* Deliberately undefined structure */ extern void fput(struct file *); @@ -31,8 +32,24 @@ struct fd { struct file *file; unsigned int flags; }; -#define FDPUT_FPUT 1 -#define FDPUT_POS_UNLOCK 2 +#define FDPUT_FPUT 1 +#define FDPUT_POS_UNLOCK 2 +#define FDPUT__MASK 3 + +static inline unsigned long __fdflags(struct fd_cookie *f) +{ + return (unsigned long)f & FDPUT__MASK; +} + +static inline struct file *__fdfile(struct fd_cookie *f) +{ + return (struct file *)((unsigned long)f & ~FDPUT__MASK); +} + +static inline void __fdput(struct fd_cookie *f) +{ + fput_light(__fdfile(f), __fdflags(f) & FDPUT_FPUT); +} static inline void fdput(struct fd fd) { @@ -42,14 +59,14 @@ static inline void fdput(struct fd fd) extern struct file *fget(unsigned int fd); extern struct file *fget_raw(unsigned int fd); -extern unsigned long __fdget(unsigned int fd); -extern unsigned long __fdget_raw(unsigned int fd); -extern unsigned long __fdget_pos(unsigned int fd); +extern struct fd_cookie * __fdget(unsigned int fd); +extern struct fd_cookie *__fdget_raw(unsigned int fd); +extern struct fd_cookie *__fdget_pos(unsigned int fd); extern void __f_unlock_pos(struct file *); -static inline struct fd __to_fd(unsigned long v) +static inline struct fd __to_fd(struct fd_cookie *v) { - return (struct fd){(struct file *)(v & ~3),v & 3}; + return (struct fd){__fdfile(v), __fdflags(v)}; } static inline struct fd fdget(unsigned int fd)