From: Nao Nishijima <nao.nishijima.xt@hitachi.com>
To: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Cc: James.Bottomley@HansenPartnership.com, kay.sievers@vrfy.org,
jcm@redhat.com, greg@kroah.com,
dle-develop@lists.sourceforge.net,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
yrl.pp-manager.tt@hitachi.com, dgilbert@interlog.com,
stefanr@s5r6.in-berlin.de, hare@suse.de
Subject: [RFC PATCH 0/4] Persistent device name using alias name
Date: Fri, 08 Jul 2011 17:45:47 +0900 [thread overview]
Message-ID: <20110708084547.2091.55262.stgit@ltc197.sdl.hitachi.co.jp> (raw)
Hi,
This patch series provides an "alias name" of the disk into kernel and procfs
messages. The user can assign a preferred name to an alias name of the device.
Based on previous discussion (*), I changed patches as follows
- This is "alias name"
- An "alias name" is stored in gendisk struct
- Add document to Documentation/ABI/testing/sysfs-block
- When the user changes an "alias name", kernel notifies udev
(*) http://marc.info/?l=linux-scsi&m=130812625531219&w=2
How to use:
1. Build and install the kernel with this series, and reboot with the kernel.
2. Check device names.
[localhost]# cat /proc/partitions
major minor #blocks name
8 0 12582912 sda
8 1 12582878 sda1
8 0 8388608 sdb
8 1 512000 sdb1
8 2 7875584 sdb2
3. Make a script of get alias_name
[localhost]# vi /lib/udev/get_alias_name
#!/bin/sh -e
DEVNAME=`echo $1 | sed -e 's/[0-9]//g'`
echo "ALIAS=`cat /sys/block/$DEVNAME/alias_name`"
exit 0
And you should set an execute bit,
[localhost]# chmod +x /lib/udev/get_alias_name
4. Check disk's id
Here is an example to get the serial id and the path of the device.
Some devices have not the serial id. Therefore, to identify a device,
users need to get the path of the device.
[localhost]# udevadm info --query=property --path=/sys/block/sda \
| grep ID_SERIAL=
ID_SERIAL=0QEMU_QEMU_HARDDISK_drive-scsi0-0-1
or you can also use the path of the device
[localhost]# udevadm info --query=property --path=/sys/block/sr0 \
| grep ID_PATH=
ID_PATH=pci-0000:00:01.1-scsi-1:0:0:0
5. Write udev rules as follows
(The user assigns "foo" to sda and "bar" to sr0)
We use ENV{ID_SERIAL} or ENV{ID_PATH} (get by 3) to identify a disk.
And to assign automatically an "alias name", we use ATTR key.
If ENV{ALIAS} is empty, we use to get an "alias_name" by get_alias_name script.
[localhost]# vi /etc/udev/rules.d/70-alias_name.rules
SUBSYSTEM!="block", GOTO="end"
# write alias name for sdX
KERNEL=="sd*[!0-9]", ACTION=="add", ATTR{alias_name}="foo", \
ENV{ID_SERIAL}=="0QEMU_QEMU_HARDDISK_drive-scsi0-0-1"
# write alias name for srX
KERNEL=="sr[0-9]", ACTION=="add", ATTR{alias_name}="bar", \
ENV{ID_PATH}=="pci-0000:00:01.1-scsi-1:0:0:0"
# make symlink
ENV{DEVTYPE}=="disk", ENV{ALIAS}=="?*", SYMLINK+="disk/by-alias/$env{ALIAS}"
ENV{DEVTYPE}=="partition", ENV{ALIAS}=="", \
IMPORT{program}="/lib/udev/get_alias_name %k"
ENV{DEVTYPE}=="partition", ENV{ALIAS}=="?*", \
SYMLINK+="disk/by-alias/$env{ALIAS}%n"
LABEL="end"
6. reboot
After reboot, we can see alias name in kernel and procfs messages.
[localhost]# ls -l /dev/disk/by-alias/
total 0
lrwxrwxrwx. 1 root root 9 Jul 1 21:21 bar -> ../../sr0
lrwxrwxrwx. 1 root root 9 Jul 1 21:21 foo -> ../../sda
lrwxrwxrwx. 1 root root 10 Jul 1 21:21 foo1 -> ../../sda1
[localhost]# dmesg
...
sd 2:0:1:0: [sda] Attached SCSI disk
alias_name: assigned foo to sda
EXT4-fs (foo1): warning: maximal mount count reached, running e2fsck is recommended
EXT4-fs (foo1): mounted filesystem with ordered data mode. Opts: (null)
...
[localhost]# cat /proc/partitions
major minor #blocks name
8 0 12582912 foo
8 1 12582878 foo1
8 0 8388608 sdb
8 1 512000 sdb1
8 2 7875584 sdb2
When a new device is added, the udev appends a new rule manually.
In the future, it is appended automatically, as like NIC.
TODO:
- Modify blkid to show "alias name"
Best Regards,
---
Nao Nishijima (4):
sd: cleanup for alias name
fs: modify disk_name() for alias name
sd: modify printk for alias_name
block: add a new attribute "alias name" in gendisk structure
Documentation/ABI/testing/sysfs-block | 15 ++++++
block/genhd.c | 85 +++++++++++++++++++++++++++++++++
drivers/scsi/sd.c | 7 ++-
drivers/scsi/sd.h | 2 -
fs/partitions/check.c | 6 +-
include/linux/genhd.h | 4 ++
include/scsi/scsi_device.h | 3 +
7 files changed, 114 insertions(+), 8 deletions(-)
--
Nao Nishijima (nao.nishijima.xt@hitachi.com)
next reply other threads:[~2011-07-08 8:46 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-08 8:45 Nao Nishijima [this message]
2011-07-08 8:46 ` [RFC PATCH 1/4] block: add a new attribute "alias name" in gendisk structure Nao Nishijima
2011-07-08 8:46 ` [RFC PATCH 2/4] sd: modify printk for alias_name Nao Nishijima
2011-07-09 5:42 ` [PATCH] scsi: Make functions out of logging macros Joe Perches
2011-07-09 13:32 ` Nao Nishijima
2011-07-08 8:46 ` [RFC PATCH 3/4] fs: modify disk_name() for alias name Nao Nishijima
2011-07-08 8:46 ` [RFC PATCH 4/4] sd: cleanup " Nao Nishijima
2011-07-08 14:54 ` [RFC PATCH 0/4] Persistent device name using " Greg KH
2011-07-08 15:41 ` Kay Sievers
2011-07-08 15:47 ` Greg KH
2011-07-08 15:54 ` James Bottomley
2011-07-08 16:04 ` Greg KH
2011-07-08 16:17 ` James Bottomley
2011-07-08 16:32 ` Greg KH
2011-07-08 16:15 ` Kay Sievers
2011-07-08 16:38 ` Kay Sievers
2011-07-11 11:47 ` Hannes Reinecke
2011-07-09 6:11 ` Masami Hiramatsu
2011-08-03 17:16 ` Borislav Petkov
2011-08-10 2:01 ` Masami Hiramatsu
2011-07-08 19:45 ` Karel Zak
2011-07-08 19:58 ` Greg KH
2011-07-15 6:55 ` Nao Nishijima
2011-07-15 12:48 ` Karel Zak
2011-07-16 11:40 ` Nao Nishijima
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110708084547.2091.55262.stgit@ltc197.sdl.hitachi.co.jp \
--to=nao.nishijima.xt@hitachi.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=dgilbert@interlog.com \
--cc=dle-develop@lists.sourceforge.net \
--cc=greg@kroah.com \
--cc=hare@suse.de \
--cc=jcm@redhat.com \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=stefanr@s5r6.in-berlin.de \
--cc=yrl.pp-manager.tt@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®