From patchwork Mon Oct 29 17:02:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1664681 Return-Path: X-Original-To: patchwork-cifs-client@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 9C0D7DFB7A for ; Mon, 29 Oct 2012 17:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753068Ab2J2RC6 (ORCPT ); Mon, 29 Oct 2012 13:02:58 -0400 Received: from mail-yh0-f46.google.com ([209.85.213.46]:54412 "EHLO mail-yh0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753436Ab2J2RC5 (ORCPT ); Mon, 29 Oct 2012 13:02:57 -0400 Received: by mail-yh0-f46.google.com with SMTP id m54so944690yhm.19 for ; Mon, 29 Oct 2012 10:02:56 -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=t+PQGnKDBzQt1VEEEq4UyIAfoV/9jAvaTQjwGnFJFqk=; b=IqTH1s9MSylkAMZSv5N+RdQc8bRRCN6IEStTdOT2YCs3nrcAM667Q3C6w6rSLKW8Um ao1sn25pVMtb56g//61PUnnkZxdjbp0O7XLrzbLG7hxFhqS4JQMJdxDdlD8eavRs8BC5 huBMI7t/SGBIRSHXHUYV23rb8jypcqvU23G1WsqN8nqFc6EjgdUGtf5Q/z8mJUEaDlud uk8AW0QLFxGeFvgjr5Pv7KyhssUZj2dp/rOBdI231ue1alBwRhJflWhU11eXp6lYdDv+ xDJiYBcctRTrSeIWlQpcpZHUqUrDv4+Bdav7Z+mfZudS9x7vMrWkFynJRoA6BepZt/P/ Wr6A== Received: by 10.236.35.131 with SMTP id u3mr30539166yha.12.1351530176600; Mon, 29 Oct 2012 10:02:56 -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 j8sm9038013ann.3.2012.10.29.10.02.54 (version=SSLv3 cipher=OTHER); Mon, 29 Oct 2012 10:02:55 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCH v2 6/7] cifs.idmap: set a timeout on keys that it instantiates Date: Mon, 29 Oct 2012 13:02:48 -0400 Message-Id: <1351530168-17619-1-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351336822-16425-7-git-send-email-jlayton@samba.org> References: <1351336822-16425-7-git-send-email-jlayton@samba.org> X-Gm-Message-State: ALoCoQktn5LbyufIYGMtYF834Xq2FniQxKA2SsvtWDlHfTB0Ak9fexMO6iISFYPfPYd0fkhAacJa Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org ...and add a command-line option to allow the admin to tune that value. I think this is a better way to handle this instead of trying to set the timeouts in kernel space. Signed-off-by: Jeff Layton --- cifs.idmap.8.in | 7 ++++++- cifs.idmap.c | 25 +++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/cifs.idmap.8.in b/cifs.idmap.8.in index efec7b6..152046b 100644 --- a/cifs.idmap.8.in +++ b/cifs.idmap.8.in @@ -22,7 +22,7 @@ cifs.idmap \- Userspace helper for mapping ids for Common Internet File System (CIFS) .SH "SYNOPSIS" .HP \w'\ 'u -cifs\&.idmap [\-\-version|\-v] {keyid} +cifs.idmap [--timeout|-t] [--version|-v] {keyid} .SH "DESCRIPTION" .PP This tool is part of the cifs-utils suite\&. @@ -46,6 +46,11 @@ cifs\&.idmap works in conjuction with winbind facility of Samba suite to map own In case winbind and cifs.idmap facilities are unavailable, file objects in a mounted share are assigned uid and gid of the credentials of the process that mounted the share\&. So it is strongly recomemended to use mount options of uid and gid to specify a default uid and gid to map owner SIDs and group SIDs respectively in case services of winbind and cifs.idmap facility are unavailable\&. .SH "OPTIONS" .PP +--timeout|-t +.RS 4 +Set the expiration timer, in seconds on the key. The default is 600 seconds (10 minutes). Setting this to 0 will cause the key to never expire. +.RE +.PP \-\-version|\-v .RS 4 Print version number and exit\&. diff --git a/cifs.idmap.c b/cifs.idmap.c index 9639070..109d6b1 100644 --- a/cifs.idmap.c +++ b/cifs.idmap.c @@ -45,6 +45,7 @@ static const char *prog = "cifs.idmap"; static const struct option long_options[] = { + {"timeout", 1, NULL, 't'}, {"version", 0, NULL, 'v'}, {NULL, 0, NULL, 0} }; @@ -218,23 +219,35 @@ cifs_idmap_ret: int main(const int argc, char *const argv[]) { int c; - long rc = 1; + long rc; key_serial_t key = 0; char *buf; + unsigned int timeout = 600; /* default idmap cache timeout */ openlog(prog, 0, LOG_DAEMON); - while ((c = getopt_long(argc, argv, "v", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "t:v", long_options, NULL)) != -1) { switch (c) { + case 't': + rc = str_to_uint(optarg, &timeout); + if (rc) { + syslog(LOG_ERR, "bad timeout value %s: %s", + optarg, strerror(rc)); + goto out; + } + break; case 'v': + rc = 0; printf("version: %s\n", VERSION); goto out; default: + rc = EINVAL; syslog(LOG_ERR, "unknown option: %c", c); goto out; } } + rc = 1; /* is there a key? */ if (argc <= optind) { usage(); @@ -250,6 +263,14 @@ int main(const int argc, char *const argv[]) goto out; } + /* set timeout on key */ + rc = keyctl_set_timeout(key, timeout); + if (rc == -1) { + syslog(LOG_ERR, "unable to set key timeout: %s", + strerror(errno)); + goto out; + } + rc = keyctl_describe_alloc(key, &buf); if (rc == -1) { syslog(LOG_ERR, "keyctl_describe_alloc failed: %s",