Discussion:
[New to NetBSD] USB mass-storage hotplug?
Sylvain Briole
2005-06-23 15:00:55 UTC
Permalink
Hi all,

I am a new user of NetBSD, with a Debian Linux background.
I would like to know how to use USB mass-storage "hotplug" in NetBSD.

In Debian Linux Woody I was doing like this to avoid any problem:
- /etc/init.d/hotplug start
- plug in USB hard disk
- mount /dev/usb_drive /mount_point
- working with the drive
- umount /mount_point
- /etc/init.d/hotplug stop
- plug out USB hard disk

I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I did not find
out how to use "hotplug". Do I have to do anything before/after :
- plug-in?
- plug-out?
To avoid any kernel panic or something like this?

I thank you in advance,

Sylvain.
Hauke Fath
2005-06-24 09:13:53 UTC
Permalink
Post by Sylvain Briole
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I
did not find out how to use "hotplug".
There is no daemon in NetBSD that handles USB hot-plugging events,
afaik. The closest thing to hot-plugging support of storage devices
is using amd(8) with a map like what we use here:

# $Id: amd.media,v 1.12 2005/05/11 11:39:29 hf Exp $
#
# /media - mount local removable media (CDROMs,floppy, USB stick)
# by cd'ing into it: cd /media/cd0
# Unmount by typing "amq -u /media/cd0" etc.
#

# ICK: The am-utils that ship with RH-Linux do not support 'pcfs'.

/defaults opts:=nosuid,nodev

# CDROM drives

cd0 -type:=cdfs;addopts:=ro,defperm \
os==netbsd2;dev:=/dev/cd0a \
os==linux;dev:=/dev/cdrom

cd1 -type:=cdfs;addopts:=ro,defperm \
os==netbsd2;dev:=/dev/cd0a \
os==linux;dev:=/dev/cdrom1

# Floppy Disc

floppy -addopts:=rw \
os==netbsd2;type:=pcfs;dev:=/dev/fd0a \
os==linux;type:=pcfs;dev:=/dev/fd0

# USB Memory Sticks (depends on partitioning)

stick0 -addopts:=rw \
os==netbsd2;type:=pcfs;dev:=/dev/sd0d \
os==linux;type:=pcfs;dev:=/dev/sda

stick1 -addopts:=rw \
os==netbsd2;type:=pcfs;dev:=/dev/sd0e \
os==linux;type:=pcfs;dev:=/dev/sda1

stick2 -addopts:=rw \
os==netbsd2;type:=pcfs;dev:=/dev/sd0f \
os==linux;type:=pcfs;dev:=/dev/sda1


HTH,
hauke
--
/~\ The ASCII Ribbon Campaign Hauke Fath
\ / No HTML/RTF in email Institut für Nachrichtentechnik
X No Word docs in email TU Darmstadt
/ \ Respect for open standards Ruf +49-6151-16-3281
Jukka Marin
2005-06-24 09:19:57 UTC
Permalink
Post by Hauke Fath
Post by Sylvain Briole
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I
did not find out how to use "hotplug".
There is no daemon in NetBSD that handles USB hot-plugging events,
afaik.
I wrote a prg which polls for a given USB device and executes a script
when the device is plugged in or out. The problem is that this prg can
cause a kernel panic under 2.0.2 - I think there must be a race condition
which causes the panic if the USB devices are polled at the "wrong" time
(exactly at the moment when a new device is being attached, probably).

