From patchwork Thu Mar 31 18:05:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Duncan X-Patchwork-Id: 8715251 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7CC029F30C for ; Thu, 31 Mar 2016 18:10:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 95AFC202AE for ; Thu, 31 Mar 2016 18:10:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9F00120295 for ; Thu, 31 Mar 2016 18:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756284AbcCaSKI (ORCPT ); Thu, 31 Mar 2016 14:10:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:33435 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752278AbcCaSKG (ORCPT ); Thu, 31 Mar 2016 14:10:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 672C5AD1C; Thu, 31 Mar 2016 18:10:01 +0000 (UTC) Received: by worklaptop.gonzoleeman.net (Postfix, from userid 1000) id A9F8940C56; Thu, 31 Mar 2016 11:05:32 -0700 (PDT) From: Lee Duncan To: , Cc: , , , , Lee Duncan Subject: [PATCH 1/2] target: Make target db location configurable Date: Thu, 31 Mar 2016 11:05:29 -0700 Message-Id: <553cc68ded2c5fcc51bffa1cf0033a7a9c88144f.1459278305.git.lduncan@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit adds the read-write attribute "dbroot", in the top-level CONFIGFS (core) target directory, normally /sys/kernel/config/target. This attribute defaults to "/var/target" but can be changed by writing a new pathname string to it. Target modules that care about the target database root directory will be modified to use this attribute in a future commit. Reviewed-by: Johannnes Thumshirn --- drivers/target/target_core_configfs.c | 31 +++++++++++++++++++++++++++++++ drivers/target/target_core_internal.h | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 713c63d9681b..bfc5a8bb5778 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -99,6 +99,36 @@ static ssize_t target_core_item_version_show(struct config_item *item, CONFIGFS_ATTR_RO(target_core_item_, version); +char db_root[DB_ROOT_LEN] = DB_ROOT_DEFAULT; + +static ssize_t target_core_item_dbroot_show(struct config_item *item, + char *page) +{ + return sprintf(page, "%s\n", db_root); +} + +static ssize_t target_core_item_dbroot_store(struct config_item *item, + const char *page, size_t count) +{ + ssize_t read_bytes; + + if (count > (DB_ROOT_LEN - 1)) { + pr_err("db_root count: %d exceeds DB_ROOT_LEN-1: %u\n", + (int)count, DB_ROOT_LEN - 1); + return -EINVAL; + } + + read_bytes = snprintf(db_root, DB_ROOT_LEN, "%s", page); + if (!read_bytes) + return -EINVAL; + if (db_root[read_bytes - 1] == '\n') + db_root[read_bytes - 1] = '\0'; + + return read_bytes; +} + +CONFIGFS_ATTR(target_core_item_, dbroot); + static struct target_fabric_configfs *target_core_get_fabric( const char *name) { @@ -249,6 +279,7 @@ static struct configfs_group_operations target_core_fabric_group_ops = { */ static struct configfs_attribute *target_core_fabric_item_attrs[] = { &target_core_item_attr_version, + &target_core_item_attr_dbroot, NULL, }; diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 040cf5202e54..c2a18b960c5d 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -156,4 +156,10 @@ void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *); /* target_core_xcopy.c */ extern struct se_portal_group xcopy_pt_tpg; +/* target_core_configfs.c */ +#define DB_ROOT_LEN 4096 +#define DB_ROOT_DEFAULT "/var/target" + +extern char db_root[]; + #endif /* TARGET_CORE_INTERNAL_H */