From patchwork Tue Aug 24 16:16:19 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B6rn_Jacke?= X-Patchwork-Id: 127271 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7OGGXUN031623 for ; Tue, 24 Aug 2010 16:16:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755184Ab0HXQQd (ORCPT ); Tue, 24 Aug 2010 12:16:33 -0400 Received: from mail1.SerNet.de ([193.175.80.2]:53703 "EHLO mail.SerNet.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755073Ab0HXQQc (ORCPT ); Tue, 24 Aug 2010 12:16:32 -0400 Received: from intern.SerNet.DE by mail.SerNet.DE with esmtp (Exim 4.69 #1) for linux-cifs@vger.kernel.org id 1OnwAo-0008T8-Lh; Tue, 24 Aug 2010 18:16:30 +0200 Received: by intern.SerNet.DE id 1OnwAo-008Rzd-Bd; Tue, 24 Aug 2010 18:16:30 +0200 Received: by intern.SerNet.DE id 1OnwAo-008RzM-4D; Tue, 24 Aug 2010 18:16:30 +0200 Received: from bjacke by pell.sernet.de with local (Exim 4.71) (envelope-from ) id 1OnwAd-0007Cs-Gd for linux-cifs@vger.kernel.org; Tue, 24 Aug 2010 18:16:19 +0200 Date: Tue, 24 Aug 2010 18:16:19 +0200 From: =?iso-8859-1?Q?Bj=F6rn?= JACKE To: linux-cifs@vger.kernel.org Subject: monotonic time for mount.cifs timeouts MIME-Version: 1.0 Content-Disposition: inline Message-Id: Organization: SerNet GmbH, Goettingen, Germany Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 24 Aug 2010 16:16:34 +0000 (UTC) From 4e8d243b9b0a5eb7bf4619c4cddbd9d3a8f4eb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= Date: Tue, 24 Aug 2010 09:41:01 +0200 Subject: [PATCH 2/2] mount.cifs: use monotonic time for timeouts this is especially important during the boot process, where the clock is often being set initially and clock jumps are more common. --- mtab.c | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-) diff --git a/mtab.c b/mtab.c index de1aabd..64e7250 100644 --- a/mtab.c +++ b/mtab.c @@ -39,6 +39,7 @@ #include #include #include "mount.h" +#include "config.h" /* Updating mtab ----------------------------------------------*/ @@ -60,6 +61,22 @@ setlkw_timeout (int sig __attribute__((unused))) { /* nothing, fcntl will fail anyway */ } +/* use monotonic time for timeouts */ +struct timeval +mono_time(void) { + struct timeval ret; +#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) + struct timespec ts; + if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { + ret.tv_sec = ts.tv_sec; + ret.tv_usec = ts.tv_nsec/1000; + return ret; + } +#endif + gettimeofday(&ret,NULL); + return ret; +} + /* Remove lock file. */ void unlock_mtab (void) { @@ -150,7 +167,7 @@ lock_mtab (void) { } close(i); - gettimeofday(&maxtime, NULL); + maxtime = mono_time(); maxtime.tv_sec += MOUNTLOCK_MAXTIME; waittime.tv_sec = 0; @@ -177,7 +194,7 @@ lock_mtab (void) { if (lockfile_fd < 0) { /* Strange... Maybe the file was just deleted? */ - gettimeofday(&now, NULL); + now = mono_time(); if (errno == ENOENT && now.tv_sec < maxtime.tv_sec) { we_created_lockfile = 0; continue; @@ -199,7 +216,7 @@ lock_mtab (void) { (void) unlink(linktargetfile); } else { /* Someone else made the link. Wait. */ - gettimeofday(&now, NULL); + now = mono_time(); if (now.tv_sec < maxtime.tv_sec) { alarm(maxtime.tv_sec - now.tv_sec); if (fcntl (lockfile_fd, F_SETLKW, &flock) == -1) { -- 1.7.1