I was going to use this prg and script to mount my digicam, move all pics
to hd and then umount the disk - but I don't like the kernel panic that
much :(

-jm
Hauke Fath
2005-06-24 11:05:42 UTC
Permalink
Post by Jukka Marin
Post by Hauke Fath
There is no daemon in NetBSD that handles USB hot-plugging events,
afaik.
I wrote a prg which polls for a given USB device and executes a script
when the device is plugged in or out. The problem is that this prg can
cause a kernel panic under 2.0.2 - I think there must be a race condition
which causes the panic if the USB devices are polled at the "wrong" time
(exactly at the moment when a new device is being attached, probably).
Uh. Did you try with a build from the netbsd-2 branch? From where I
stand there is no good reason to stick with netbsd-2-0 unless you're
in a production environment, since it sees almost no bug fixes.

Actually, some instance of hotplugd is sorely missing from NetBSD.
Probably the most frequent complaint from students ("...sooo much
easier on Windows!") using our lab machines concerns mass media
handling (USB memory sticks, floppies).

How about pkg'ing the program and putting it on pkgsrc-wip?

hauke
--
/~\ The ASCII Ribbon Campaign Hauke Fath
\ / No HTML/RTF in email Institut für Nachrichtentechnik
X No Word docs in email TU Darmstadt
/ \ Respect for open standards Ruf +49-6151-16-3281
Zbigniew Baniewski
2005-06-24 23:23:54 UTC
Permalink
From where I stand there is no good reason to stick with netbsd-2-0 unless
you're in a production environment, since it sees almost no bug fixes.
Really? Should netbsd-2 branch be considered as kind of "abandonware"?
--
pozdrawiam / regards

Zbigniew Baniewski
Lubomir Sedlacik
2005-06-24 23:25:34 UTC
Permalink
Post by Zbigniew Baniewski
From where I stand there is no good reason to stick with netbsd-2-0
unless you're in a production environment, since it sees almost no
bug fixes.
Really? Should netbsd-2 branch be considered as kind of "abandonware"?
netbsd-2 != netbsd-2-0

please see http://NetBSD.org/Releases/release-map.html for details.


regards,
--
-- Lubomir Sedlacik <salo@{NetBSD,Xtrmntr,silcnet}.org> --
fab
2005-06-24 15:01:42 UTC
Permalink
Post by Hauke Fath
Post by Sylvain Briole
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I
did not find out how to use "hotplug".
There is no daemon in NetBSD that handles USB hot-plugging events,
afaik. The closest thing to hot-plugging support of storage devices
AFAIK, I coded something to do this some months ago:
http://fab.gnux.info/divers/pluged.tgz

I havn't worked with it recently but it should works.

Hope this helps.
Fabien Devaux.
Malte Dehling
2005-06-24 10:40:30 UTC
Permalink
Post by Sylvain Briole
Hi all,
I am a new user of NetBSD, with a Debian Linux background.
I would like to know how to use USB mass-storage "hotplug" in NetBSD.
- /etc/init.d/hotplug start
- plug in USB hard disk
- mount /dev/usb_drive /mount_point
- working with the drive
- umount /mount_point
- /etc/init.d/hotplug stop
- plug out USB hard disk
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I did not find
- plug-in?
- plug-out?
To avoid any kernel panic or something like this?
From my experience with my (usb-connected) digicam, which shows up as a usb
mass storage device with scsi emulation, it worked like this:
- plug in
- mount
- work
- umount
- unplug

I never noticed any problems and there was no need for any hotplug
scripts... ofcourse, if you want you device to be mounted automagically,
you'll need to use amd or something.
--
Malte Dehling

Mail: mdehling [at] math.ruhr-uni-bochum.de
Website: http://mdehling.ath.cx/
PGP: 2586 A3BF B438 E68E 2B85 C4EA C5A7 AD96 C865 03D2
Courtney R. Spencer
2005-06-24 14:08:01 UTC
Permalink
Post by Sylvain Briole
Hi all,
I am a new user of NetBSD, with a Debian Linux background.
I would like to know how to use USB mass-storage "hotplug" in NetBSD.
- /etc/init.d/hotplug start
- plug in USB hard disk
- mount /dev/usb_drive /mount_point
- working with the drive
- umount /mount_point
- /etc/init.d/hotplug stop
- plug out USB hard disk
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I did not find
- plug-in?
- plug-out?
To avoid any kernel panic or something like this?
I thank you in advance,
To answer your question, since you do use mount/umount, there
is no other script needed and nothing else you have to do in netbsd.
Post by Sylvain Briole
- plug in USB hard disk
- mount /dev/usb_drive /mount_point
- working with the drive
- umount /mount_point
- plug out USB hard disk
--
Courtney R. Spencer
Carl Brewer
2005-06-30 03:28:05 UTC
Permalink
Post by Courtney R. Spencer
Post by Sylvain Briole
Hi all,
I am a new user of NetBSD, with a Debian Linux background.
I would like to know how to use USB mass-storage "hotplug" in NetBSD.
- /etc/init.d/hotplug start
- plug in USB hard disk
- mount /dev/usb_drive /mount_point
- working with the drive
- umount /mount_point
- /etc/init.d/hotplug stop
- plug out USB hard disk
I have read USB manpages (usb(4), umass(4)) on NetBSD 2.0.2, but I did not find
- plug-in?
- plug-out?
To avoid any kernel panic or something like this?
I thank you in advance,
To answer your question, since you do use mount/umount, there
is no other script needed and nothing else you have to do in netbsd.
Except maybe patch the kernel! umass has known problems
with removable storage (it's broken in 2.0.2 at least)
that AFAIK (please tell me someone has fixed it!) means
that after a "while" you can't mount removable disks, due to :

umass0: using SCSI over Bulk-Only
umass0: no buffer memory

which seems to happen after a while (days? hours? I'm not
sure yet)

I've a PR on it :
http://www.netbsd.org/cgi-bin/query-pr-single.pl?number=30615
Jukka Salmi
2005-06-30 09:02:12 UTC
Permalink
Post by Carl Brewer
Except maybe patch the kernel! umass has known problems
with removable storage (it's broken in 2.0.2 at least)
that AFAIK (please tell me someone has fixed it!) means
umass0: using SCSI over Bulk-Only
umass0: no buffer memory
which seems to happen after a while (days? hours? I'm not
sure yet)
AFAICT this is fixed for HEAD, netbsd-3 and netbsd-2, but not for
netbsd-2-0. Search for USB_MEM_RESERVE.

HTH, Jukka
--
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
Carl Brewer
2005-07-11 03:02:25 UTC
Permalink
Post by Jukka Salmi
Post by Carl Brewer
Except maybe patch the kernel! umass has known problems
with removable storage (it's broken in 2.0.2 at least)
that AFAIK (please tell me someone has fixed it!) means
umass0: using SCSI over Bulk-Only
umass0: no buffer memory
which seems to happen after a while (days? hours? I'm not
sure yet)
AFAICT this is fixed for HEAD, netbsd-3 and netbsd-2, but not for
netbsd-2-0. Search for USB_MEM_RESERVE.
I pulled my kernel up to the netbsd-2 version, and will report back
with how it goes

Carl
Carl Brewer
2005-07-14 02:04:11 UTC
Permalink
Post by Carl Brewer
Post by Jukka Salmi
Post by Carl Brewer
Except maybe patch the kernel! umass has known problems
with removable storage (it's broken in 2.0.2 at least)
that AFAIK (please tell me someone has fixed it!) means
umass0: using SCSI over Bulk-Only
umass0: no buffer memory
which seems to happen after a while (days? hours? I'm not
sure yet)
AFAICT this is fixed for HEAD, netbsd-3 and netbsd-2, but not for
netbsd-2-0. Search for USB_MEM_RESERVE.
I pulled my kernel up to the netbsd-2 version, and will report back
with how it goes
So far so good - I'm seeing this every time it mounts :
sd0: fabricating a geometry
/dev/sd0a: file system not clean (fs_clean=40); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
I remount it daily on a moderatly busy LAN/mail server to do
dumps and misc backups to it.

It seems to be working just fine anyway:

/dev/sd0a 145G 41G 103G 28% /mnt/usbdrive

This is with 2.0_STABLE NetBSD 2.0_STABLE (GENERIC) (pulled up
using cvs up -Pd -r netbsd-2)

Carl
Jukka Salmi
2005-07-14 07:49:29 UTC
Permalink
Post by Carl Brewer
sd0: fabricating a geometry
/dev/sd0a: file system not clean (fs_clean=40); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
Does this also happen if you explicitly sync(8) before unmounting?
I remember seeing the same problem on a netbsd-2 i386 system using
a USB CF adapter; syncing before unmounting seemed to fix the problem.


Cheers, Jukka
--
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
Carl Brewer
2005-07-14 22:17:22 UTC
Permalink
Post by Jukka Salmi
Post by Carl Brewer
sd0: fabricating a geometry
/dev/sd0a: file system not clean (fs_clean=40); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
Does this also happen if you explicitly sync(8) before unmounting?
I remember seeing the same problem on a netbsd-2 i386 system using
a USB CF adapter; syncing before unmounting seemed to fix the problem.
No, same warning. It seems to work ok, just whinges and takes
some time (~30s) to complete the mount process.
Steven M. Bellovin
2005-07-14 22:22:04 UTC
Permalink
Post by Carl Brewer
Post by Jukka Salmi
Post by Carl Brewer
sd0: fabricating a geometry
/dev/sd0a: file system not clean (fs_clean=40); please fsck(8)
/dev/sd0a: lost blocks 0 files 0
Does this also happen if you explicitly sync(8) before unmounting?
I remember seeing the same problem on a netbsd-2 i386 system using
a USB CF adapter; syncing before unmounting seemed to fix the problem.
No, same warning. It seems to work ok, just whinges and takes
some time (~30s) to complete the mount process.
sd0a? That's odd -- usually, it's sd0e.

--Steven M. Bellovin, http://www.cs.columbia.edu/~smb

Loading...