chiark / gitweb /
5013c87e1daf3e2e5fa150fbac0c99ef55291658
[elogind.git] / docs / persistent_naming / Testing_scsi_notes.txt
1 Using UDEV to do Persistent storage device naming 
2 for large numbers of storage devices
3 3/16/2004
4
5 Here are some lessons we learned at OSDL recently on how to use
6 UDEV (version 021) to do persistent device naming for lots of storage
7 devices.  We used what was available in udev for scsi devices.  Here is
8 an outline of this report:
9
10 Background information - a list of resources we needed to get
11 started.
12 Setup - what we needed to create the right enviroment (kernel,
13 patches, drivers)
14 How udev works to assign persistent storage device names -
15 what the documentation didn't tell us.
16 Performance - A sanity test we ran to compare with and without
17 persistent naming.
18
19
20 BACKGROUND INFORMATION
21 To get started, here are some references.  Review the overview
22 articles so that the rest of the information makes sense.
23
24 Download the latest udev stuff from:
25 http://www.kernel.org/pub/linux/utils/kernel/hotplug/
26
27 mailing list:
28 linux-hotplug-devel@lists.sourceforge.net
29
30 Here is a nice overview article to get started (warning, this is from
31 summer 2003 so many items indicated as "todo" have been done and
32 configuration file name references have sometime changed):
33 http://www.kroah.com/linux/talks/ols_2003_udev_paper/Reprint-Kroah-Hartman-OLS2003.pdf
34 (also included when you download udev)
35
36 More general info (also included in the udev package):
37 http://kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ
38 UDEV version 021 Announcement:
39 http://marc.theaimsgroup.com/?l=linux-hotplug-devel&m=107827264803336&w=2
40
41 "Managing Dynamic Naming" 
42 http://lwn.net/Articles/28897/
43
44 If you are a fan of devfs, whatever you do, don't complain until you
45 read everything you possibly can about udev.  This for example:
46 http://kernel.org/pub/linux/utils/kernel/hotplug/udev_vs_devfs
47
48 You will need to create udev.rules to supply consistent names.  (See
49 etc/udev/udev.rules in the download).  This article gives you some
50 background about udev.rules, but avoids describing the "PROGRAM"
51 key which is needed for our work.  Read it for background:
52 writing udev rules (current as of udev 018) 
53 http://www.reactivated.net/udevrules.php
54
55 bitkeeper tree:
56 bk://kernel.bkbits.net/gregkh/udev
57
58 Libsysfs  (used to get sysfs information):
59 http://www-124.ibm.com/linux/papers/libsysfs/libsysfs-linuxconfau2004.pdf
60
61 UDEV works using the way hotplug events are handled by the kernel.
62 Several overview articles about hotplug include:
63 Hotplug events
64 http://lwn.net/Articles/52621/
65 Overview of Hotplug
66 http://linux-hotplug.sourceforge.net/
67
68 Gentoo centric install info:
69 http://webpages.charter.net/decibelshelp/LinuxHelp_UDEVPrimer.html
70
71 rpms built against Red Hat FC2-test1 may be available at:
72 http://kernel.org/pub/linux/utils/kernel/hotplug/udev-021-1.i386.rpm
73
74 with the source rpm at:
75 http://kernel.org/pub/linux/utils/kernel/hotplug/udev-021-1.src.rpm
76
77
78
79 SETUP
80
81 Here is a brief checklist of what you need on your system for this to
82 work:
83
84 Kernel must be a 2.6 kernel
85
86 Must use CONFIG_HOTPLUG kernel config option, since the solution
87 is based on hotplug capabilities.
88
89 To test more than 256 scsi devices you need a patch to the scsi driver
90 to support that many (available from IBM or SuSE).  To see the patch
91 we used, see this link:
92 http://developer.osdl.org/maryedie/DCL/PSDN/lotsofdisks.patch
93
94 Your storage device must support (via the driver) a unique identifier for
95 persistent device naming.  (Adaptec RAID device does not, for
96 example.)
97
98 Your device driver must support sysfs (new in 2.6 kernel).  This is
99 already done for scsi devices and most if not all block devices.
100
101 A program (scsi_id) exists in the udev download
102 ( extras/scsi_id/scsi_id.c) for scsi devices. It can read the identifier and
103 is needed for persistent naming.   
104
105
106 HOW UDEV WORKS  TO ASSIGN PERSISTENT NAMES:
107
108 There are three places where device information is stored that udev
109 uses:
110 (1) /sys maintained by sysfs 
111 (2) /etc/udev/udev.rules - where you can store the identifier to NAME
112 mapping information.
113 (3) The tdb (udev-021/tdb/tdb.c),  trivial data base,  that is held in
114 memory and holds the valid system configuration.  It is not saved
115 between one boot to the next.  It is constructed at boot time and
116 updated with configuration changes.
117
118 The persistent names are kept (at least this is one way to do it) in
119 udev.rules (uuid and NAME), one entry per device.  If you want to
120 initially give your 1000 disk devices a default name and then make
121 sure those names are preserved, here is how :
122
123 Start with no special entry in udev.rules when do you an initial boot of
124 your system with disks in place.   Udev will assign default names (there
125 are ways to control what you want for default too).  
126
127 Once the names are assigned, use a script supplied for scsi devices -
128 udev-021/extras/scsi_id/gen_scsi_id_udev_rules.sh
129 to generate the lines needed for udev.rules, one per device.  Each line
130 indicates the identifier and the NAME it was assigned.  You could
131 optionally create this manually if you prefer other names .
132
133 [example entries in udev.rules for scsi disks]
134 BUS="scsi", PROGRAM="scsi_id", RESULT="<uuid1>",NAME="<name1>"
135 BUS="scsi", RESULT="<uuid2>",NAME="<name2>"
136 ...
137 BUS="scsi",  RESULT="<uuid1000>",NAME="<name1000>"
138
139 (The actual file we used is the file udev.rules_1000_scsi_debug  in this
140 directory )
141
142 Upon reboot, for each device a hotplug event occurs.  The udev.rules
143 file is scanned looking for the device type (BUS) in this case for "scsi". 
144 The first entry generated by the above program references a
145 PROGRAM in the key field (scsi_id) which is called to probe the device
146 and determine the unique identifier.    sysfs is used to determine the
147 major/minor number for the device.  The result of the program
148 execution (the uuid)  is compared with the RESULT entry in the same
149 udev.rules line.  
150
151 -If it matches, then the NAME entered on this line is used.  The uuid
152 and major/minor number is saved in tdb (newly recreated upon boot).
153 That device is created in /udev (the target directory name is
154 configurable) with the assigned NAME.    
155
156 -If it doesn't match, the RESULT (uuid) is preserved for use on the next
157 udev.rules line as long as the bus type (scsi) is the same.  So the result
158 (the uuid) is compared on the next line, and the next until a match
159 occurs.  
160
161 -If no match occurs, the device will be assigned a default name.  
162
163 -Tdb is updated with the resulting name assignment.
164
165
166 Thus if the uuid and names are enumerated, they will be found,
167 assigned, and are therefore permanent.
168
169 If the device is removed from a live system, a hotplug event occurs,
170 and it is removed from tdb and the /udev entry disappears.
171
172 If it is re-inserted at a new location, the udev.rules file is scanned as
173 above.  The new major/minor number goes in tdb with the uuid , the
174 name in udev.rules is found again,  and the /udev name re-appears.
175
176
177
178 PERFORMANCE 
179
180 Now the question becomes, how much longer does it take to scan the
181 udev.rules table once there are 1000 entries?
182
183 To test this, we  created 1000 "scsi " devices using the scsi debug
184 device driver supplied in the kernel. When this device driver is loaded
185 you can specify how many fake scsi devices to create.  There is no
186 real I/O involved but it does respond to some scsi commands.  It
187 simulates the uuid by using the device number assigned when the
188 device is created.  
189
190 Then we auto-generated entries into udev.rules with
191 gen_scsi_id_udev_rules.sh.  We then removed the devices and
192 reassigned them to simulate a reboot.  The delta between assigning
193 defaults and assigning the names enumerated in the udev.rules file
194 was 7 seconds (that's for 1000 drives).  
195
196 Scripts utilized the feature (described above) that saves the "RESULT"
197 key after one scsi-id program call for later reference with other
198 udev.rules entries (so only have one PROGRAM key is the moral of
199 the story).  If you repeated the PROGRAM key, you would
200 unnecessarily call the program up to 999 times!  
201
202 The script that creates udev.rules did not work for 1000 drives (the
203 input line is too long).  We determined that a patch for this already
204 existed but had not yet been checked in.  
205
206
207
208
209
210
211
212
213