From patchwork Fri Apr 6 15:37:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Duncan X-Patchwork-Id: 10327183 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 AAFB960208 for ; Fri, 6 Apr 2018 15:37:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CCA02847D for ; Fri, 6 Apr 2018 15:37:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91ABE2853A; Fri, 6 Apr 2018 15:37:49 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 E98782847D for ; Fri, 6 Apr 2018 15:37:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753079AbeDFPhs (ORCPT ); Fri, 6 Apr 2018 11:37:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:57742 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753068AbeDFPhq (ORCPT ); Fri, 6 Apr 2018 11:37:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id BAB6AAD95; Fri, 6 Apr 2018 15:37:44 +0000 (UTC) From: Lee Duncan To: Linux SCSI , Target Development , Christoph Hellwig Cc: nab@linux-scsi.org, hare@suse.de, Lee Duncan Subject: [PATCH] target: prefer dbroot of /etc/target over /var/target Date: Fri, 6 Apr 2018 08:37:17 -0700 Message-Id: <20180406153717.7523-1-lduncan@suse.com> X-Mailer: git-send-email 2.13.6 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The target database root directory, dbroot, has defaulted to /var/target for a while, but its main client, targetcli-fb, has been moving it to /etc/target for quite some time. With the plethora of target drivers now appearing, it has become more difficult to initialize this attribute before use by any child drivers. If the directory /etc/target exists, use that as the DB root. Otherwise, fall back to using /var/target. The ability to override this dbroot attribute still exists via sysfs. Signed-off-by: Lee Duncan --- drivers/target/target_core_configfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c index 3f4bf126eed0..5ccef7d597fa 100644 --- a/drivers/target/target_core_configfs.c +++ b/drivers/target/target_core_configfs.c @@ -155,6 +155,8 @@ static ssize_t target_core_item_dbroot_store(struct config_item *item, mutex_unlock(&g_tf_lock); + pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root); + return read_bytes; } @@ -3213,6 +3215,27 @@ void target_setup_backend_cits(struct target_backend *tb) target_core_setup_dev_stat_cit(tb); } +static void target_init_dbroot(void) +{ + struct file *fp; + + snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED); + fp = filp_open(db_root_stage, O_RDONLY, 0); + if (IS_ERR(fp)) { + pr_err("db_root: cannot open: %s\n", db_root_stage); + return; + } + if (!S_ISDIR(file_inode(fp)->i_mode)) { + filp_close(fp, NULL); + pr_err("db_root: not a valid directory: %s\n", db_root_stage); + return; + } + filp_close(fp, NULL); + + strncpy(db_root, db_root_stage, DB_ROOT_LEN); + pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root); +} + static int __init target_core_init_configfs(void) { struct configfs_subsystem *subsys = &target_core_fabrics; @@ -3293,6 +3316,8 @@ static int __init target_core_init_configfs(void) if (ret < 0) goto out; + target_init_dbroot(); + return 0; out: