From patchwork Wed Oct 3 12:42:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1541391 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 2879EDFF71 for ; Wed, 3 Oct 2012 12:43:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452Ab2JCMnB (ORCPT ); Wed, 3 Oct 2012 08:43:01 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:45988 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753057Ab2JCMnA (ORCPT ); Wed, 3 Oct 2012 08:43:00 -0400 Received: by ggnr5 with SMTP id r5so1928603ggn.19 for ; Wed, 03 Oct 2012 05:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=0JC1FTxMAI0fyt64x1/cCzu9xHo9yRJxVMjnzxVUxvY=; b=bH4kGTpda4P0R7j6xiXSZn3eaiPyyOVKPEOO9lp/YgnyYj9AdfVVGK7fOyNcuTxThp 7zsJrIbSx1z8ztco7t14jH2sc+Eyi1swxlxXl3xpELRpPR+O8qxJeZk+BhZqpGJPfpaL kfA750UzbAg9fwbFuGRlV4AIpDI03yAFZZc4O2T8Wx2Ccg/LcXJ72YceLaEC4YHrDmqb 0Vbq+sbFybYIVM0z1fdLWdgr/x1z08zKS1U2eljPs+oRucYdx6+w57wkheMwiGummDui aFN5e7GkKW/qvkR4httc/6gsj+dUQOBpcThzgZLCiAyBe7qNuNu74tQlDyiEOjp3xyEc aoPA== Received: by 10.236.114.200 with SMTP id c48mr1558727yhh.118.1349268179855; Wed, 03 Oct 2012 05:42:59 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id w1sm3762386anm.8.2012.10.03.05.42.58 (version=SSLv3 cipher=OTHER); Wed, 03 Oct 2012 05:42:59 -0700 (PDT) From: Jeff Layton To: steved@redhat.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism Date: Wed, 3 Oct 2012 08:42:53 -0400 Message-Id: <1349268173-16574-1-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1349092365-23920-1-git-send-email-jlayton@redhat.com> References: <1349092365-23920-1-git-send-email-jlayton@redhat.com> X-Gm-Message-State: ALoCoQnYDDFqKC28M9L4vN/j+7Wv8SSSGsc1K24BVN2M1H/HW/WbMS76UEnhSCo9+Wr6aSL94t3r Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If the kernel passes the legacy recdir path in the environment, then we can use that to transition from the old legacy tracker to the new one. On a "check" operation, if there is no record of the client in the database, check to see if there is a matching recoverydir. If there isn't then just refuse the reclaim. If there is, then insert a new record for this client into the db, and remove the legacy recoverydir. If either of those operations fail, then refuse the reclaim. On a "gracedone" operation, clean out the entire legacy recoverydir after purging any unreclaimed records from the db. There's not much we can do if this fails, so just log a warning if it does. Note that this is a one-way conversion. If the user later boots back into an older kernel, it will have no knowledge of the new database. In principle, we could create a tool that would walk the clients table, md5 hash the clientids and create directories in the v4recovery dir. Trying to do that automatically would be a mess though... Signed-off-by: Jeff Layton --- utils/nfsdcltrack/nfsdcltrack.c | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/utils/nfsdcltrack/nfsdcltrack.c b/utils/nfsdcltrack/nfsdcltrack.c index db7e534..7c2625a 100644 --- a/utils/nfsdcltrack/nfsdcltrack.c +++ b/utils/nfsdcltrack/nfsdcltrack.c @@ -36,6 +36,7 @@ #include #include #include +#include #ifdef HAVE_SYS_CAPABILITY_H #include #include @@ -296,6 +297,50 @@ cltrack_remove(const char *id) } static int +cltrack_check_legacy(const unsigned char *blob, const ssize_t len) +{ + int ret; + char *recdir; + struct stat st; + + /* see if the legacy recdir exists */ + recdir = getenv("NFSDCLTRACK_LEGACY_RECDIR"); + if (!recdir) { + xlog(D_GENERAL, "No NFSDCLTRACK_LEGACY_RECDIR env var"); + return -EOPNOTSUPP; + } + + /* fail recovery on any stat failure */ + ret = stat(recdir, &st); + if (ret) { + xlog(D_GENERAL, "Unable to stat %s: %d", recdir, errno); + return -errno; + } + + /* fail if it isn't a directory */ + if (!S_ISDIR(st.st_mode)) { + xlog(D_GENERAL, "%s is not a directory: mode=0%o", recdir + , st.st_mode); + return -ENOTDIR; + } + + /* Dir exists, try to insert record into db */ + ret = sqlite_insert_client(blob, len); + if (ret) { + xlog(D_GENERAL, "Failed to insert client: %d", ret); + return -EREMOTEIO; + } + + /* remove the legacy recoverydir */ + ret = rmdir(recdir); + if (ret) { + xlog(D_GENERAL, "Failed to rmdir %s: %d", recdir, errno); + return -errno; + } + return 0; +} + +static int cltrack_check(const char *id) { int ret; @@ -312,10 +357,50 @@ cltrack_check(const char *id) return (int)len; ret = sqlite_check_client(blob, len); + if (ret) + ret = cltrack_check_legacy(blob, len); return ret ? -EPERM : ret; } +/* Clean out the v4recoverydir -- best effort here */ +static void +cltrack_legacy_gracedone(void) +{ + char *dirname = getenv("NFSDCLTRACK_LEGACY_TOPDIR"); + DIR *v4recovery; + struct dirent *entry; + + if (!dirname) + return; + + v4recovery = opendir(dirname); + if (!v4recovery) + return; + + while ((entry = readdir(v4recovery))) { + int len; + + /* borrow the clientid blob for this */ + len = snprintf((char *)blob, sizeof(blob), "%s/%s", dirname, + entry->d_name); + + /* if there's a problem, then skip this entry */ + if (len < 0 || (size_t)len >= sizeof(blob)) { + xlog(L_WARNING, "%s: unable to build filename for %s!", + __func__, entry->d_name); + continue; + } + + len = rmdir((char *)blob); + if (len) + xlog(L_WARNING, "%s: unable to rmdir %s: %d", __func__, + (char *)blob, len); + } + + closedir(v4recovery); +} + static int cltrack_gracedone(const char *timestr) { @@ -343,6 +428,8 @@ cltrack_gracedone(const char *timestr) ret = sqlite_remove_unreclaimed(gracetime); + cltrack_legacy_gracedone(); + return ret ? -EREMOTEIO : ret; }