From patchwork Wed Nov 2 15:04:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepa Dinamani X-Patchwork-Id: 9409329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5EAD46022E for ; Wed, 2 Nov 2016 15:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FA8A2A2F3 for ; Wed, 2 Nov 2016 15:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43EF82A2F7; Wed, 2 Nov 2016 15:05:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAD0F2A2F3 for ; Wed, 2 Nov 2016 15:05:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755945AbcKBPFS (ORCPT ); Wed, 2 Nov 2016 11:05:18 -0400 Received: from mail-yb0-f196.google.com ([209.85.213.196]:35985 "EHLO mail-yb0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755927AbcKBPFQ (ORCPT ); Wed, 2 Nov 2016 11:05:16 -0400 Received: by mail-yb0-f196.google.com with SMTP id d128so331358ybh.3; Wed, 02 Nov 2016 08:05:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xYykfp4+hV4Y6dAyYsPSEJ5tG+OtEhiC1i+sL8ALhAs=; b=n0/6DdCaQ0HJ3lXLToF9/FGdHp5+9CB/P+pdXEwxa0GsDJt/0brNykmnJ9pgRD7q1Z 68ydIzHY8lVsV/URbktJxOgq0G7legOSKpnK0CpVpHKhv0YQ49A82XbKSFSFibK1jkG2 G5U6vu67WR2KovBUneroIYhJ8liZ3LQGgVnct1LEeZy3qBheYteHRNHUM+uADr58J4N8 xoTNxPcqJbJt9aA0ZzEjGNsRYDeUvTlOqqiX29bdmujRAcr+K5IrIqQ+YL33fB9OC+WP hE/skbp2W/FnZGWCmudSi4omc3tPVcvBujQZ5imNn+UEq/abqRUGLZtgjoHzBHtNEm/N 6JNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xYykfp4+hV4Y6dAyYsPSEJ5tG+OtEhiC1i+sL8ALhAs=; b=A4Eyp/KD30bXRQH3LnlY2c3SNrW4gX0yJrZl+V/+mcw4yktPqMG4tkum21tB7y2rUw 8MlsiRyk2rPiRlWpslEmrbPKvlJmIJhDZLXYGp/OUPWHtXEHGTt6GUMzF63xmO4/EwR4 JOSJKnTAEF66Oneh3v1QmmmgQ5pxCIX3G/EQL1jupDy8PkHIufscfWXol0ZWD4KKb2UY BnP5IIV9n4BwiYa2AgzMADpRFqNfupbu7aGD16tfkQCpTjcwZkVAvq4JVndY2UGdPVUX EN9W0u2AmrdBhHWQ+oyLNjceNWB/SbW5lw2Jqkp3cTN3VcIfQlIEG1pUU0RU3CQyTj+3 h38Q== X-Gm-Message-State: ABUngvcCoE3g3xRziUtZZnXttiA25WmytpFp1E0vIWViuxRj7ImSfwmWTe/CE1dfWOJE+w== X-Received: by 10.37.10.199 with SMTP id 190mr1508873ybk.101.1478099115326; Wed, 02 Nov 2016 08:05:15 -0700 (PDT) Received: from deepa-ubuntu.hil-sfecghh.abq.wayport.net (ip-64-134-56-224.public.wayport.net. [64.134.56.224]) by smtp.gmail.com with ESMTPSA id m126sm723358ywf.14.2016.11.02.08.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Nov 2016 08:05:14 -0700 (PDT) From: Deepa Dinamani To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: arnd@arndb.de, tglx@linutronix.de, gregkh@linuxfoundation.org, akpm@linux-foundation.org, tytso@mit.edu, viro@zeniv.linux.org.uk, y2038@lists.linaro.org Subject: [RFC 5/6] vfs: Add timestamp_truncate() api Date: Wed, 2 Nov 2016 08:04:55 -0700 Message-Id: <1478099096-25637-6-git-send-email-deepa.kernel@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1478099096-25637-1-git-send-email-deepa.kernel@gmail.com> References: <1478099096-25637-1-git-send-email-deepa.kernel@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP timespec_trunc() function is used to truncate a filesystem timestamp to the right granularity. But, the function does not clamp tv_sec part of the timestamps according to the filesystem timestamp limits. Also, timespec_trunc() is exclusively used for filesystem timestamps. Move the api to be part of vfs. The replacement api: timestamp_truncate() also alters the signature of the function to accommodate filesystem timestamp clamping according to flesystem limits. Note that clamp_t macro is used for clamping here as vfs is not yet using struct timespec64 internally. This is only for compilation purposes. The actual patch can only be merged after the vfs is transitioned to use timespec64 for correct operation of clamp macro. At which point, clamp_t() will be replaced by clamp(). Signed-off-by: Deepa Dinamani --- fs/inode.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 7b2b78d..f9285f2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2106,6 +2106,36 @@ void inode_nohighmem(struct inode *inode) EXPORT_SYMBOL(inode_nohighmem); /** + * fs_timespec_trunc - Truncate timespec to a granularity + * @t: Timespec + * @gran: Granularity in ns. + * + * Truncate a timespec to a granularity. Always rounds down. gran must + * not be 0 nor greater than a second (NSEC_PER_SEC, or 10^9 ns). + */ +struct timespec timestamp_truncate(struct timespec t, struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + unsigned int gran = sb->s_time_gran; + + t.tv_sec = clamp_t(time64_t, t.tv_sec, sb->s_time_min, sb->s_time_max); + + /* Avoid division in the common cases 1 ns and 1 s. */ + if (gran == 1) { + /* nothing */ + } else if (gran == NSEC_PER_SEC) { + t.tv_nsec = 0; + } else if (gran > 1 && gran < NSEC_PER_SEC) { + t.tv_nsec -= t.tv_nsec % gran; + } else { + WARN(1, "illegal file time granularity: %u", gran); + } + return t; +} +EXPORT_SYMBOL(timestamp_truncate); + + +/** * current_time - Return FS time * @inode: inode. * @@ -2124,6 +2154,6 @@ struct timespec current_time(struct inode *inode) return now; } - return timespec_trunc(now, inode->i_sb->s_time_gran); + return timestamp_truncate(now, inode); } EXPORT_SYMBOL(current_time);