From patchwork Thu Oct 22 17:27:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 55447 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lf0-f69.google.com (mail-lf0-f69.google.com [209.85.215.69]) by patches.linaro.org (Postfix) with ESMTPS id 9B6D820581 for ; Thu, 22 Oct 2015 17:27:44 +0000 (UTC) Received: by lfu67 with SMTP id 67sf10581635lfu.2 for ; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=GTXB1LQOSUuc2LAL4B939g2uB6U+MX6cfsZ8hTZgWtw=; b=Xd4YGFdCCbEWcaHpmAYdtSkvnnfRjQRibpIcgyP5HUtkJ7L2VscVQc6anSE5CQYIoE /2/zbuSuSxSJo7GkPHH5VBoY7w3p8AgGlW412SQ6aTi7VlmLP3/fjaLR7acDGy79j2E7 ntka2mLZlAQGyFzUM5I8muV051xjFzAtZ1gFKdljRi6Rm0QUDGHEgOQ1RIyudWGai8va c0tZIzBpK3G0Halgs5fI24KL4gZbXgUPTUf38NCtyRkfzXfSYejM15qUHEQscLM3gCZw WjRSos7MlVglG4sIHmsqB0aL2ypXDlO99rCgX7GVa+VJsOBYEXSzyElxrmBd5ryoqAsx GyNw== X-Gm-Message-State: ALoCoQnu9y7f7M1PPCUHvfJU4rcyG7Ou0gJydy/r7Rz2zDNrjjDaeSahoMgarONcEp/290n72+PT X-Received: by 10.112.151.9 with SMTP id um9mr3960066lbb.19.1445534863599; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.88.67 with SMTP id m64ls341280lfb.103.gmail; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) X-Received: by 10.25.20.24 with SMTP id k24mr6045429lfi.117.1445534863459; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) Received: from mail-lf0-x229.google.com (mail-lf0-x229.google.com. [2a00:1450:4010:c07::229]) by mx.google.com with ESMTPS id p189si5649338lfe.138.2015.10.22.10.27.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 10:27:43 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::229 as permitted sender) client-ip=2a00:1450:4010:c07::229; Received: by lffz202 with SMTP id z202so56475705lff.3 for ; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) X-Received: by 10.112.64.72 with SMTP id m8mr8723632lbs.41.1445534863303; Thu, 22 Oct 2015 10:27:43 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.59.35 with SMTP id w3csp733068lbq; Thu, 22 Oct 2015 10:27:42 -0700 (PDT) X-Received: by 10.66.254.7 with SMTP id ae7mr18370093pad.107.1445534862259; Thu, 22 Oct 2015 10:27:42 -0700 (PDT) Received: from mail-pa0-x229.google.com (mail-pa0-x229.google.com. [2607:f8b0:400e:c03::229]) by mx.google.com with ESMTPS id b1si22460684pat.193.2015.10.22.10.27.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Oct 2015 10:27:42 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c03::229 as permitted sender) client-ip=2607:f8b0:400e:c03::229; Received: by padhk11 with SMTP id hk11so92168575pad.1 for ; Thu, 22 Oct 2015 10:27:41 -0700 (PDT) X-Received: by 10.68.98.99 with SMTP id eh3mr18641638pbb.126.1445534861874; Thu, 22 Oct 2015 10:27:41 -0700 (PDT) Received: from localhost.localdomain (c-76-115-103-22.hsd1.or.comcast.net. [76.115.103.22]) by smtp.gmail.com with ESMTPSA id ce3sm14808615pbb.35.2015.10.22.10.27.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Oct 2015 10:27:41 -0700 (PDT) From: John Stultz To: linux-kernel@vger.kernel.org Cc: San Mehat , Jens Axboe , Rom Lemarchand , Android Kernel Team , Dima Zavin , John Stultz Subject: [PATCH] block: genhd: Add disk/partition specific uevent callbacks for partition info Date: Thu, 22 Oct 2015 10:27:32 -0700 Message-Id: <1445534852-7456-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2a00:1450:4010:c07::229 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=pass header.i=@linaro_org.20150623.gappssmtp.com Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: San Mehat This patch has been carried in the Android tree for quite some time and is one of the few patches required to get a mainline kernel up and running with an exsiting Android userspace. So I wanted to submit it for review and consideration if it should be merged. For disk devices, a new uevent parameter 'NPARTS' specifies the number of partitions detected by the kernel. Partition devices get 'PARTN' which specifies the partitions index in the table, and 'PARTNAME', which specifies PARTNAME specifices the partition name of a partition device Android's userspace uses this for creating device node links from the partition name and number: ie: /dev/block/platform/soc/by-name/system or /dev/block/platform/soc/by-num/p1 One can see its usage here: https://android.googlesource.com/platform/system/core/+/master/init/devices.cpp#355 and https://android.googlesource.com/platform/system/core/+/master/init/devices.cpp#494 Thoughts and feedback would be greatly appreciated! Cc: Jens Axboe Cc: Rom Lemarchand Cc: Android Kernel Team Signed-off-by: Dima Zavin [jstultz: Added more context to commit message & whitespace fix] Signed-off-by: John Stultz --- block/genhd.c | 17 +++++++++++++++++ block/partition-generic.c | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 0c706f3..248139e 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1115,6 +1115,22 @@ static void disk_release(struct device *dev) blk_put_queue(disk->queue); kfree(disk); } + +static int disk_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + struct gendisk *disk = dev_to_disk(dev); + struct disk_part_iter piter; + struct hd_struct *part; + int cnt = 0; + + disk_part_iter_init(&piter, disk, 0); + while ((part = disk_part_iter_next(&piter))) + cnt++; + disk_part_iter_exit(&piter); + add_uevent_var(env, "NPARTS=%u", cnt); + return 0; +} + struct class block_class = { .name = "block", }; @@ -1134,6 +1150,7 @@ static struct device_type disk_type = { .groups = disk_attr_groups, .release = disk_release, .devnode = block_devnode, + .uevent = disk_uevent, }; #ifdef CONFIG_PROC_FS diff --git a/block/partition-generic.c b/block/partition-generic.c index e771113..e5d91c9 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -216,10 +216,21 @@ static void part_release(struct device *dev) kfree(p); } +static int part_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + struct hd_struct *part = dev_to_part(dev); + + add_uevent_var(env, "PARTN=%u", part->partno); + if (part->info && part->info->volname[0]) + add_uevent_var(env, "PARTNAME=%s", part->info->volname); + return 0; +} + struct device_type part_type = { .name = "partition", .groups = part_attr_groups, .release = part_release, + .uevent = part_uevent, }; static void delete_partition_rcu_cb(struct rcu_head *head)