Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp560735imm; Fri, 14 Sep 2018 02:52:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdawO8na3pgb5zrVDb2QJ8zdoINbXE362AizCAuPomnFQhD/aesydsYNDsTcWk2VXPiItd59 X-Received: by 2002:a63:1f55:: with SMTP id q21-v6mr10822225pgm.88.1536918732138; Fri, 14 Sep 2018 02:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536918732; cv=none; d=google.com; s=arc-20160816; b=jfTwpkwvYz+Ss8QS9cnKwiZn9QRshNeCsljKeRdldr0mD1Z2D35+gu6WemBZ3ElWRn Sa2tIZ/u9KD2Q3BLX1Hc68oN3tQ1pnRn3n1MOm7Kr5mVMJa+viuRF/CcKDypsKrFmsUF V3SSdZs4F3RNXzgv4W10OPZWFJiPXFAcCHIW59LcAPMRgfoS6pwGlbpn7AKGrScWVEFf 4uY1qi/sr+17U2m2/vdTYuPduE+vkGoJ6WgJNhmSAk5gGmD1U4Ix3h6/sS+y0XhH2wdF 1ite5m8+8+pRzIYcgRij10ZmkoKzQiAqYgy0Z/09EQM0WOhDbAVUV81awhYxjSSoM2CM hw4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=7UBpilPnsKaTQPnAbtva6+x1zvWlZWKjPW37uDKpvJI=; b=zZt3MbgRUsw7Ta20XPvHGBGufy/Qb5hGdHGaFlZ0FJgByytfoiuI3Vf2cP7oQQSwzw rGhvxhlgwZLxOZDbTGPOZPCUEpWeNJFJCYXMPWC4mzeA4tB6Wml7b/mNlkpnAc/+jOVt XH90RD5pcvp+QnGLMsi4sPq/MNZ1NeMn0PFbA2yeOX5QVzH2d/1+CUW+67RwwOYLAeH4 n1yqTCKydYRxEHAZayo6DlG7If6qiJQfP7r5RfjYS9JShm+3GePJ+/weXDZGW4HeKRRO 1JNn21Pb+kKcV1Qxf9grsAV7I8odm2jdn3KeN5tg+mSB0kbx/64tqPZcIr2Bpy/sR6Qr tk7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=TIbDPUeQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l63-v6si6896115plb.166.2018.09.14.02.51.56; Fri, 14 Sep 2018 02:52:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=TIbDPUeQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728012AbeINPF0 (ORCPT + 99 others); Fri, 14 Sep 2018 11:05:26 -0400 Received: from m12-11.163.com ([220.181.12.11]:35729 "EHLO m12-11.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726905AbeINPF0 (ORCPT ); Fri, 14 Sep 2018 11:05:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=7UBpilPnsKaTQPnAbt va6+x1zvWlZWKjPW37uDKpvJI=; b=TIbDPUeQGrWWH4fatNMGyXT6RZQuCVf/zI rLaWIyBnpO/6ZCrD7AUyoNmkWp2YEe041vqYwuPMYRqFeIv3DN183v5BfJKg+lyf qqxSoiWuN7mu2fmS1arQ+pK/cu0KoWobArrNguyPvRiJankYHQK2sI42zWsBmxki wavUNr4To= Received: from localhost.localdomain (unknown [117.136.0.171]) by smtp7 (Coremail) with SMTP id C8CowAAHhSqmhJtbfcAgAQ--.41883S4; Fri, 14 Sep 2018 17:51:35 +0800 (CST) From: Dongbo Cao To: colyli@suse.de Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, Dongbo Cao Subject: [PATCH] add label interface for cache device in sysfs Date: Fri, 14 Sep 2018 17:51:20 +0800 Message-Id: <20180914095120.2699-1-cdbdyx@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: C8CowAAHhSqmhJtbfcAgAQ--.41883S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7GrWDZrWxCw1fWryrWF43GFg_yoW8JrWfpF W3W34rWw1kX347Jrn3CF17GaySg3ySya4kWrW2yay8Za4jq3WDC3yFgayY9ryktr45Ca93 Ar18tF45Wa1UWFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j8Xo7UUUUU= X-Originating-IP: [117.136.0.171] X-CM-SenderInfo: xfgev5r06rljoofrz/1tbiJQ-B3FUMM6ZMHgAAsp Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org label interface will be called by bcache tools in user space. Signed-off-by: Dongbo Cao --- drivers/md/bcache/sysfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 225b15aa..e64c718f 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -950,6 +950,13 @@ SHOW(__bch_cache) return ret; } + if (attr == &sysfs_label) { + memcpy(buf, ca->sb.label, SB_LABEL_SIZE); + buf[SB_LABEL_SIZE + 1] = '\0'; + strcat(buf, "\n"); + return strlen(buf); + } + return 0; } SHOW_LOCKED(bch_cache) @@ -993,6 +1000,17 @@ STORE(__bch_cache) atomic_set(&ca->io_errors, 0); } + if (attr == &sysfs_label) { + if (size > SB_LABEL_SIZE) + return -EINVAL; + memcpy(ca->sb.label, buf, size); + if (size < SB_LABEL_SIZE) + ca->sb.label[size] = '\0'; + if (size && ca->sb.label[size - 1] == '\n') + ca->sb.label[size - 1] = '\0'; + bcache_write_super(ca->set); + } + return size; } STORE_LOCKED(bch_cache) @@ -1009,6 +1027,7 @@ static struct attribute *bch_cache_files[] = { &sysfs_io_errors, &sysfs_clear_stats, &sysfs_cache_replacement_policy, + &sysfs_label, NULL }; KTYPE(bch_cache); -- 2.17.1