トップ «前の日記(2022-04-19) 最新 次の日記(2022-05-20)» 編集

Orz日記 by Akio Morita

ToDo:

  • 15 SAD Fit[]回りの障害事例の解析
  • 10 smart pointer版PEGクラスの再実装(Left Recursionまわり)
2006|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|06|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|07|08|09|10|11|12|
2013|01|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|06|07|08|10|12|
2016|01|02|03|05|06|08|10|11|
2017|01|02|03|04|05|06|07|09|10|11|12|
2018|01|02|03|04|06|07|08|09|10|11|12|
2019|01|03|04|05|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|09|10|11|12|
2024|01|02|03|04|05|06|07|08|09|10|11|

2022-05-14 [長年日記]

_ [FreeBSD]sysutils/nut 2.8.0

2.7.4から2.8.0に上がったところで、OMRON BW100Tとの通信がうまくいかなくなって、しばらくnut-2.7.4_21を使っていたが、原因が分かった

USB通信回りのバックエンドだが、 2.7.4までは libusb-0.1 APIベースの実装、 2.8.0から libusb-0.1 APIと libusb-1.0 APIの両対応になっており、 configureによる自動検出で libusb-1.0 APIが選択されるのだが、 libusb-1.0版だとうまく通信出来ない模様

# /usr/local/libexec/nut/blazer_usb -D -D -D -D -a BW100T
Network UPS Tools - Megatec/Q1 protocol USB driver 0.14 (2.8.0)
   0.000000     [D3] main_arg: var='driver' val='blazer_usb'
   0.000011     [D3] main_arg: var='port' val='auto'
   0.000020     [D3] main_arg: var='desc' val='OMRON BW100T'
   0.000024     [D3] main_arg: var='vendorid' val='0590'
   0.000031     [D3] main_arg: var='productid' val='00d1'
   0.000037     [D3] main_arg: var='subdriver' val='ippon'
   0.000043     [D3] main_arg: var='default.battery.voltage.high' val='27.0'
   0.000048     [D3] main_arg: var='default.battery.voltage.low' val='23.5'
   0.000053     [D3] main_arg: var='runtimecal' val='259,100,780,49'
   0.000062     [D1] debug level is '4'
   0.001502     [D2] Checking device 1 of 1 (0590/00D1)
   0.024657     [D2] - VendorID: 0590
   0.024667     [D2] - ProductID: 00d1
   0.024670     [D2] - Manufacturer: OMRON
   0.024673     [D2] - Product: BW100T
   0.024676     [D2] - Serial Number: unknown
   0.024679     [D2] - Bus: 001
   0.024682     [D2] - Device: unknown
   0.024685     [D2] - Device release number: 0100
   0.024688     [D2] Trying to match device
   0.024691     [D3] match_function_regex: matching a device...
   0.024704     [D2] Device matches
   0.024707     [D2] Reading first configuration descriptor
   0.024731     [D3] libusb_kernel_driver_active() returned 1 (driver active)
   0.024735     [D2] successfully set kernel driver auto-detach flag
   0.024742     [D2] failed to claim USB device: Other error
   0.024746     [D1] failed to detach kernel driver from USB device: Other error
   0.024749     [D2] failed to claim USB device: Other error
   0.024753     [D1] failed to detach kernel driver from USB device: Other error
   0.024756     [D2] failed to claim USB device: Other error
   0.024758     [D1] failed to detach kernel driver from USB device: Other error
   0.024762     [D2] failed to claim USB device: Other error
   0.024765     [D1] failed to detach kernel driver from USB device: Other error
   0.024771     Can't claim USB device [0590:00d1]@0/0: Other error

libusb-0.1 APIで動く nut-2.7.4に問題は無いので、drivers/libusb0.cを使うべく sysutils/nut/Makefile内の USB_CONFIGURE_WITHの設定をusb=autoから usb=libusb-0.1に変えて、libusb-0.1 APIを要求すると configureに失敗する

原因は、configure scriptでpkgconfからlibusb-0.1 APIのmodule versionを検出する際の 名前に libusbを使っているが、FreeBSD system側に/usr/libdata/pkgconf/libusb-0.1.pcのみが用意されているため

/usr/libdata/pkgconfにsymbolic linkを作るのも他で問題がでる可能性があるので、 sysutils/nut/Makefilepre-patchターゲットを追加して、pkgconfの参照先を変更

pre-patch:
	@${REINPLACE_CMD} -i '' -e 's| libusb 2| libusb-0.1 2|' ${WRKSRC}/m4/nut_check_libusb.m4
	@${REINPLACE_CMD} -i '' -e 's| libusb 2| libusb-0.1 2|' ${WRKSRC}/configure

一応、libusb-0.1 API版でビルドすると nut-2.8.0でも問題なく動く模様

本来は、libusb-1.0 API版で発生しているfailed to claim USB deviceエラーの原因を調べるのが本道なのだが

# /usr/local/libexec/nut/blazer_usb -D -D -D -D -a BW100T
Network UPS Tools - Megatec/Q1 protocol USB driver 0.14 (2.8.0)
   0.000000     [D3] main_arg: var='driver' val='blazer_usb'
   0.000011     [D3] main_arg: var='port' val='auto'
   0.000020     [D3] main_arg: var='desc' val='OMRON BW100T'
   0.000024     [D3] main_arg: var='vendorid' val='0590'
   0.000031     [D3] main_arg: var='productid' val='00d1'
   0.000036     [D3] main_arg: var='subdriver' val='ippon'
   0.000042     [D3] main_arg: var='default.battery.voltage.high' val='27.0'
   0.000047     [D3] main_arg: var='default.battery.voltage.low' val='23.5'
   0.000052     [D3] main_arg: var='runtimecal' val='259,100,780,49'
   0.000062     [D1] debug level is '4'
   0.001562     [D3] usb_busses=0x800275200
   0.001569     [D2] Checking device (0590/00D1) (/dev/usb//dev/ugen1.5)
   0.024190     [D2] - VendorID: 0590
   0.024200     [D2] - ProductID: 00d1
   0.024205     [D2] - Manufacturer: OMRON
   0.024208     [D2] - Product: BW100T
   0.024211     [D2] - Serial Number: unknown
   0.024214     [D2] - Bus: /dev/usb
   0.024217     [D2] - Device: /dev/ugen1.5
   0.024219     [D2] - Device release number: 0100
   0.024223     [D2] Trying to match device
   0.024226     [D3] match_function_regex: matching a device...
   0.024255     [D2] Device matches
   0.024262     [D3] nut_usb_set_altinterface: skipped usb_set_altinterface(udev, 0)
   0.024282     Please note that this driver is deprecated and will not receive new development.
                If it works for managing your devices - fine, but if you are running it
                to try setting up a new device, please consider the newer nutdrv_qx instead,
                which should handle all 'Qx' protocol variants for NUT.
                (Please also report if your device works with this driver,
                 but nutdrv_qx would not actually support it with any subdriver!)
   0.024286     [D2] Trying megatec protocol...
   0.027187     [D3] send: Q1
   0.297257     [D3] read: (100.0 000.0 099.9 047 50.1 27.1 34.9 00101000
   0.297300     [D2] Status read in 1 tries
   0.297304     Supported UPS detected with megatec protocol
   0.299182     [D3] send: F
   0.401247     [D3] read: NAK
   0.401260     [D2] blazer_rating: short reply
   0.401264     [D1] Rating read 1 failed
   0.403181     [D3] send: F
   0.513253     [D3] read: NAK
   0.513264     [D2] blazer_rating: short reply
   0.513267     [D1] Rating read 2 failed
   0.515185     [D3] send: F
   0.625251     [D3] read: NAK
   0.625263     [D2] blazer_rating: short reply
   0.625267     [D1] Rating read 3 failed
   0.625271     Rating information unavailable
   0.627186     [D3] send: I
   0.729249     [D3] read: NAK
   0.729260     [D2] blazer_vendor: short reply
   0.729264     [D1] Vendor information read 1 failed
   0.731187     [D3] send: I
   0.841254     [D3] read: NAK
   0.841268     [D2] blazer_vendor: short reply
   0.841272     [D1] Vendor information read 2 failed
   0.843185     [D3] send: I
   0.953244     [D3] read: NAK
   0.953257     [D2] blazer_vendor: short reply
   0.953261     [D1] Vendor information read 3 failed
   0.953266     Vendor information unavailable
   0.953286     [D2] battery runtime exponent : 1.545
   0.953290     [D2] battery runtime nominal  : 259.0
   0.953294     [D2] battery runtime estimate : 259.0
   0.953298     No charge time specified, using built in default [43200 seconds]
   0.953301     No idle load specified, using built in default [10.0 %]
   0.955176     [D3] send: Q1
   1.217248     [D3] read: (100.0 000.0 099.9 047 50.1 27.1 34.9 00101000
   1.217494     [D2] dstate_init: sock /var/db/nut/blazer_usb-BW100T open on fd 8
   1.219177     [D3] send: Q1
   1.489238     [D3] read: (100.0 000.0 099.9 047 50.1 27.1 35.0 00101000

ざっくり、drivers/libusb1.cのコメントを流し読みしたが…

  • failed to claim USB device: Other errorの出所は、libusb_claim_interface内のlibusb_detach_kernel_driverから
  • failed to detach kernel driver from USB device: Other errorに関しては、libusb_claim_interfaceに失敗した後のlibusb_detach_kernel_driverから
  • libusb_set_auto_detach_kernel_driverしてるコードのコメントだと、driver codeがroooで動いてないとauto_detachなlibusb_claim_interfaceは動かないとあるが、nutの実行権限のdefaultはuucp

要検証だが

  • nutの実行権限をrootにする
    • blazer_usbに-u rootを渡す(試験)
    • /usr/local/etc/nut/ups.confuserパラメータを追加する
      • libusb-1.0で動くが、 built-in defaultと異なるアカウントだと警告が出る Group and/or user account for this driver was customized ('root:uucp') compared to built-in defaults. Fixing socket '/var/db/nut/blazer_usb-BW100T' ownership/access (追試 2022/05/20)
  • auto_detachを外す
    • drivers/libusb1.cからHAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVERを無効にする
      • auto detach無効状態だと、built-in defaultのuucpアカウントで、device specialにuucp group writableを与えた状態で普通に動く(追試 2022/05/22)

あたりで、libusb-1.0 API版が動くようになるのでは?

(2022/05/22 追記) nut-2.7がdefault設定で動く環境では、HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVERを無効にして動かすのが一番素直な模様

pre-patch:
	@${REINPLACE_CMD} -i '' -e 's|HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER|__HAVE_LIBUSB_SET_AUTO_DETACH_KERNEL_DRIVER|g' ${WRKSRC}/drivers/libusb1.c

カテゴリー: Admin | Emacs | EPICS | Fortran | FreeBSD | GCC | hgsubversion | IPv6 | KEKB | LHC | Lisp | LLVM | MADX | Ryzen | SAD | samba | tDiary | unix | WWW | YaSAI | お仕事 | イベント | 出張 | 宴会 | 数学 | 艦これ | 買いもの | 追記 | 雑記