Merge lp:~xnox/ubuntu/quantal/lvm2/merge95 into lp:ubuntu/quantal/lvm2
- Quantal (12.10)
- merge95
- Merge into quantal
Status: | Merged | ||||||||
---|---|---|---|---|---|---|---|---|---|
Merge reported by: | Dimitri John Ledkov | ||||||||
Merged at revision: | not available | ||||||||
Proposed branch: | lp:~xnox/ubuntu/quantal/lvm2/merge95 | ||||||||
Merge into: | lp:ubuntu/quantal/lvm2 | ||||||||
Diff against target: |
85158 lines (+39300/-20331) 513 files modified
.pc/applied-patches (+0/-7) .pc/avoid-dev-block.patch/lib/device/dev-cache.c (+0/-976) .pc/dirs.patch/daemons/dmeventd/Makefile.in (+108/-0) .pc/dirs.patch/daemons/dmeventd/dmeventd.c (+2009/-0) .pc/dirs.patch/doc/example.conf.in (+0/-662) .pc/dirs.patch/lib/commands/toolcontext.c (+0/-1513) .pc/dm-event-api.patch/daemons/dmeventd/.exported_symbols (+4/-0) .pc/dm-event-api.patch/daemons/dmeventd/dmeventd.c (+2018/-0) .pc/dm-event-api.patch/daemons/dmeventd/libdevmapper-event.c (+874/-0) .pc/force-modprobe.patch/configure.in (+0/-1369) .pc/implicit-pointer.patch/tools/lvm.c (+0/-253) .pc/install.patch/daemons/dmeventd/plugins/lvm2/Makefile.in (+31/-0) .pc/install.patch/daemons/dmeventd/plugins/mirror/Makefile.in (+37/-0) .pc/install.patch/daemons/dmeventd/plugins/raid/Makefile.in (+36/-0) .pc/install.patch/daemons/dmeventd/plugins/snapshot/Makefile.in (+33/-0) .pc/install.patch/daemons/dmeventd/plugins/thin/Makefile.in (+36/-0) .pc/install.patch/make.tmpl.in (+0/-396) .pc/libs-cleanup.patch/configure.in (+0/-1423) .pc/monitoring-default-off.patch/doc/example.conf.in (+773/-0) .pc/monitoring-default-off.patch/lib/config/defaults.h (+0/-165) .pc/monitoring-default-off.patch/tools/toollib.c (+1637/-0) Makefile.in (+14/-7) VERSION (+1/-1) VERSION_DM (+1/-1) WHATS_NEW (+273/-1) WHATS_NEW_DM (+109/-0) configure (+391/-118) configure.in (+158/-17) daemons/Makefile.in (+8/-4) daemons/clvmd/Makefile.in (+4/-2) daemons/clvmd/clvm.h (+11/-4) daemons/clvmd/clvmd-cman.c (+1/-0) daemons/clvmd/clvmd-command.c (+44/-47) daemons/clvmd/clvmd-comms.h (+2/-1) daemons/clvmd/clvmd-corosync.c (+61/-2) daemons/clvmd/clvmd-openais.c (+1/-0) daemons/clvmd/clvmd-singlenode.c (+51/-24) daemons/clvmd/clvmd.c (+158/-103) daemons/clvmd/lvm-functions.c (+78/-74) daemons/clvmd/lvm-functions.h (+1/-1) daemons/clvmd/refresh_clvmd.c (+27/-24) daemons/cmirrord/clogd.c (+17/-5) daemons/cmirrord/cluster.c (+120/-25) daemons/cmirrord/functions.c (+25/-8) daemons/dmeventd/.exported_symbols (+3/-3) daemons/dmeventd/Makefile.in (+5/-4) daemons/dmeventd/dmeventd.c (+165/-133) daemons/dmeventd/dmeventd.h (+1/-0) daemons/dmeventd/libdevmapper-event.c (+38/-30) daemons/dmeventd/libdevmapper-event.h (+3/-0) daemons/dmeventd/plugins/Makefile.in (+6/-1) daemons/dmeventd/plugins/lvm2/.exported_symbols (+1/-0) daemons/dmeventd/plugins/lvm2/Makefile.in (+3/-5) daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c (+25/-4) daemons/dmeventd/plugins/lvm2/dmeventd_lvm.h (+3/-0) daemons/dmeventd/plugins/mirror/Makefile.in (+3/-4) daemons/dmeventd/plugins/mirror/dmeventd_mirror.c (+16/-26) daemons/dmeventd/plugins/raid/Makefile.in (+2/-4) daemons/dmeventd/plugins/raid/dmeventd_raid.c (+30/-3) daemons/dmeventd/plugins/snapshot/Makefile.in (+3/-4) daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c (+60/-38) daemons/dmeventd/plugins/thin/.exported_symbols (+3/-0) daemons/dmeventd/plugins/thin/Makefile.in (+37/-0) daemons/dmeventd/plugins/thin/dmeventd_thin.c (+288/-0) daemons/lvmetad/Makefile.in (+59/-0) daemons/lvmetad/lvmetad-client.h (+81/-0) daemons/lvmetad/lvmetad-core.c (+1126/-0) daemons/lvmetad/test.sh (+16/-0) daemons/lvmetad/testclient.c (+127/-0) debian/changelog (+118/-0) debian/clvm.init (+6/-4) debian/clvmd.ra (+2/-2) debian/control (+22/-10) debian/dmeventd.install (+2/-0) debian/libdevmapper-dev.install (+2/-5) debian/libdevmapper-event1.02.1.install (+1/-1) debian/libdevmapper-event1.02.1.symbols (+6/-6) debian/libdevmapper1.02.1.install (+1/-1) debian/libdevmapper1.02.1.symbols (+66/-0) debian/liblvm2app2.2.install (+1/-1) debian/liblvm2cmd2.02.install (+1/-1) debian/lvm2.init (+6/-6) debian/lvm2.postinst (+4/-3) debian/lvm2.postrm (+9/-0) debian/lvm2.preinst (+4/-0) debian/patches/dirs.patch (+35/-4) debian/patches/dm-event-api.patch (+115/-0) debian/patches/install.patch (+83/-8) debian/patches/libs-cleanup.patch (+5/-13) debian/patches/monitoring-default-off.patch (+50/-12) debian/patches/series (+1/-0) debian/rules (+55/-43) doc/example.conf.in (+118/-7) doc/kernel/crypt.txt (+76/-0) doc/kernel/delay.txt (+26/-0) doc/kernel/flakey.txt (+53/-0) doc/kernel/io.txt (+75/-0) doc/kernel/kcopyd.txt (+47/-0) doc/kernel/linear.txt (+61/-0) doc/kernel/log.txt (+54/-0) doc/kernel/persistent-data.txt (+84/-0) doc/kernel/queue-length.txt (+39/-0) doc/kernel/raid.txt (+108/-0) doc/kernel/service-time.txt (+91/-0) doc/kernel/snapshot.txt (+168/-0) doc/kernel/striped.txt (+58/-0) doc/kernel/thin-provisioning.txt (+285/-0) doc/kernel/uevent.txt (+97/-0) doc/kernel/zero.txt (+37/-0) doc/lvm2-raid.txt (+197/-20) doc/lvm_fault_handling.txt (+41/-60) doc/lvmetad_design.txt (+2/-2) doc/tagging.txt (+6/-6) doc/udev_assembly.txt (+2/-2) include/.symlinks.in (+5/-0) lib/Makefile.in (+17/-1) lib/activate/activate.c (+395/-132) lib/activate/activate.h (+30/-12) lib/activate/dev_manager.c (+430/-57) lib/activate/dev_manager.h (+12/-1) lib/activate/fs.c (+22/-11) lib/activate/fs.h (+1/-0) lib/cache/lvmcache.c (+433/-54) lib/cache/lvmcache.h (+68/-49) lib/cache/lvmetad.c (+717/-0) lib/cache/lvmetad.h (+126/-0) lib/commands/toolcontext.c (+152/-95) lib/commands/toolcontext.h (+11/-4) lib/config/config.c (+266/-1207) lib/config/config.h (+21/-89) lib/config/defaults.h (+19/-5) lib/datastruct/str_list.c (+3/-6) lib/datastruct/str_list.h (+2/-2) lib/device/dev-cache.c (+87/-45) lib/device/dev-cache.h (+3/-0) lib/device/dev-io.c (+7/-20) lib/display/display.c (+105/-23) lib/filters/filter-mpath.c (+213/-0) lib/filters/filter-mpath.h (+23/-0) lib/filters/filter-persistent.c (+21/-15) lib/filters/filter-persistent.h (+1/-1) lib/filters/filter-regex.c (+14/-13) lib/filters/filter-regex.h (+1/-1) lib/filters/filter-sysfs.c (+3/-1) lib/filters/filter.c (+48/-21) lib/filters/filter.h (+2/-1) lib/format1/disk-rep.c (+48/-24) lib/format1/format1.c (+42/-12) lib/format1/import-extents.c (+4/-4) lib/format1/lvm1-label.c (+5/-6) lib/format_pool/disk_rep.c (+106/-76) lib/format_pool/format_pool.c (+34/-5) lib/format_pool/import_export.c (+4/-4) lib/format_text/archive.c (+1/-1) lib/format_text/archiver.c (+27/-11) lib/format_text/export.c (+33/-11) lib/format_text/flags.c (+9/-3) lib/format_text/format-text.c (+191/-186) lib/format_text/format-text.h (+12/-0) lib/format_text/import-export.h (+8/-7) lib/format_text/import.c (+16/-15) lib/format_text/import_vsn1.c (+150/-141) lib/format_text/layout.h (+1/-11) lib/format_text/tags.c (+3/-3) lib/format_text/text_export.h (+2/-2) lib/format_text/text_import.h (+3/-3) lib/format_text/text_label.c (+117/-94) lib/label/label.c (+16/-22) lib/label/label.h (+2/-0) lib/locking/cluster_locking.c (+36/-30) lib/locking/external_locking.c (+1/-1) lib/locking/file_locking.c (+15/-7) lib/locking/locking.c (+61/-9) lib/locking/locking.h (+27/-7) lib/locking/no_locking.c (+2/-2) lib/log/log.c (+8/-8) lib/metadata/lv.c (+209/-27) lib/metadata/lv.h (+11/-1) lib/metadata/lv_alloc.h (+7/-4) lib/metadata/lv_manip.c (+693/-255) lib/metadata/merge.c (+127/-2) lib/metadata/metadata-exported.h (+123/-87) lib/metadata/metadata.c (+282/-191) lib/metadata/metadata.h (+50/-46) lib/metadata/mirror.c (+144/-93) lib/metadata/pv.c (+72/-45) lib/metadata/pv_manip.c (+8/-6) lib/metadata/pv_map.c (+3/-3) lib/metadata/pv_map.h (+2/-2) lib/metadata/raid_manip.c (+654/-22) lib/metadata/replicator_manip.c (+0/-8) lib/metadata/segtype.h (+19/-16) lib/metadata/snapshot_manip.c (+4/-0) lib/metadata/thin_manip.c (+425/-0) lib/metadata/vg.c (+22/-3) lib/metadata/vg.h (+5/-0) lib/mirror/mirrored.c (+37/-38) lib/misc/configure.h.in (+15/-0) lib/misc/lvm-exec.c (+3/-2) lib/misc/lvm-file.c (+2/-1) lib/misc/lvm-globals.c (+14/-3) lib/misc/lvm-globals.h (+3/-0) lib/misc/lvm-percent.h (+2/-1) lib/misc/lvm-string.c (+43/-284) lib/misc/lvm-string.h (+0/-34) lib/misc/sharedlib.c (+4/-2) lib/mm/memlock.c (+23/-22) lib/raid/.exported_symbols (+1/-1) lib/raid/raid.c (+115/-81) lib/replicator/replicator.c (+39/-35) lib/report/columns.h (+12/-1) lib/report/properties.c (+39/-3) lib/report/properties.h (+1/-1) lib/report/report.c (+244/-16) lib/snapshot/snapshot.c (+10/-8) lib/striped/striped.c (+13/-11) lib/thin/.exported_symbols (+1/-0) lib/thin/Makefile.in (+25/-0) lib/thin/thin.c (+601/-0) lib/unknown/unknown.c (+9/-7) libdaemon/Makefile.in (+29/-0) libdaemon/client/Makefile.in (+20/-0) libdaemon/client/daemon-client.c (+118/-0) libdaemon/client/daemon-client.h (+105/-0) libdaemon/client/daemon-shared.c (+141/-0) libdaemon/client/daemon-shared.h (+30/-0) libdaemon/server/Makefile.in (+22/-0) libdaemon/server/daemon-server.c (+523/-0) libdaemon/server/daemon-server.h (+122/-0) libdm/Makefile.in (+1/-0) libdm/ioctl/libdm-iface.c (+220/-126) libdm/ioctl/libdm-targets.h (+3/-0) libdm/libdevmapper.h (+325/-4) libdm/libdm-common.c (+760/-104) libdm/libdm-common.h (+17/-4) libdm/libdm-config.c (+1174/-0) libdm/libdm-deptree.c (+1011/-386) libdm/libdm-file.c (+20/-1) libdm/libdm-report.c (+3/-0) libdm/libdm-string.c (+272/-13) libdm/misc/dm-log-userspace.h (+25/-6) libdm/mm/dbg_malloc.c (+16/-8) libdm/mm/dbg_malloc.h (+0/-46) libdm/mm/pool-fast.c (+13/-2) libdm/mm/pool.c (+1/-0) libdm/regex/matcher.c (+108/-68) liblvm/Makefile.in (+3/-1) liblvm/lvm2app.h (+2/-1) liblvm/lvm_base.c (+1/-1) liblvm/lvm_lv.c (+15/-9) liblvm/lvm_pv.c (+5/-5) make.tmpl.in (+40/-30) man/Makefile.in (+4/-4) man/clvmd.8.in (+14/-0) man/dmeventd.8.in (+22/-13) man/dmsetup.8.in (+472/-258) man/fsadm.8.in (+59/-45) man/lvconvert.8.in (+42/-0) man/lvcreate.8.in (+196/-108) man/lvextend.8.in (+1/-0) man/lvm.8.in (+2/-1) man/lvm.conf.5.in (+16/-4) man/lvreduce.8.in (+43/-31) man/lvremove.8.in (+15/-9) man/lvrename.8.in (+17/-23) man/lvresize.8.in (+56/-52) man/lvs.8.in (+68/-33) man/pvcreate.8.in (+1/-1) man/pvscan.8.in (+19/-0) scripts/Makefile.in (+20/-2) scripts/dm_event_systemd_red_hat.service.in (+3/-1) scripts/fsadm.sh (+51/-46) scripts/gdbinit (+68/-43) scripts/lvm2_lvmetad_init_red_hat.in (+115/-0) scripts/lvm2_lvmetad_systemd_red_hat.service.in (+17/-0) scripts/lvm2_lvmetad_systemd_red_hat.socket.in (+10/-0) scripts/lvm2_monitoring_init_red_hat.in (+4/-4) scripts/lvm2_monitoring_init_rhel4 (+4/-4) scripts/lvm2_monitoring_systemd_red_hat.service.in (+1/-2) scripts/lvm2_tmpfiles_red_hat.conf.in (+2/-0) scripts/lvm2create_initrd/lvm2create_initrd (+3/-3) scripts/lvm2create_initrd/lvm2create_initrd.8 (+53/-44) scripts/lvm2create_initrd/lvm2create_initrd.pod (+5/-5) scripts/vgimportclone.sh (+7/-5) test/Makefile.in (+46/-40) test/api/Makefile.in (+15/-34) test/api/percent.sh (+2/-0) test/lib/aux.sh (+75/-11) test/lib/check.sh (+4/-4) test/lib/harness.c (+20/-9) test/lib/test.sh (+12/-3) test/shell/000-basic.sh (+28/-0) test/shell/activate-missing.sh (+87/-0) test/shell/activate-partial.sh (+30/-0) test/shell/clvmd-restart.sh (+53/-0) test/shell/covercmd.sh (+82/-0) test/shell/dmeventd-restart.sh (+42/-0) test/shell/dumpconfig.sh (+35/-0) test/shell/fsadm.sh (+128/-0) test/shell/inconsistent-metadata.sh (+78/-0) test/shell/listings.sh (+83/-0) test/shell/lock-blocking.sh (+41/-0) test/shell/lvchange-mirror.sh (+28/-0) test/shell/lvconvert-mirror-basic-0.sh (+12/-0) test/shell/lvconvert-mirror-basic-1.sh (+12/-0) test/shell/lvconvert-mirror-basic-2.sh (+12/-0) test/shell/lvconvert-mirror-basic-3.sh (+12/-0) test/shell/lvconvert-mirror-basic.sh (+143/-0) test/shell/lvconvert-mirror.sh (+259/-0) test/shell/lvconvert-raid.sh (+215/-0) test/shell/lvconvert-repair-dmeventd.sh (+26/-0) test/shell/lvconvert-repair-policy.sh (+91/-0) test/shell/lvconvert-repair-replace.sh (+93/-0) test/shell/lvconvert-repair-snapshot.sh (+27/-0) test/shell/lvconvert-repair-transient-dmeventd.sh (+27/-0) test/shell/lvconvert-repair-transient.sh (+26/-0) test/shell/lvconvert-repair.sh (+114/-0) test/shell/lvconvert-twostep.sh (+26/-0) test/shell/lvcreate-large.sh (+40/-0) test/shell/lvcreate-mirror.sh (+41/-0) test/shell/lvcreate-operation.sh (+43/-0) test/shell/lvcreate-pvtags.sh (+47/-0) test/shell/lvcreate-raid.sh (+95/-0) test/shell/lvcreate-repair.sh (+100/-0) test/shell/lvcreate-small-snap.sh (+30/-0) test/shell/lvcreate-striped-mirror.sh (+65/-0) test/shell/lvcreate-thin.sh (+216/-0) test/shell/lvcreate-usage.sh (+152/-0) test/shell/lvextend-percent-extents.sh (+106/-0) test/shell/lvextend-snapshot-dmeventd.sh (+62/-0) test/shell/lvextend-snapshot-policy.sh (+47/-0) test/shell/lvm-init.sh (+21/-0) test/shell/lvmcache-exercise.sh (+22/-0) test/shell/lvmetad-pvs.sh (+20/-0) test/shell/lvresize-mirror.sh (+38/-0) test/shell/lvresize-rounding.sh (+25/-0) test/shell/lvresize-usage.sh (+20/-0) test/shell/mdata-strings.sh (+39/-0) test/shell/metadata-balance.sh (+232/-0) test/shell/metadata-dirs.sh (+43/-0) test/shell/metadata.sh (+80/-0) test/shell/mirror-names.sh (+156/-0) test/shell/mirror-vgreduce-removemissing.sh (+424/-0) test/shell/name-mangling.sh (+230/-0) test/shell/nomda-missing.sh (+83/-0) test/shell/pool-labels.sh (+40/-0) test/shell/pv-duplicate.sh (+25/-0) test/shell/pv-min-size.sh (+31/-0) test/shell/pv-range-overflow.sh (+32/-0) test/shell/pvchange-usage.sh (+66/-0) test/shell/pvcreate-metadata0.sh (+32/-0) test/shell/pvcreate-operation-md.sh (+147/-0) test/shell/pvcreate-operation.sh (+121/-0) test/shell/pvcreate-usage.sh (+192/-0) test/shell/pvmove-basic.sh (+385/-0) test/shell/pvremove-usage.sh (+68/-0) test/shell/read-ahead.sh (+62/-0) test/shell/snapshot-autoumount-dmeventd.sh (+39/-0) test/shell/snapshot-merge.sh (+134/-0) test/shell/snapshots-of-mirrors.sh (+44/-0) test/shell/tags.sh (+74/-0) test/shell/test-partition.sh (+30/-0) test/shell/topology-support.sh (+106/-0) test/shell/unknown-segment.sh (+34/-0) test/shell/unlost-pv.sh (+38/-0) test/shell/vgcfgbackup-usage.sh (+54/-0) test/shell/vgchange-maxlv.sh (+31/-0) test/shell/vgchange-sysinit.sh (+51/-0) test/shell/vgchange-usage.sh (+44/-0) test/shell/vgcreate-usage.sh (+163/-0) test/shell/vgextend-restoremissing.sh (+30/-0) test/shell/vgextend-usage.sh (+129/-0) test/shell/vgimportclone.sh (+38/-0) test/shell/vgmerge-operation.sh (+81/-0) test/shell/vgmerge-usage.sh (+67/-0) test/shell/vgreduce-removemissing-snapshot.sh (+26/-0) test/shell/vgreduce-usage.sh (+87/-0) test/shell/vgrename-usage.sh (+41/-0) test/shell/vgsplit-operation.sh (+295/-0) test/shell/vgsplit-stacked.sh (+29/-0) test/shell/vgsplit-usage.sh (+168/-0) test/t-000-basic.sh (+0/-30) test/t-activate-missing.sh (+0/-87) test/t-activate-partial.sh (+0/-30) test/t-covercmd.sh (+0/-82) test/t-dmeventd-restart.sh (+0/-40) test/t-fsadm.sh (+0/-123) test/t-inconsistent-metadata.sh (+0/-75) test/t-listings.sh (+0/-83) test/t-lock-blocking.sh (+0/-41) test/t-lvchange-mirror.sh (+0/-28) test/t-lvconvert-mirror-basic-0.sh (+0/-12) test/t-lvconvert-mirror-basic-1.sh (+0/-12) test/t-lvconvert-mirror-basic-2.sh (+0/-12) test/t-lvconvert-mirror-basic-3.sh (+0/-12) test/t-lvconvert-mirror-basic.sh (+0/-142) test/t-lvconvert-mirror.sh (+0/-255) test/t-lvconvert-raid.sh (+0/-158) test/t-lvconvert-repair-dmeventd.sh (+0/-26) test/t-lvconvert-repair-policy.sh (+0/-91) test/t-lvconvert-repair-replace.sh (+0/-93) test/t-lvconvert-repair-snapshot.sh (+0/-27) test/t-lvconvert-repair-transient-dmeventd.sh (+0/-27) test/t-lvconvert-repair-transient.sh (+0/-26) test/t-lvconvert-repair.sh (+0/-108) test/t-lvconvert-twostep.sh (+0/-26) test/t-lvcreate-mirror.sh (+0/-41) test/t-lvcreate-operation.sh (+0/-43) test/t-lvcreate-pvtags.sh (+0/-45) test/t-lvcreate-raid.sh (+0/-113) test/t-lvcreate-repair.sh (+0/-97) test/t-lvcreate-small-snap.sh (+0/-30) test/t-lvcreate-usage.sh (+0/-152) test/t-lvextend-percent-extents.sh (+0/-106) test/t-lvextend-snapshot-dmeventd.sh (+0/-51) test/t-lvextend-snapshot-policy.sh (+0/-47) test/t-lvm-init.sh (+0/-21) test/t-lvmcache-exercise.sh (+0/-23) test/t-lvresize-mirror.sh (+0/-38) test/t-lvresize-usage.sh (+0/-20) test/t-mdata-strings.sh (+0/-33) test/t-metadata-balance.sh (+0/-232) test/t-metadata-dirs.sh (+0/-43) test/t-metadata.sh (+0/-80) test/t-mirror-names.sh (+0/-156) test/t-mirror-vgreduce-removemissing.sh (+0/-424) test/t-nomda-missing.sh (+0/-83) test/t-pool-labels.sh (+0/-39) test/t-pv-duplicate.sh (+0/-25) test/t-pv-min-size.sh (+0/-31) test/t-pv-range-overflow.sh (+0/-32) test/t-pvchange-usage.sh (+0/-66) test/t-pvcreate-metadata0.sh (+0/-32) test/t-pvcreate-operation-md.sh (+0/-147) test/t-pvcreate-operation.sh (+0/-121) test/t-pvcreate-usage.sh (+0/-192) test/t-pvmove-basic.sh (+0/-378) test/t-pvremove-usage.sh (+0/-68) test/t-read-ahead.sh (+0/-62) test/t-snapshot-autoumount-dmeventd.sh (+0/-39) test/t-snapshot-merge.sh (+0/-133) test/t-snapshots-of-mirrors.sh (+0/-44) test/t-tags.sh (+0/-74) test/t-test-partition.sh (+0/-30) test/t-topology-support.sh (+0/-106) test/t-unknown-segment.sh (+0/-34) test/t-unlost-pv.sh (+0/-38) test/t-vgcfgbackup-usage.sh (+0/-54) test/t-vgchange-maxlv.sh (+0/-31) test/t-vgchange-sysinit.sh (+0/-51) test/t-vgchange-usage.sh (+0/-44) test/t-vgcreate-usage.sh (+0/-163) test/t-vgextend-restoremissing.sh (+0/-30) test/t-vgextend-usage.sh (+0/-129) test/t-vgimportclone.sh (+0/-36) test/t-vgmerge-operation.sh (+0/-81) test/t-vgmerge-usage.sh (+0/-67) test/t-vgreduce-removemissing-snapshot.sh (+0/-26) test/t-vgreduce-usage.sh (+0/-87) test/t-vgrename-usage.sh (+0/-41) test/t-vgsplit-operation.sh (+0/-290) test/t-vgsplit-stacked.sh (+0/-29) test/t-vgsplit-usage.sh (+0/-168) test/unit/Makefile.in (+33/-0) test/unit/bitset_t.c (+133/-0) test/unit/config_t.c (+156/-0) test/unit/matcher_data.h (+1013/-0) test/unit/matcher_t.c (+85/-0) test/unit/run.c (+29/-0) test/unit/string_t.c (+83/-0) tools/Makefile.in (+2/-4) tools/args.h (+7/-2) tools/commands.h (+16/-7) tools/dmsetup.c (+378/-71) tools/dumpconfig.c (+1/-1) tools/lvchange.c (+45/-17) tools/lvconvert.c (+144/-23) tools/lvcreate.c (+582/-156) tools/lvm.c (+1/-2) tools/lvm2cmd.h (+6/-0) tools/lvmcmdlib.c (+4/-0) tools/lvmcmdline.c (+28/-16) tools/lvmdiskscan.c (+7/-4) tools/lvrename.c (+15/-0) tools/lvresize.c (+128/-31) tools/polldaemon.c (+24/-7) tools/polldaemon.h (+3/-3) tools/pvchange.c (+1/-1) tools/pvck.c (+1/-1) tools/pvcreate.c (+3/-3) tools/pvmove.c (+32/-29) tools/pvremove.c (+9/-6) tools/pvresize.c (+1/-1) tools/pvscan.c (+146/-7) tools/reporter.c (+3/-0) tools/toollib.c (+57/-39) tools/toollib.h (+0/-1) tools/tools.h (+3/-0) tools/vgcfgbackup.c (+1/-1) tools/vgcfgrestore.c (+2/-0) tools/vgchange.c (+17/-10) tools/vgconvert.c (+1/-5) tools/vgcreate.c (+2/-0) tools/vgmerge.c (+2/-1) tools/vgreduce.c (+4/-4) tools/vgremove.c (+1/-1) tools/vgrename.c (+8/-3) tools/vgscan.c (+8/-1) tools/vgsplit.c (+16/-3) udev/13-dm-disk.rules (+0/-27) udev/13-dm-disk.rules.in (+38/-0) udev/69-dm-lvm-metad.rules (+25/-0) udev/Makefile.in (+12/-2) |
||||||||
To merge this branch: | bzr merge lp:~xnox/ubuntu/quantal/lvm2/merge95 | ||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Steve Langasek | Needs Fixing | ||
Kees Cook | Pending | ||
Canonical Foundations Team | Pending | ||
Ubuntu branches | Pending | ||
Review via email: mp+119696@code.launchpad.net |
Commit message
Description of the change
* Debian accepted some of the event manager packaging
* Debian multiarched libdevmapper libs, but not the libdevmapper-dev
* Ubuntu's "Don't install documentation in udebs" vanished and there are no traces of it
* Ubuntu's "don't ship lvm2 init script" transformed into "don't ship clvm init script" see bug 1037033
* I added libdevmapper-dev multiarching
* It looks like Debian refreshed api patch, which is now different to Ubuntu's. Since the 'new' api was only in quantal so far, I am tempted to switch for Debian's API instead & recompile. See $ bzr log -p debian/*.symbols
The rest stayed the same.
- 79. By Dimitri John Ledkov
-
Note additional multi-arch changes only once.
- 80. By Dimitri John Ledkov
-
(omit leading /var/): create /run/lvm if it doesn't exist.
- 81. By Dimitri John Ledkov
-
* debian/
lvm2.{preinst, postinst, postrm} :
- Implement removal of obsolete /etc/init.d/lvm2 conffile, which
should not have been re-introduced in Quantal. - 82. By Dimitri John Ledkov
-
minimise diff
- 83. By Dimitri John Ledkov
-
* libdevmapper-
event1. 02.1:
- Add Breaks: dmeventd (<< 2.02.95-4ubuntu1) due to debian symbol rename
Dimitri John Ledkov (xnox) wrote : | # |
Address all comments.
/etc/init.d/lvm2 was only reintroduced in quantal, added rm_conffile snippets for it which can be removed in R.
Preview Diff
1 | === added file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
3 | +++ .pc/applied-patches 2012-08-21 10:18:22 +0000 | |||
4 | @@ -0,0 +1,8 @@ | |||
5 | 1 | install.patch | ||
6 | 2 | libs-cleanup.patch | ||
7 | 3 | dirs.patch | ||
8 | 4 | force-modprobe.patch | ||
9 | 5 | implicit-pointer.patch | ||
10 | 6 | avoid-dev-block.patch | ||
11 | 7 | dm-event-api.patch | ||
12 | 8 | monitoring-default-off.patch | ||
13 | 0 | 9 | ||
14 | === removed file '.pc/applied-patches' | |||
15 | --- .pc/applied-patches 2012-04-14 02:57:53 +0000 | |||
16 | +++ .pc/applied-patches 1970-01-01 00:00:00 +0000 | |||
17 | @@ -1,7 +0,0 @@ | |||
18 | 1 | install.patch | ||
19 | 2 | libs-cleanup.patch | ||
20 | 3 | dirs.patch | ||
21 | 4 | force-modprobe.patch | ||
22 | 5 | implicit-pointer.patch | ||
23 | 6 | avoid-dev-block.patch | ||
24 | 7 | monitoring-default-off.patch | ||
25 | 8 | 0 | ||
26 | === added directory '.pc/avoid-dev-block.patch' | |||
27 | === removed directory '.pc/avoid-dev-block.patch' | |||
28 | === added directory '.pc/avoid-dev-block.patch/lib' | |||
29 | === removed directory '.pc/avoid-dev-block.patch/lib' | |||
30 | === added directory '.pc/avoid-dev-block.patch/lib/device' | |||
31 | === removed directory '.pc/avoid-dev-block.patch/lib/device' | |||
32 | === added file '.pc/avoid-dev-block.patch/lib/device/dev-cache.c' | |||
33 | --- .pc/avoid-dev-block.patch/lib/device/dev-cache.c 1970-01-01 00:00:00 +0000 | |||
34 | +++ .pc/avoid-dev-block.patch/lib/device/dev-cache.c 2012-08-21 10:18:22 +0000 | |||
35 | @@ -0,0 +1,1018 @@ | |||
36 | 1 | /* | ||
37 | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. | ||
38 | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. | ||
39 | 4 | * | ||
40 | 5 | * This file is part of LVM2. | ||
41 | 6 | * | ||
42 | 7 | * This copyrighted material is made available to anyone wishing to use, | ||
43 | 8 | * modify, copy, or redistribute it subject to the terms and conditions | ||
44 | 9 | * of the GNU Lesser General Public License v.2.1. | ||
45 | 10 | * | ||
46 | 11 | * You should have received a copy of the GNU Lesser General Public License | ||
47 | 12 | * along with this program; if not, write to the Free Software Foundation, | ||
48 | 13 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
49 | 14 | */ | ||
50 | 15 | |||
51 | 16 | #include "lib.h" | ||
52 | 17 | #include "dev-cache.h" | ||
53 | 18 | #include "lvm-types.h" | ||
54 | 19 | #include "btree.h" | ||
55 | 20 | #include "filter.h" | ||
56 | 21 | #include "filter-persistent.h" | ||
57 | 22 | #include "toolcontext.h" | ||
58 | 23 | |||
59 | 24 | #include <unistd.h> | ||
60 | 25 | #include <sys/param.h> | ||
61 | 26 | #include <dirent.h> | ||
62 | 27 | |||
63 | 28 | struct dev_iter { | ||
64 | 29 | struct btree_iter *current; | ||
65 | 30 | struct dev_filter *filter; | ||
66 | 31 | }; | ||
67 | 32 | |||
68 | 33 | struct dir_list { | ||
69 | 34 | struct dm_list list; | ||
70 | 35 | char dir[0]; | ||
71 | 36 | }; | ||
72 | 37 | |||
73 | 38 | static struct { | ||
74 | 39 | struct dm_pool *mem; | ||
75 | 40 | struct dm_hash_table *names; | ||
76 | 41 | struct btree *devices; | ||
77 | 42 | struct dm_regex *preferred_names_matcher; | ||
78 | 43 | const char *dev_dir; | ||
79 | 44 | |||
80 | 45 | int has_scanned; | ||
81 | 46 | struct dm_list dirs; | ||
82 | 47 | struct dm_list files; | ||
83 | 48 | |||
84 | 49 | } _cache; | ||
85 | 50 | |||
86 | 51 | #define _zalloc(x) dm_pool_zalloc(_cache.mem, (x)) | ||
87 | 52 | #define _free(x) dm_pool_free(_cache.mem, (x)) | ||
88 | 53 | #define _strdup(x) dm_pool_strdup(_cache.mem, (x)) | ||
89 | 54 | |||
90 | 55 | static int _insert(const char *path, int rec, int check_with_udev_db); | ||
91 | 56 | |||
92 | 57 | /* Setup non-zero members of passed zeroed 'struct device' */ | ||
93 | 58 | static void _dev_init(struct device *dev, int max_error_count) | ||
94 | 59 | { | ||
95 | 60 | dev->block_size = -1; | ||
96 | 61 | dev->fd = -1; | ||
97 | 62 | dev->read_ahead = -1; | ||
98 | 63 | dev->max_error_count = max_error_count; | ||
99 | 64 | |||
100 | 65 | dm_list_init(&dev->aliases); | ||
101 | 66 | dm_list_init(&dev->open_list); | ||
102 | 67 | } | ||
103 | 68 | |||
104 | 69 | struct device *dev_create_file(const char *filename, struct device *dev, | ||
105 | 70 | struct str_list *alias, int use_malloc) | ||
106 | 71 | { | ||
107 | 72 | int allocate = !dev; | ||
108 | 73 | |||
109 | 74 | if (allocate) { | ||
110 | 75 | if (use_malloc) { | ||
111 | 76 | if (!(dev = dm_zalloc(sizeof(*dev)))) { | ||
112 | 77 | log_error("struct device allocation failed"); | ||
113 | 78 | return NULL; | ||
114 | 79 | } | ||
115 | 80 | if (!(alias = dm_zalloc(sizeof(*alias)))) { | ||
116 | 81 | log_error("struct str_list allocation failed"); | ||
117 | 82 | dm_free(dev); | ||
118 | 83 | return NULL; | ||
119 | 84 | } | ||
120 | 85 | if (!(alias->str = dm_strdup(filename))) { | ||
121 | 86 | log_error("filename strdup failed"); | ||
122 | 87 | dm_free(dev); | ||
123 | 88 | dm_free(alias); | ||
124 | 89 | return NULL; | ||
125 | 90 | } | ||
126 | 91 | } else { | ||
127 | 92 | if (!(dev = _zalloc(sizeof(*dev)))) { | ||
128 | 93 | log_error("struct device allocation failed"); | ||
129 | 94 | return NULL; | ||
130 | 95 | } | ||
131 | 96 | if (!(alias = _zalloc(sizeof(*alias)))) { | ||
132 | 97 | log_error("struct str_list allocation failed"); | ||
133 | 98 | _free(dev); | ||
134 | 99 | return NULL; | ||
135 | 100 | } | ||
136 | 101 | if (!(alias->str = _strdup(filename))) { | ||
137 | 102 | log_error("filename strdup failed"); | ||
138 | 103 | return NULL; | ||
139 | 104 | } | ||
140 | 105 | } | ||
141 | 106 | } else if (!(alias->str = dm_strdup(filename))) { | ||
142 | 107 | log_error("filename strdup failed"); | ||
143 | 108 | return NULL; | ||
144 | 109 | } | ||
145 | 110 | |||
146 | 111 | _dev_init(dev, NO_DEV_ERROR_COUNT_LIMIT); | ||
147 | 112 | dev->flags = DEV_REGULAR | ((use_malloc) ? DEV_ALLOCED : 0); | ||
148 | 113 | dm_list_add(&dev->aliases, &alias->list); | ||
149 | 114 | |||
150 | 115 | return dev; | ||
151 | 116 | } | ||
152 | 117 | |||
153 | 118 | static struct device *_dev_create(dev_t d) | ||
154 | 119 | { | ||
155 | 120 | struct device *dev; | ||
156 | 121 | |||
157 | 122 | if (!(dev = _zalloc(sizeof(*dev)))) { | ||
158 | 123 | log_error("struct device allocation failed"); | ||
159 | 124 | return NULL; | ||
160 | 125 | } | ||
161 | 126 | |||
162 | 127 | _dev_init(dev, dev_disable_after_error_count()); | ||
163 | 128 | dev->dev = d; | ||
164 | 129 | |||
165 | 130 | return dev; | ||
166 | 131 | } | ||
167 | 132 | |||
168 | 133 | void dev_set_preferred_name(struct str_list *sl, struct device *dev) | ||
169 | 134 | { | ||
170 | 135 | /* | ||
171 | 136 | * Don't interfere with ordering specified in config file. | ||
172 | 137 | */ | ||
173 | 138 | if (_cache.preferred_names_matcher) | ||
174 | 139 | return; | ||
175 | 140 | |||
176 | 141 | log_debug("%s: New preferred name", sl->str); | ||
177 | 142 | dm_list_del(&sl->list); | ||
178 | 143 | dm_list_add_h(&dev->aliases, &sl->list); | ||
179 | 144 | } | ||
180 | 145 | |||
181 | 146 | /* | ||
182 | 147 | * Check whether path0 or path1 contains the subpath. The path that | ||
183 | 148 | * *does not* contain the subpath wins (return 0 or 1). If both paths | ||
184 | 149 | * contain the subpath, return -1. If none of them contains the subpath, | ||
185 | 150 | * return -2. | ||
186 | 151 | */ | ||
187 | 152 | static int _builtin_preference(const char *path0, const char *path1, | ||
188 | 153 | size_t skip_prefix_count, const char *subpath) | ||
189 | 154 | { | ||
190 | 155 | size_t subpath_len; | ||
191 | 156 | int r0, r1; | ||
192 | 157 | |||
193 | 158 | subpath_len = strlen(subpath); | ||
194 | 159 | |||
195 | 160 | r0 = !strncmp(path0 + skip_prefix_count, subpath, subpath_len); | ||
196 | 161 | r1 = !strncmp(path1 + skip_prefix_count, subpath, subpath_len); | ||
197 | 162 | |||
198 | 163 | if (!r0 && r1) | ||
199 | 164 | /* path0 does not have the subpath - it wins */ | ||
200 | 165 | return 0; | ||
201 | 166 | else if (r0 && !r1) | ||
202 | 167 | /* path1 does not have the subpath - it wins */ | ||
203 | 168 | return 1; | ||
204 | 169 | else if (r0 && r1) | ||
205 | 170 | /* both of them have the subpath */ | ||
206 | 171 | return -1; | ||
207 | 172 | |||
208 | 173 | /* no path has the subpath */ | ||
209 | 174 | return -2; | ||
210 | 175 | } | ||
211 | 176 | |||
212 | 177 | static int _apply_builtin_path_preference_rules(const char *path0, const char *path1) | ||
213 | 178 | { | ||
214 | 179 | size_t devdir_len; | ||
215 | 180 | int r; | ||
216 | 181 | |||
217 | 182 | devdir_len = strlen(_cache.dev_dir); | ||
218 | 183 | |||
219 | 184 | if (!strncmp(path0, _cache.dev_dir, devdir_len) && | ||
220 | 185 | !strncmp(path1, _cache.dev_dir, devdir_len)) { | ||
221 | 186 | /* | ||
222 | 187 | * We're trying to achieve the ordering: | ||
223 | 188 | * /dev/block/ < /dev/dm-* < /dev/disk/ < /dev/mapper/ < anything else | ||
224 | 189 | */ | ||
225 | 190 | |||
226 | 191 | /* Prefer any other path over /dev/block/ path. */ | ||
227 | 192 | if ((r = _builtin_preference(path0, path1, devdir_len, "block/")) >= -1) | ||
228 | 193 | return r; | ||
229 | 194 | |||
230 | 195 | /* Prefer any other path over /dev/dm-* path. */ | ||
231 | 196 | if ((r = _builtin_preference(path0, path1, devdir_len, "dm-")) >= -1) | ||
232 | 197 | return r; | ||
233 | 198 | |||
234 | 199 | /* Prefer any other path over /dev/disk/ path. */ | ||
235 | 200 | if ((r = _builtin_preference(path0, path1, devdir_len, "disk/")) >= -1) | ||
236 | 201 | return r; | ||
237 | 202 | |||
238 | 203 | /* Prefer any other path over /dev/mapper/ path. */ | ||
239 | 204 | if ((r = _builtin_preference(path0, path1, 0, dm_dir())) >= -1) | ||
240 | 205 | return r; | ||
241 | 206 | } | ||
242 | 207 | |||
243 | 208 | return -1; | ||
244 | 209 | } | ||
245 | 210 | |||
246 | 211 | /* Return 1 if we prefer path1 else return 0 */ | ||
247 | 212 | static int _compare_paths(const char *path0, const char *path1) | ||
248 | 213 | { | ||
249 | 214 | int slash0 = 0, slash1 = 0; | ||
250 | 215 | int m0, m1; | ||
251 | 216 | const char *p; | ||
252 | 217 | char p0[PATH_MAX], p1[PATH_MAX]; | ||
253 | 218 | char *s0, *s1; | ||
254 | 219 | struct stat stat0, stat1; | ||
255 | 220 | int r; | ||
256 | 221 | |||
257 | 222 | /* | ||
258 | 223 | * FIXME Better to compare patterns one-at-a-time against all names. | ||
259 | 224 | */ | ||
260 | 225 | if (_cache.preferred_names_matcher) { | ||
261 | 226 | m0 = dm_regex_match(_cache.preferred_names_matcher, path0); | ||
262 | 227 | m1 = dm_regex_match(_cache.preferred_names_matcher, path1); | ||
263 | 228 | |||
264 | 229 | if (m0 != m1) { | ||
265 | 230 | if (m0 < 0) | ||
266 | 231 | return 1; | ||
267 | 232 | if (m1 < 0) | ||
268 | 233 | return 0; | ||
269 | 234 | if (m0 < m1) | ||
270 | 235 | return 1; | ||
271 | 236 | if (m1 < m0) | ||
272 | 237 | return 0; | ||
273 | 238 | } | ||
274 | 239 | } | ||
275 | 240 | |||
276 | 241 | /* Apply built-in preference rules first. */ | ||
277 | 242 | if ((r = _apply_builtin_path_preference_rules(path0, path1)) >= 0) | ||
278 | 243 | return r; | ||
279 | 244 | |||
280 | 245 | /* Return the path with fewer slashes */ | ||
281 | 246 | for (p = path0; p++; p = (const char *) strchr(p, '/')) | ||
282 | 247 | slash0++; | ||
283 | 248 | |||
284 | 249 | for (p = path1; p++; p = (const char *) strchr(p, '/')) | ||
285 | 250 | slash1++; | ||
286 | 251 | |||
287 | 252 | if (slash0 < slash1) | ||
288 | 253 | return 0; | ||
289 | 254 | if (slash1 < slash0) | ||
290 | 255 | return 1; | ||
291 | 256 | |||
292 | 257 | strncpy(p0, path0, sizeof(p0) - 1); | ||
293 | 258 | p0[sizeof(p0) - 1] = '\0'; | ||
294 | 259 | strncpy(p1, path1, sizeof(p1) - 1); | ||
295 | 260 | p1[sizeof(p1) - 1] = '\0'; | ||
296 | 261 | s0 = p0 + 1; | ||
297 | 262 | s1 = p1 + 1; | ||
298 | 263 | |||
299 | 264 | /* | ||
300 | 265 | * If we reach here, both paths are the same length. | ||
301 | 266 | * Now skip past identical path components. | ||
302 | 267 | */ | ||
303 | 268 | while (*s0 && *s0 == *s1) | ||
304 | 269 | s0++, s1++; | ||
305 | 270 | |||
306 | 271 | /* We prefer symlinks - they exist for a reason! | ||
307 | 272 | * So we prefer a shorter path before the first symlink in the name. | ||
308 | 273 | * FIXME Configuration option to invert this? */ | ||
309 | 274 | while (s0) { | ||
310 | 275 | s0 = strchr(s0, '/'); | ||
311 | 276 | s1 = strchr(s1, '/'); | ||
312 | 277 | if (s0) { | ||
313 | 278 | *s0 = '\0'; | ||
314 | 279 | *s1 = '\0'; | ||
315 | 280 | } | ||
316 | 281 | if (lstat(p0, &stat0)) { | ||
317 | 282 | log_sys_very_verbose("lstat", p0); | ||
318 | 283 | return 1; | ||
319 | 284 | } | ||
320 | 285 | if (lstat(p1, &stat1)) { | ||
321 | 286 | log_sys_very_verbose("lstat", p1); | ||
322 | 287 | return 0; | ||
323 | 288 | } | ||
324 | 289 | if (S_ISLNK(stat0.st_mode) && !S_ISLNK(stat1.st_mode)) | ||
325 | 290 | return 0; | ||
326 | 291 | if (!S_ISLNK(stat0.st_mode) && S_ISLNK(stat1.st_mode)) | ||
327 | 292 | return 1; | ||
328 | 293 | if (s0) { | ||
329 | 294 | *s0++ = '/'; | ||
330 | 295 | *s1++ = '/'; | ||
331 | 296 | } | ||
332 | 297 | } | ||
333 | 298 | |||
334 | 299 | /* ASCII comparison */ | ||
335 | 300 | if (strcmp(path0, path1) < 0) | ||
336 | 301 | return 0; | ||
337 | 302 | else | ||
338 | 303 | return 1; | ||
339 | 304 | } | ||
340 | 305 | |||
341 | 306 | static int _add_alias(struct device *dev, const char *path) | ||
342 | 307 | { | ||
343 | 308 | struct str_list *sl = _zalloc(sizeof(*sl)); | ||
344 | 309 | struct str_list *strl; | ||
345 | 310 | const char *oldpath; | ||
346 | 311 | int prefer_old = 1; | ||
347 | 312 | |||
348 | 313 | if (!sl) | ||
349 | 314 | return_0; | ||
350 | 315 | |||
351 | 316 | /* Is name already there? */ | ||
352 | 317 | dm_list_iterate_items(strl, &dev->aliases) { | ||
353 | 318 | if (!strcmp(strl->str, path)) { | ||
354 | 319 | log_debug("%s: Already in device cache", path); | ||
355 | 320 | return 1; | ||
356 | 321 | } | ||
357 | 322 | } | ||
358 | 323 | |||
359 | 324 | sl->str = path; | ||
360 | 325 | |||
361 | 326 | if (!dm_list_empty(&dev->aliases)) { | ||
362 | 327 | oldpath = dm_list_item(dev->aliases.n, struct str_list)->str; | ||
363 | 328 | prefer_old = _compare_paths(path, oldpath); | ||
364 | 329 | log_debug("%s: Aliased to %s in device cache%s", | ||
365 | 330 | path, oldpath, prefer_old ? "" : " (preferred name)"); | ||
366 | 331 | |||
367 | 332 | } else | ||
368 | 333 | log_debug("%s: Added to device cache", path); | ||
369 | 334 | |||
370 | 335 | if (prefer_old) | ||
371 | 336 | dm_list_add(&dev->aliases, &sl->list); | ||
372 | 337 | else | ||
373 | 338 | dm_list_add_h(&dev->aliases, &sl->list); | ||
374 | 339 | |||
375 | 340 | return 1; | ||
376 | 341 | } | ||
377 | 342 | |||
378 | 343 | /* | ||
379 | 344 | * Either creates a new dev, or adds an alias to | ||
380 | 345 | * an existing dev. | ||
381 | 346 | */ | ||
382 | 347 | static int _insert_dev(const char *path, dev_t d) | ||
383 | 348 | { | ||
384 | 349 | struct device *dev; | ||
385 | 350 | static dev_t loopfile_count = 0; | ||
386 | 351 | int loopfile = 0; | ||
387 | 352 | char *path_copy; | ||
388 | 353 | |||
389 | 354 | /* Generate pretend device numbers for loopfiles */ | ||
390 | 355 | if (!d) { | ||
391 | 356 | if (dm_hash_lookup(_cache.names, path)) | ||
392 | 357 | return 1; | ||
393 | 358 | d = ++loopfile_count; | ||
394 | 359 | loopfile = 1; | ||
395 | 360 | } | ||
396 | 361 | |||
397 | 362 | /* is this device already registered ? */ | ||
398 | 363 | if (!(dev = (struct device *) btree_lookup(_cache.devices, | ||
399 | 364 | (uint32_t) d))) { | ||
400 | 365 | /* create new device */ | ||
401 | 366 | if (loopfile) { | ||
402 | 367 | if (!(dev = dev_create_file(path, NULL, NULL, 0))) | ||
403 | 368 | return_0; | ||
404 | 369 | } else if (!(dev = _dev_create(d))) | ||
405 | 370 | return_0; | ||
406 | 371 | |||
407 | 372 | if (!(btree_insert(_cache.devices, (uint32_t) d, dev))) { | ||
408 | 373 | log_error("Couldn't insert device into binary tree."); | ||
409 | 374 | _free(dev); | ||
410 | 375 | return 0; | ||
411 | 376 | } | ||
412 | 377 | } | ||
413 | 378 | |||
414 | 379 | if (!(path_copy = dm_pool_strdup(_cache.mem, path))) { | ||
415 | 380 | log_error("Failed to duplicate path string."); | ||
416 | 381 | return 0; | ||
417 | 382 | } | ||
418 | 383 | |||
419 | 384 | if (!loopfile && !_add_alias(dev, path_copy)) { | ||
420 | 385 | log_error("Couldn't add alias to dev cache."); | ||
421 | 386 | return 0; | ||
422 | 387 | } | ||
423 | 388 | |||
424 | 389 | if (!dm_hash_insert(_cache.names, path_copy, dev)) { | ||
425 | 390 | log_error("Couldn't add name to hash in dev cache."); | ||
426 | 391 | return 0; | ||
427 | 392 | } | ||
428 | 393 | |||
429 | 394 | return 1; | ||
430 | 395 | } | ||
431 | 396 | |||
432 | 397 | static char *_join(const char *dir, const char *name) | ||
433 | 398 | { | ||
434 | 399 | size_t len = strlen(dir) + strlen(name) + 2; | ||
435 | 400 | char *r = dm_malloc(len); | ||
436 | 401 | if (r) | ||
437 | 402 | snprintf(r, len, "%s/%s", dir, name); | ||
438 | 403 | |||
439 | 404 | return r; | ||
440 | 405 | } | ||
441 | 406 | |||
442 | 407 | /* | ||
443 | 408 | * Get rid of extra slashes in the path string. | ||
444 | 409 | */ | ||
445 | 410 | static void _collapse_slashes(char *str) | ||
446 | 411 | { | ||
447 | 412 | char *ptr; | ||
448 | 413 | int was_slash = 0; | ||
449 | 414 | |||
450 | 415 | for (ptr = str; *ptr; ptr++) { | ||
451 | 416 | if (*ptr == '/') { | ||
452 | 417 | if (was_slash) | ||
453 | 418 | continue; | ||
454 | 419 | |||
455 | 420 | was_slash = 1; | ||
456 | 421 | } else | ||
457 | 422 | was_slash = 0; | ||
458 | 423 | *str++ = *ptr; | ||
459 | 424 | } | ||
460 | 425 | |||
461 | 426 | *str = *ptr; | ||
462 | 427 | } | ||
463 | 428 | |||
464 | 429 | static int _insert_dir(const char *dir) | ||
465 | 430 | { | ||
466 | 431 | int n, dirent_count, r = 1; | ||
467 | 432 | struct dirent **dirent; | ||
468 | 433 | char *path; | ||
469 | 434 | |||
470 | 435 | dirent_count = scandir(dir, &dirent, NULL, alphasort); | ||
471 | 436 | if (dirent_count > 0) { | ||
472 | 437 | for (n = 0; n < dirent_count; n++) { | ||
473 | 438 | if (dirent[n]->d_name[0] == '.') { | ||
474 | 439 | free(dirent[n]); | ||
475 | 440 | continue; | ||
476 | 441 | } | ||
477 | 442 | |||
478 | 443 | if (!(path = _join(dir, dirent[n]->d_name))) | ||
479 | 444 | return_0; | ||
480 | 445 | |||
481 | 446 | _collapse_slashes(path); | ||
482 | 447 | r &= _insert(path, 1, 0); | ||
483 | 448 | dm_free(path); | ||
484 | 449 | |||
485 | 450 | free(dirent[n]); | ||
486 | 451 | } | ||
487 | 452 | free(dirent); | ||
488 | 453 | } | ||
489 | 454 | |||
490 | 455 | return r; | ||
491 | 456 | } | ||
492 | 457 | |||
493 | 458 | static int _insert_file(const char *path) | ||
494 | 459 | { | ||
495 | 460 | struct stat info; | ||
496 | 461 | |||
497 | 462 | if (stat(path, &info) < 0) { | ||
498 | 463 | log_sys_very_verbose("stat", path); | ||
499 | 464 | return 0; | ||
500 | 465 | } | ||
501 | 466 | |||
502 | 467 | if (!S_ISREG(info.st_mode)) { | ||
503 | 468 | log_debug("%s: Not a regular file", path); | ||
504 | 469 | return 0; | ||
505 | 470 | } | ||
506 | 471 | |||
507 | 472 | if (!_insert_dev(path, 0)) | ||
508 | 473 | return_0; | ||
509 | 474 | |||
510 | 475 | return 1; | ||
511 | 476 | } | ||
512 | 477 | |||
513 | 478 | #ifdef UDEV_SYNC_SUPPORT | ||
514 | 479 | |||
515 | 480 | static int _device_in_udev_db(const dev_t d) | ||
516 | 481 | { | ||
517 | 482 | struct udev *udev; | ||
518 | 483 | struct udev_device *udev_device; | ||
519 | 484 | |||
520 | 485 | if (!(udev = udev_get_library_context())) | ||
521 | 486 | return_0; | ||
522 | 487 | |||
523 | 488 | if ((udev_device = udev_device_new_from_devnum(udev, 'b', d))) { | ||
524 | 489 | udev_device_unref(udev_device); | ||
525 | 490 | return 1; | ||
526 | 491 | } | ||
527 | 492 | |||
528 | 493 | return 0; | ||
529 | 494 | } | ||
530 | 495 | |||
531 | 496 | static int _insert_udev_dir(struct udev *udev, const char *dir) | ||
532 | 497 | { | ||
533 | 498 | struct udev_enumerate *udev_enum = NULL; | ||
534 | 499 | struct udev_list_entry *device_entry, *symlink_entry; | ||
535 | 500 | const char *node_name, *symlink_name; | ||
536 | 501 | struct udev_device *device; | ||
537 | 502 | int r = 1; | ||
538 | 503 | |||
539 | 504 | if (!(udev_enum = udev_enumerate_new(udev))) | ||
540 | 505 | goto bad; | ||
541 | 506 | |||
542 | 507 | if (udev_enumerate_add_match_subsystem(udev_enum, "block") || | ||
543 | 508 | udev_enumerate_scan_devices(udev_enum)) | ||
544 | 509 | goto bad; | ||
545 | 510 | |||
546 | 511 | udev_list_entry_foreach(device_entry, udev_enumerate_get_list_entry(udev_enum)) { | ||
547 | 512 | if (!(device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(device_entry)))) { | ||
548 | 513 | log_warn("WARNING: udev failed to return a device entry."); | ||
549 | 514 | continue; | ||
550 | 515 | } | ||
551 | 516 | |||
552 | 517 | if (!(node_name = udev_device_get_devnode(device))) | ||
553 | 518 | log_warn("WARNING: udev failed to return a device node."); | ||
554 | 519 | else | ||
555 | 520 | r &= _insert(node_name, 0, 0); | ||
556 | 521 | |||
557 | 522 | udev_list_entry_foreach(symlink_entry, udev_device_get_devlinks_list_entry(device)) { | ||
558 | 523 | if (!(symlink_name = udev_list_entry_get_name(symlink_entry))) | ||
559 | 524 | log_warn("WARNING: udev failed to return a symlink name."); | ||
560 | 525 | else | ||
561 | 526 | r &= _insert(symlink_name, 0, 0); | ||
562 | 527 | } | ||
563 | 528 | |||
564 | 529 | udev_device_unref(device); | ||
565 | 530 | } | ||
566 | 531 | |||
567 | 532 | udev_enumerate_unref(udev_enum); | ||
568 | 533 | return r; | ||
569 | 534 | |||
570 | 535 | bad: | ||
571 | 536 | log_error("Failed to enumerate udev device list."); | ||
572 | 537 | udev_enumerate_unref(udev_enum); | ||
573 | 538 | return 0; | ||
574 | 539 | } | ||
575 | 540 | |||
576 | 541 | static void _insert_dirs(struct dm_list *dirs) | ||
577 | 542 | { | ||
578 | 543 | struct dir_list *dl; | ||
579 | 544 | struct udev *udev; | ||
580 | 545 | int with_udev; | ||
581 | 546 | |||
582 | 547 | with_udev = obtain_device_list_from_udev() && | ||
583 | 548 | (udev = udev_get_library_context()); | ||
584 | 549 | |||
585 | 550 | dm_list_iterate_items(dl, &_cache.dirs) { | ||
586 | 551 | if (with_udev) { | ||
587 | 552 | if (!_insert_udev_dir(udev, dl->dir)) | ||
588 | 553 | log_debug("%s: Failed to insert devices from " | ||
589 | 554 | "udev-managed directory to device " | ||
590 | 555 | "cache fully", dl->dir); | ||
591 | 556 | } | ||
592 | 557 | else if (!_insert_dir(dl->dir)) | ||
593 | 558 | log_debug("%s: Failed to insert devices to " | ||
594 | 559 | "device cache fully", dl->dir); | ||
595 | 560 | } | ||
596 | 561 | } | ||
597 | 562 | |||
598 | 563 | #else /* UDEV_SYNC_SUPPORT */ | ||
599 | 564 | |||
600 | 565 | static int _device_in_udev_db(const dev_t d) | ||
601 | 566 | { | ||
602 | 567 | return 0; | ||
603 | 568 | } | ||
604 | 569 | |||
605 | 570 | static void _insert_dirs(struct dm_list *dirs) | ||
606 | 571 | { | ||
607 | 572 | struct dir_list *dl; | ||
608 | 573 | |||
609 | 574 | dm_list_iterate_items(dl, &_cache.dirs) | ||
610 | 575 | _insert_dir(dl->dir); | ||
611 | 576 | } | ||
612 | 577 | |||
613 | 578 | #endif /* UDEV_SYNC_SUPPORT */ | ||
614 | 579 | |||
615 | 580 | static int _insert(const char *path, int rec, int check_with_udev_db) | ||
616 | 581 | { | ||
617 | 582 | struct stat info; | ||
618 | 583 | int r = 0; | ||
619 | 584 | |||
620 | 585 | if (stat(path, &info) < 0) { | ||
621 | 586 | log_sys_very_verbose("stat", path); | ||
622 | 587 | return 0; | ||
623 | 588 | } | ||
624 | 589 | |||
625 | 590 | if (check_with_udev_db && !_device_in_udev_db(info.st_rdev)) { | ||
626 | 591 | log_very_verbose("%s: Not in udev db", path); | ||
627 | 592 | return 0; | ||
628 | 593 | } | ||
629 | 594 | |||
630 | 595 | if (S_ISDIR(info.st_mode)) { /* add a directory */ | ||
631 | 596 | /* check it's not a symbolic link */ | ||
632 | 597 | if (lstat(path, &info) < 0) { | ||
633 | 598 | log_sys_very_verbose("lstat", path); | ||
634 | 599 | return 0; | ||
635 | 600 | } | ||
636 | 601 | |||
637 | 602 | if (S_ISLNK(info.st_mode)) { | ||
638 | 603 | log_debug("%s: Symbolic link to directory", path); | ||
639 | 604 | return 0; | ||
640 | 605 | } | ||
641 | 606 | |||
642 | 607 | if (rec) | ||
643 | 608 | r = _insert_dir(path); | ||
644 | 609 | |||
645 | 610 | } else { /* add a device */ | ||
646 | 611 | if (!S_ISBLK(info.st_mode)) { | ||
647 | 612 | log_debug("%s: Not a block device", path); | ||
648 | 613 | return 0; | ||
649 | 614 | } | ||
650 | 615 | |||
651 | 616 | if (!_insert_dev(path, info.st_rdev)) | ||
652 | 617 | return_0; | ||
653 | 618 | |||
654 | 619 | r = 1; | ||
655 | 620 | } | ||
656 | 621 | |||
657 | 622 | return r; | ||
658 | 623 | } | ||
659 | 624 | |||
660 | 625 | static void _full_scan(int dev_scan) | ||
661 | 626 | { | ||
662 | 627 | struct dir_list *dl; | ||
663 | 628 | |||
664 | 629 | if (_cache.has_scanned && !dev_scan) | ||
665 | 630 | return; | ||
666 | 631 | |||
667 | 632 | _insert_dirs(&_cache.dirs); | ||
668 | 633 | |||
669 | 634 | dm_list_iterate_items(dl, &_cache.files) | ||
670 | 635 | _insert_file(dl->dir); | ||
671 | 636 | |||
672 | 637 | _cache.has_scanned = 1; | ||
673 | 638 | init_full_scan_done(1); | ||
674 | 639 | } | ||
675 | 640 | |||
676 | 641 | int dev_cache_has_scanned(void) | ||
677 | 642 | { | ||
678 | 643 | return _cache.has_scanned; | ||
679 | 644 | } | ||
680 | 645 | |||
681 | 646 | void dev_cache_scan(int do_scan) | ||
682 | 647 | { | ||
683 | 648 | if (!do_scan) | ||
684 | 649 | _cache.has_scanned = 1; | ||
685 | 650 | else | ||
686 | 651 | _full_scan(1); | ||
687 | 652 | } | ||
688 | 653 | |||
689 | 654 | static int _init_preferred_names(struct cmd_context *cmd) | ||
690 | 655 | { | ||
691 | 656 | const struct dm_config_node *cn; | ||
692 | 657 | const struct dm_config_value *v; | ||
693 | 658 | struct dm_pool *scratch = NULL; | ||
694 | 659 | const char **regex; | ||
695 | 660 | unsigned count = 0; | ||
696 | 661 | int i, r = 0; | ||
697 | 662 | |||
698 | 663 | _cache.preferred_names_matcher = NULL; | ||
699 | 664 | |||
700 | 665 | if (!(cn = find_config_tree_node(cmd, "devices/preferred_names")) || | ||
701 | 666 | cn->v->type == DM_CFG_EMPTY_ARRAY) { | ||
702 | 667 | log_very_verbose("devices/preferred_names not found in config file: " | ||
703 | 668 | "using built-in preferences"); | ||
704 | 669 | return 1; | ||
705 | 670 | } | ||
706 | 671 | |||
707 | 672 | for (v = cn->v; v; v = v->next) { | ||
708 | 673 | if (v->type != DM_CFG_STRING) { | ||
709 | 674 | log_error("preferred_names patterns must be enclosed in quotes"); | ||
710 | 675 | return 0; | ||
711 | 676 | } | ||
712 | 677 | |||
713 | 678 | count++; | ||
714 | 679 | } | ||
715 | 680 | |||
716 | 681 | if (!(scratch = dm_pool_create("preferred device name matcher", 1024))) | ||
717 | 682 | return_0; | ||
718 | 683 | |||
719 | 684 | if (!(regex = dm_pool_alloc(scratch, sizeof(*regex) * count))) { | ||
720 | 685 | log_error("Failed to allocate preferred device name " | ||
721 | 686 | "pattern list."); | ||
722 | 687 | goto out; | ||
723 | 688 | } | ||
724 | 689 | |||
725 | 690 | for (v = cn->v, i = count - 1; v; v = v->next, i--) { | ||
726 | 691 | if (!(regex[i] = dm_pool_strdup(scratch, v->v.str))) { | ||
727 | 692 | log_error("Failed to allocate a preferred device name " | ||
728 | 693 | "pattern."); | ||
729 | 694 | goto out; | ||
730 | 695 | } | ||
731 | 696 | } | ||
732 | 697 | |||
733 | 698 | if (!(_cache.preferred_names_matcher = | ||
734 | 699 | dm_regex_create(_cache.mem, regex, count))) { | ||
735 | 700 | log_error("Preferred device name pattern matcher creation failed."); | ||
736 | 701 | goto out; | ||
737 | 702 | } | ||
738 | 703 | |||
739 | 704 | r = 1; | ||
740 | 705 | |||
741 | 706 | out: | ||
742 | 707 | dm_pool_destroy(scratch); | ||
743 | 708 | |||
744 | 709 | return r; | ||
745 | 710 | } | ||
746 | 711 | |||
747 | 712 | int dev_cache_init(struct cmd_context *cmd) | ||
748 | 713 | { | ||
749 | 714 | _cache.names = NULL; | ||
750 | 715 | _cache.has_scanned = 0; | ||
751 | 716 | |||
752 | 717 | if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024))) | ||
753 | 718 | return_0; | ||
754 | 719 | |||
755 | 720 | if (!(_cache.names = dm_hash_create(128))) { | ||
756 | 721 | dm_pool_destroy(_cache.mem); | ||
757 | 722 | _cache.mem = 0; | ||
758 | 723 | return_0; | ||
759 | 724 | } | ||
760 | 725 | |||
761 | 726 | if (!(_cache.devices = btree_create(_cache.mem))) { | ||
762 | 727 | log_error("Couldn't create binary tree for dev-cache."); | ||
763 | 728 | goto bad; | ||
764 | 729 | } | ||
765 | 730 | |||
766 | 731 | if (!(_cache.dev_dir = _strdup(cmd->dev_dir))) { | ||
767 | 732 | log_error("strdup dev_dir failed."); | ||
768 | 733 | goto bad; | ||
769 | 734 | } | ||
770 | 735 | |||
771 | 736 | dm_list_init(&_cache.dirs); | ||
772 | 737 | dm_list_init(&_cache.files); | ||
773 | 738 | |||
774 | 739 | if (!_init_preferred_names(cmd)) | ||
775 | 740 | goto_bad; | ||
776 | 741 | |||
777 | 742 | return 1; | ||
778 | 743 | |||
779 | 744 | bad: | ||
780 | 745 | dev_cache_exit(); | ||
781 | 746 | return 0; | ||
782 | 747 | } | ||
783 | 748 | |||
784 | 749 | static void _check_closed(struct device *dev) | ||
785 | 750 | { | ||
786 | 751 | if (dev->fd >= 0) | ||
787 | 752 | log_error("Device '%s' has been left open.", dev_name(dev)); | ||
788 | 753 | } | ||
789 | 754 | |||
790 | 755 | static void _check_for_open_devices(void) | ||
791 | 756 | { | ||
792 | 757 | dm_hash_iter(_cache.names, (dm_hash_iterate_fn) _check_closed); | ||
793 | 758 | } | ||
794 | 759 | |||
795 | 760 | void dev_cache_exit(void) | ||
796 | 761 | { | ||
797 | 762 | if (_cache.names) | ||
798 | 763 | _check_for_open_devices(); | ||
799 | 764 | |||
800 | 765 | if (_cache.preferred_names_matcher) | ||
801 | 766 | _cache.preferred_names_matcher = NULL; | ||
802 | 767 | |||
803 | 768 | if (_cache.mem) { | ||
804 | 769 | dm_pool_destroy(_cache.mem); | ||
805 | 770 | _cache.mem = NULL; | ||
806 | 771 | } | ||
807 | 772 | |||
808 | 773 | if (_cache.names) { | ||
809 | 774 | dm_hash_destroy(_cache.names); | ||
810 | 775 | _cache.names = NULL; | ||
811 | 776 | } | ||
812 | 777 | |||
813 | 778 | _cache.devices = NULL; | ||
814 | 779 | _cache.has_scanned = 0; | ||
815 | 780 | dm_list_init(&_cache.dirs); | ||
816 | 781 | dm_list_init(&_cache.files); | ||
817 | 782 | } | ||
818 | 783 | |||
819 | 784 | int dev_cache_add_dir(const char *path) | ||
820 | 785 | { | ||
821 | 786 | struct dir_list *dl; | ||
822 | 787 | struct stat st; | ||
823 | 788 | |||
824 | 789 | if (stat(path, &st)) { | ||
825 | 790 | log_error("Ignoring %s: %s", path, strerror(errno)); | ||
826 | 791 | /* But don't fail */ | ||
827 | 792 | return 1; | ||
828 | 793 | } | ||
829 | 794 | |||
830 | 795 | if (!S_ISDIR(st.st_mode)) { | ||
831 | 796 | log_error("Ignoring %s: Not a directory", path); | ||
832 | 797 | return 1; | ||
833 | 798 | } | ||
834 | 799 | |||
835 | 800 | if (!(dl = _zalloc(sizeof(*dl) + strlen(path) + 1))) { | ||
836 | 801 | log_error("dir_list allocation failed"); | ||
837 | 802 | return 0; | ||
838 | 803 | } | ||
839 | 804 | |||
840 | 805 | strcpy(dl->dir, path); | ||
841 | 806 | dm_list_add(&_cache.dirs, &dl->list); | ||
842 | 807 | return 1; | ||
843 | 808 | } | ||
844 | 809 | |||
845 | 810 | int dev_cache_add_loopfile(const char *path) | ||
846 | 811 | { | ||
847 | 812 | struct dir_list *dl; | ||
848 | 813 | struct stat st; | ||
849 | 814 | |||
850 | 815 | if (stat(path, &st)) { | ||
851 | 816 | log_error("Ignoring %s: %s", path, strerror(errno)); | ||
852 | 817 | /* But don't fail */ | ||
853 | 818 | return 1; | ||
854 | 819 | } | ||
855 | 820 | |||
856 | 821 | if (!S_ISREG(st.st_mode)) { | ||
857 | 822 | log_error("Ignoring %s: Not a regular file", path); | ||
858 | 823 | return 1; | ||
859 | 824 | } | ||
860 | 825 | |||
861 | 826 | if (!(dl = _zalloc(sizeof(*dl) + strlen(path) + 1))) { | ||
862 | 827 | log_error("dir_list allocation failed for file"); | ||
863 | 828 | return 0; | ||
864 | 829 | } | ||
865 | 830 | |||
866 | 831 | strcpy(dl->dir, path); | ||
867 | 832 | dm_list_add(&_cache.files, &dl->list); | ||
868 | 833 | return 1; | ||
869 | 834 | } | ||
870 | 835 | |||
871 | 836 | /* Check cached device name is still valid before returning it */ | ||
872 | 837 | /* This should be a rare occurrence */ | ||
873 | 838 | /* set quiet if the cache is expected to be out-of-date */ | ||
874 | 839 | /* FIXME Make rest of code pass/cache struct device instead of dev_name */ | ||
875 | 840 | const char *dev_name_confirmed(struct device *dev, int quiet) | ||
876 | 841 | { | ||
877 | 842 | struct stat buf; | ||
878 | 843 | const char *name; | ||
879 | 844 | int r; | ||
880 | 845 | |||
881 | 846 | if ((dev->flags & DEV_REGULAR)) | ||
882 | 847 | return dev_name(dev); | ||
883 | 848 | |||
884 | 849 | while ((r = stat(name = dm_list_item(dev->aliases.n, | ||
885 | 850 | struct str_list)->str, &buf)) || | ||
886 | 851 | (buf.st_rdev != dev->dev)) { | ||
887 | 852 | if (r < 0) { | ||
888 | 853 | if (quiet) | ||
889 | 854 | log_sys_debug("stat", name); | ||
890 | 855 | else | ||
891 | 856 | log_sys_error("stat", name); | ||
892 | 857 | } | ||
893 | 858 | if (quiet) | ||
894 | 859 | log_debug("Path %s no longer valid for device(%d,%d)", | ||
895 | 860 | name, (int) MAJOR(dev->dev), | ||
896 | 861 | (int) MINOR(dev->dev)); | ||
897 | 862 | else | ||
898 | 863 | log_error("Path %s no longer valid for device(%d,%d)", | ||
899 | 864 | name, (int) MAJOR(dev->dev), | ||
900 | 865 | (int) MINOR(dev->dev)); | ||
901 | 866 | |||
902 | 867 | /* Remove the incorrect hash entry */ | ||
903 | 868 | dm_hash_remove(_cache.names, name); | ||
904 | 869 | |||
905 | 870 | /* Leave list alone if there isn't an alternative name */ | ||
906 | 871 | /* so dev_name will always find something to return. */ | ||
907 | 872 | /* Otherwise add the name to the correct device. */ | ||
908 | 873 | if (dm_list_size(&dev->aliases) > 1) { | ||
909 | 874 | dm_list_del(dev->aliases.n); | ||
910 | 875 | if (!r) | ||
911 | 876 | _insert(name, 0, obtain_device_list_from_udev()); | ||
912 | 877 | continue; | ||
913 | 878 | } | ||
914 | 879 | |||
915 | 880 | /* Scanning issues this inappropriately sometimes. */ | ||
916 | 881 | log_debug("Aborting - please provide new pathname for what " | ||
917 | 882 | "used to be %s", name); | ||
918 | 883 | return NULL; | ||
919 | 884 | } | ||
920 | 885 | |||
921 | 886 | return dev_name(dev); | ||
922 | 887 | } | ||
923 | 888 | |||
924 | 889 | struct device *dev_cache_get(const char *name, struct dev_filter *f) | ||
925 | 890 | { | ||
926 | 891 | struct stat buf; | ||
927 | 892 | struct device *d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
928 | 893 | |||
929 | 894 | if (d && (d->flags & DEV_REGULAR)) | ||
930 | 895 | return d; | ||
931 | 896 | |||
932 | 897 | /* If the entry's wrong, remove it */ | ||
933 | 898 | if (d && (stat(name, &buf) || (buf.st_rdev != d->dev))) { | ||
934 | 899 | dm_hash_remove(_cache.names, name); | ||
935 | 900 | d = NULL; | ||
936 | 901 | } | ||
937 | 902 | |||
938 | 903 | if (!d) { | ||
939 | 904 | _insert(name, 0, obtain_device_list_from_udev()); | ||
940 | 905 | d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
941 | 906 | if (!d) { | ||
942 | 907 | _full_scan(0); | ||
943 | 908 | d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
944 | 909 | } | ||
945 | 910 | } | ||
946 | 911 | |||
947 | 912 | return (d && (!f || (d->flags & DEV_REGULAR) || | ||
948 | 913 | f->passes_filter(f, d))) ? d : NULL; | ||
949 | 914 | } | ||
950 | 915 | |||
951 | 916 | static struct device *_dev_cache_seek_devt(dev_t dev) | ||
952 | 917 | { | ||
953 | 918 | struct device *d = NULL; | ||
954 | 919 | struct dm_hash_node *n = dm_hash_get_first(_cache.names); | ||
955 | 920 | while (n) { | ||
956 | 921 | d = dm_hash_get_data(_cache.names, n); | ||
957 | 922 | if (d->dev == dev) | ||
958 | 923 | return d; | ||
959 | 924 | n = dm_hash_get_next(_cache.names, n); | ||
960 | 925 | } | ||
961 | 926 | return NULL; | ||
962 | 927 | } | ||
963 | 928 | |||
964 | 929 | /* | ||
965 | 930 | * TODO This is very inefficient. We probably want a hash table indexed by | ||
966 | 931 | * major:minor for keys to speed up these lookups. | ||
967 | 932 | */ | ||
968 | 933 | struct device *dev_cache_get_by_devt(dev_t dev, struct dev_filter *f) | ||
969 | 934 | { | ||
970 | 935 | struct device *d = _dev_cache_seek_devt(dev); | ||
971 | 936 | |||
972 | 937 | if (d && (d->flags & DEV_REGULAR)) | ||
973 | 938 | return d; | ||
974 | 939 | |||
975 | 940 | if (!d) { | ||
976 | 941 | _full_scan(0); | ||
977 | 942 | d = _dev_cache_seek_devt(dev); | ||
978 | 943 | } | ||
979 | 944 | |||
980 | 945 | return (d && (!f || (d->flags & DEV_REGULAR) || | ||
981 | 946 | f->passes_filter(f, d))) ? d : NULL; | ||
982 | 947 | } | ||
983 | 948 | |||
984 | 949 | struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan) | ||
985 | 950 | { | ||
986 | 951 | struct dev_iter *di = dm_malloc(sizeof(*di)); | ||
987 | 952 | |||
988 | 953 | if (!di) { | ||
989 | 954 | log_error("dev_iter allocation failed"); | ||
990 | 955 | return NULL; | ||
991 | 956 | } | ||
992 | 957 | |||
993 | 958 | if (dev_scan && !trust_cache()) { | ||
994 | 959 | /* Flag gets reset between each command */ | ||
995 | 960 | if (!full_scan_done()) | ||
996 | 961 | persistent_filter_wipe(f); /* Calls _full_scan(1) */ | ||
997 | 962 | } else | ||
998 | 963 | _full_scan(0); | ||
999 | 964 | |||
1000 | 965 | di->current = btree_first(_cache.devices); | ||
1001 | 966 | di->filter = f; | ||
1002 | 967 | di->filter->use_count++; | ||
1003 | 968 | |||
1004 | 969 | return di; | ||
1005 | 970 | } | ||
1006 | 971 | |||
1007 | 972 | void dev_iter_destroy(struct dev_iter *iter) | ||
1008 | 973 | { | ||
1009 | 974 | iter->filter->use_count--; | ||
1010 | 975 | dm_free(iter); | ||
1011 | 976 | } | ||
1012 | 977 | |||
1013 | 978 | static struct device *_iter_next(struct dev_iter *iter) | ||
1014 | 979 | { | ||
1015 | 980 | struct device *d = btree_get_data(iter->current); | ||
1016 | 981 | iter->current = btree_next(iter->current); | ||
1017 | 982 | return d; | ||
1018 | 983 | } | ||
1019 | 984 | |||
1020 | 985 | struct device *dev_iter_get(struct dev_iter *iter) | ||
1021 | 986 | { | ||
1022 | 987 | while (iter->current) { | ||
1023 | 988 | struct device *d = _iter_next(iter); | ||
1024 | 989 | if (!iter->filter || (d->flags & DEV_REGULAR) || | ||
1025 | 990 | iter->filter->passes_filter(iter->filter, d)) | ||
1026 | 991 | return d; | ||
1027 | 992 | } | ||
1028 | 993 | |||
1029 | 994 | return NULL; | ||
1030 | 995 | } | ||
1031 | 996 | |||
1032 | 997 | void dev_reset_error_count(struct cmd_context *cmd) | ||
1033 | 998 | { | ||
1034 | 999 | struct dev_iter iter; | ||
1035 | 1000 | |||
1036 | 1001 | if (!_cache.devices) | ||
1037 | 1002 | return; | ||
1038 | 1003 | |||
1039 | 1004 | iter.current = btree_first(_cache.devices); | ||
1040 | 1005 | while (iter.current) | ||
1041 | 1006 | _iter_next(&iter)->error_count = 0; | ||
1042 | 1007 | } | ||
1043 | 1008 | |||
1044 | 1009 | int dev_fd(struct device *dev) | ||
1045 | 1010 | { | ||
1046 | 1011 | return dev->fd; | ||
1047 | 1012 | } | ||
1048 | 1013 | |||
1049 | 1014 | const char *dev_name(const struct device *dev) | ||
1050 | 1015 | { | ||
1051 | 1016 | return (dev) ? dm_list_item(dev->aliases.n, struct str_list)->str : | ||
1052 | 1017 | "unknown device"; | ||
1053 | 1018 | } | ||
1054 | 0 | 1019 | ||
1055 | === removed file '.pc/avoid-dev-block.patch/lib/device/dev-cache.c' | |||
1056 | --- .pc/avoid-dev-block.patch/lib/device/dev-cache.c 2012-04-14 02:57:53 +0000 | |||
1057 | +++ .pc/avoid-dev-block.patch/lib/device/dev-cache.c 1970-01-01 00:00:00 +0000 | |||
1058 | @@ -1,976 +0,0 @@ | |||
1059 | 1 | /* | ||
1060 | 2 | * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. | ||
1061 | 3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. | ||
1062 | 4 | * | ||
1063 | 5 | * This file is part of LVM2. | ||
1064 | 6 | * | ||
1065 | 7 | * This copyrighted material is made available to anyone wishing to use, | ||
1066 | 8 | * modify, copy, or redistribute it subject to the terms and conditions | ||
1067 | 9 | * of the GNU Lesser General Public License v.2.1. | ||
1068 | 10 | * | ||
1069 | 11 | * You should have received a copy of the GNU Lesser General Public License | ||
1070 | 12 | * along with this program; if not, write to the Free Software Foundation, | ||
1071 | 13 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
1072 | 14 | */ | ||
1073 | 15 | |||
1074 | 16 | #include "lib.h" | ||
1075 | 17 | #include "dev-cache.h" | ||
1076 | 18 | #include "lvm-types.h" | ||
1077 | 19 | #include "btree.h" | ||
1078 | 20 | #include "filter.h" | ||
1079 | 21 | #include "filter-persistent.h" | ||
1080 | 22 | #include "toolcontext.h" | ||
1081 | 23 | |||
1082 | 24 | #include <unistd.h> | ||
1083 | 25 | #include <sys/param.h> | ||
1084 | 26 | #include <dirent.h> | ||
1085 | 27 | |||
1086 | 28 | struct dev_iter { | ||
1087 | 29 | struct btree_iter *current; | ||
1088 | 30 | struct dev_filter *filter; | ||
1089 | 31 | }; | ||
1090 | 32 | |||
1091 | 33 | struct dir_list { | ||
1092 | 34 | struct dm_list list; | ||
1093 | 35 | char dir[0]; | ||
1094 | 36 | }; | ||
1095 | 37 | |||
1096 | 38 | static struct { | ||
1097 | 39 | struct dm_pool *mem; | ||
1098 | 40 | struct dm_hash_table *names; | ||
1099 | 41 | struct btree *devices; | ||
1100 | 42 | struct dm_regex *preferred_names_matcher; | ||
1101 | 43 | const char *dev_dir; | ||
1102 | 44 | |||
1103 | 45 | int has_scanned; | ||
1104 | 46 | struct dm_list dirs; | ||
1105 | 47 | struct dm_list files; | ||
1106 | 48 | |||
1107 | 49 | } _cache; | ||
1108 | 50 | |||
1109 | 51 | #define _alloc(x) dm_pool_zalloc(_cache.mem, (x)) | ||
1110 | 52 | #define _free(x) dm_pool_free(_cache.mem, (x)) | ||
1111 | 53 | #define _strdup(x) dm_pool_strdup(_cache.mem, (x)) | ||
1112 | 54 | |||
1113 | 55 | static int _insert(const char *path, int rec, int check_with_udev_db); | ||
1114 | 56 | |||
1115 | 57 | struct device *dev_create_file(const char *filename, struct device *dev, | ||
1116 | 58 | struct str_list *alias, int use_malloc) | ||
1117 | 59 | { | ||
1118 | 60 | int allocate = !dev; | ||
1119 | 61 | |||
1120 | 62 | if (allocate) { | ||
1121 | 63 | if (use_malloc) { | ||
1122 | 64 | if (!(dev = dm_malloc(sizeof(*dev)))) { | ||
1123 | 65 | log_error("struct device allocation failed"); | ||
1124 | 66 | return NULL; | ||
1125 | 67 | } | ||
1126 | 68 | if (!(alias = dm_malloc(sizeof(*alias)))) { | ||
1127 | 69 | log_error("struct str_list allocation failed"); | ||
1128 | 70 | dm_free(dev); | ||
1129 | 71 | return NULL; | ||
1130 | 72 | } | ||
1131 | 73 | if (!(alias->str = dm_strdup(filename))) { | ||
1132 | 74 | log_error("filename strdup failed"); | ||
1133 | 75 | dm_free(dev); | ||
1134 | 76 | dm_free(alias); | ||
1135 | 77 | return NULL; | ||
1136 | 78 | } | ||
1137 | 79 | dev->flags = DEV_ALLOCED; | ||
1138 | 80 | } else { | ||
1139 | 81 | if (!(dev = _alloc(sizeof(*dev)))) { | ||
1140 | 82 | log_error("struct device allocation failed"); | ||
1141 | 83 | return NULL; | ||
1142 | 84 | } | ||
1143 | 85 | if (!(alias = _alloc(sizeof(*alias)))) { | ||
1144 | 86 | log_error("struct str_list allocation failed"); | ||
1145 | 87 | _free(dev); | ||
1146 | 88 | return NULL; | ||
1147 | 89 | } | ||
1148 | 90 | if (!(alias->str = _strdup(filename))) { | ||
1149 | 91 | log_error("filename strdup failed"); | ||
1150 | 92 | return NULL; | ||
1151 | 93 | } | ||
1152 | 94 | } | ||
1153 | 95 | } else if (!(alias->str = dm_strdup(filename))) { | ||
1154 | 96 | log_error("filename strdup failed"); | ||
1155 | 97 | return NULL; | ||
1156 | 98 | } | ||
1157 | 99 | |||
1158 | 100 | dev->flags |= DEV_REGULAR; | ||
1159 | 101 | dm_list_init(&dev->aliases); | ||
1160 | 102 | dm_list_add(&dev->aliases, &alias->list); | ||
1161 | 103 | dev->end = UINT64_C(0); | ||
1162 | 104 | dev->dev = 0; | ||
1163 | 105 | dev->fd = -1; | ||
1164 | 106 | dev->open_count = 0; | ||
1165 | 107 | dev->error_count = 0; | ||
1166 | 108 | dev->max_error_count = NO_DEV_ERROR_COUNT_LIMIT; | ||
1167 | 109 | dev->block_size = -1; | ||
1168 | 110 | dev->read_ahead = -1; | ||
1169 | 111 | memset(dev->pvid, 0, sizeof(dev->pvid)); | ||
1170 | 112 | dm_list_init(&dev->open_list); | ||
1171 | 113 | |||
1172 | 114 | return dev; | ||
1173 | 115 | } | ||
1174 | 116 | |||
1175 | 117 | static struct device *_dev_create(dev_t d) | ||
1176 | 118 | { | ||
1177 | 119 | struct device *dev; | ||
1178 | 120 | |||
1179 | 121 | if (!(dev = _alloc(sizeof(*dev)))) { | ||
1180 | 122 | log_error("struct device allocation failed"); | ||
1181 | 123 | return NULL; | ||
1182 | 124 | } | ||
1183 | 125 | dev->flags = 0; | ||
1184 | 126 | dm_list_init(&dev->aliases); | ||
1185 | 127 | dev->dev = d; | ||
1186 | 128 | dev->fd = -1; | ||
1187 | 129 | dev->open_count = 0; | ||
1188 | 130 | dev->max_error_count = dev_disable_after_error_count(); | ||
1189 | 131 | dev->block_size = -1; | ||
1190 | 132 | dev->read_ahead = -1; | ||
1191 | 133 | dev->end = UINT64_C(0); | ||
1192 | 134 | memset(dev->pvid, 0, sizeof(dev->pvid)); | ||
1193 | 135 | dm_list_init(&dev->open_list); | ||
1194 | 136 | |||
1195 | 137 | return dev; | ||
1196 | 138 | } | ||
1197 | 139 | |||
1198 | 140 | void dev_set_preferred_name(struct str_list *sl, struct device *dev) | ||
1199 | 141 | { | ||
1200 | 142 | /* | ||
1201 | 143 | * Don't interfere with ordering specified in config file. | ||
1202 | 144 | */ | ||
1203 | 145 | if (_cache.preferred_names_matcher) | ||
1204 | 146 | return; | ||
1205 | 147 | |||
1206 | 148 | log_debug("%s: New preferred name", sl->str); | ||
1207 | 149 | dm_list_del(&sl->list); | ||
1208 | 150 | dm_list_add_h(&dev->aliases, &sl->list); | ||
1209 | 151 | } | ||
1210 | 152 | |||
1211 | 153 | /* | ||
1212 | 154 | * Check whether path0 or path1 contains the subpath. The path that | ||
1213 | 155 | * *does not* contain the subpath wins (return 0 or 1). If both paths | ||
1214 | 156 | * contain the subpath, return -1. If none of them contains the subpath, | ||
1215 | 157 | * return -2. | ||
1216 | 158 | */ | ||
1217 | 159 | static int _builtin_preference(const char *path0, const char *path1, | ||
1218 | 160 | size_t skip_prefix_count, const char *subpath) | ||
1219 | 161 | { | ||
1220 | 162 | size_t subpath_len; | ||
1221 | 163 | int r0, r1; | ||
1222 | 164 | |||
1223 | 165 | subpath_len = strlen(subpath); | ||
1224 | 166 | |||
1225 | 167 | r0 = !strncmp(path0 + skip_prefix_count, subpath, subpath_len); | ||
1226 | 168 | r1 = !strncmp(path1 + skip_prefix_count, subpath, subpath_len); | ||
1227 | 169 | |||
1228 | 170 | if (!r0 && r1) | ||
1229 | 171 | /* path0 does not have the subpath - it wins */ | ||
1230 | 172 | return 0; | ||
1231 | 173 | else if (r0 && !r1) | ||
1232 | 174 | /* path1 does not have the subpath - it wins */ | ||
1233 | 175 | return 1; | ||
1234 | 176 | else if (r0 && r1) | ||
1235 | 177 | /* both of them have the subpath */ | ||
1236 | 178 | return -1; | ||
1237 | 179 | |||
1238 | 180 | /* no path has the subpath */ | ||
1239 | 181 | return -2; | ||
1240 | 182 | } | ||
1241 | 183 | |||
1242 | 184 | static int _apply_builtin_path_preference_rules(const char *path0, const char *path1) | ||
1243 | 185 | { | ||
1244 | 186 | size_t devdir_len; | ||
1245 | 187 | int r; | ||
1246 | 188 | |||
1247 | 189 | devdir_len = strlen(_cache.dev_dir); | ||
1248 | 190 | |||
1249 | 191 | if (!strncmp(path0, _cache.dev_dir, devdir_len) && | ||
1250 | 192 | !strncmp(path1, _cache.dev_dir, devdir_len)) { | ||
1251 | 193 | /* | ||
1252 | 194 | * We're trying to achieve the ordering: | ||
1253 | 195 | * /dev/block/ < /dev/dm-* < /dev/disk/ < /dev/mapper/ < anything else | ||
1254 | 196 | */ | ||
1255 | 197 | |||
1256 | 198 | /* Prefer any other path over /dev/block/ path. */ | ||
1257 | 199 | if ((r = _builtin_preference(path0, path1, devdir_len, "block/")) >= -1) | ||
1258 | 200 | return r; | ||
1259 | 201 | |||
1260 | 202 | /* Prefer any other path over /dev/dm-* path. */ | ||
1261 | 203 | if ((r = _builtin_preference(path0, path1, devdir_len, "dm-")) >= -1) | ||
1262 | 204 | return r; | ||
1263 | 205 | |||
1264 | 206 | /* Prefer any other path over /dev/disk/ path. */ | ||
1265 | 207 | if ((r = _builtin_preference(path0, path1, devdir_len, "disk/")) >= -1) | ||
1266 | 208 | return r; | ||
1267 | 209 | |||
1268 | 210 | /* Prefer any other path over /dev/mapper/ path. */ | ||
1269 | 211 | if ((r = _builtin_preference(path0, path1, 0, dm_dir())) >= -1) | ||
1270 | 212 | return r; | ||
1271 | 213 | } | ||
1272 | 214 | |||
1273 | 215 | return -1; | ||
1274 | 216 | } | ||
1275 | 217 | |||
1276 | 218 | /* Return 1 if we prefer path1 else return 0 */ | ||
1277 | 219 | static int _compare_paths(const char *path0, const char *path1) | ||
1278 | 220 | { | ||
1279 | 221 | int slash0 = 0, slash1 = 0; | ||
1280 | 222 | int m0, m1; | ||
1281 | 223 | const char *p; | ||
1282 | 224 | char p0[PATH_MAX], p1[PATH_MAX]; | ||
1283 | 225 | char *s0, *s1; | ||
1284 | 226 | struct stat stat0, stat1; | ||
1285 | 227 | int r; | ||
1286 | 228 | |||
1287 | 229 | /* | ||
1288 | 230 | * FIXME Better to compare patterns one-at-a-time against all names. | ||
1289 | 231 | */ | ||
1290 | 232 | if (_cache.preferred_names_matcher) { | ||
1291 | 233 | m0 = dm_regex_match(_cache.preferred_names_matcher, path0); | ||
1292 | 234 | m1 = dm_regex_match(_cache.preferred_names_matcher, path1); | ||
1293 | 235 | |||
1294 | 236 | if (m0 != m1) { | ||
1295 | 237 | if (m0 < 0) | ||
1296 | 238 | return 1; | ||
1297 | 239 | if (m1 < 0) | ||
1298 | 240 | return 0; | ||
1299 | 241 | if (m0 < m1) | ||
1300 | 242 | return 1; | ||
1301 | 243 | if (m1 < m0) | ||
1302 | 244 | return 0; | ||
1303 | 245 | } | ||
1304 | 246 | } | ||
1305 | 247 | |||
1306 | 248 | /* Apply built-in preference rules first. */ | ||
1307 | 249 | if ((r = _apply_builtin_path_preference_rules(path0, path1)) >= 0) | ||
1308 | 250 | return r; | ||
1309 | 251 | |||
1310 | 252 | /* Return the path with fewer slashes */ | ||
1311 | 253 | for (p = path0; p++; p = (const char *) strchr(p, '/')) | ||
1312 | 254 | slash0++; | ||
1313 | 255 | |||
1314 | 256 | for (p = path1; p++; p = (const char *) strchr(p, '/')) | ||
1315 | 257 | slash1++; | ||
1316 | 258 | |||
1317 | 259 | if (slash0 < slash1) | ||
1318 | 260 | return 0; | ||
1319 | 261 | if (slash1 < slash0) | ||
1320 | 262 | return 1; | ||
1321 | 263 | |||
1322 | 264 | strncpy(p0, path0, PATH_MAX); | ||
1323 | 265 | strncpy(p1, path1, PATH_MAX); | ||
1324 | 266 | s0 = &p0[0] + 1; | ||
1325 | 267 | s1 = &p1[0] + 1; | ||
1326 | 268 | |||
1327 | 269 | /* We prefer symlinks - they exist for a reason! | ||
1328 | 270 | * So we prefer a shorter path before the first symlink in the name. | ||
1329 | 271 | * FIXME Configuration option to invert this? */ | ||
1330 | 272 | while (s0) { | ||
1331 | 273 | s0 = strchr(s0, '/'); | ||
1332 | 274 | s1 = strchr(s1, '/'); | ||
1333 | 275 | if (s0) { | ||
1334 | 276 | *s0 = '\0'; | ||
1335 | 277 | *s1 = '\0'; | ||
1336 | 278 | } | ||
1337 | 279 | if (lstat(p0, &stat0)) { | ||
1338 | 280 | log_sys_very_verbose("lstat", p0); | ||
1339 | 281 | return 1; | ||
1340 | 282 | } | ||
1341 | 283 | if (lstat(p1, &stat1)) { | ||
1342 | 284 | log_sys_very_verbose("lstat", p1); | ||
1343 | 285 | return 0; | ||
1344 | 286 | } | ||
1345 | 287 | if (S_ISLNK(stat0.st_mode) && !S_ISLNK(stat1.st_mode)) | ||
1346 | 288 | return 0; | ||
1347 | 289 | if (!S_ISLNK(stat0.st_mode) && S_ISLNK(stat1.st_mode)) | ||
1348 | 290 | return 1; | ||
1349 | 291 | if (s0) { | ||
1350 | 292 | *s0++ = '/'; | ||
1351 | 293 | *s1++ = '/'; | ||
1352 | 294 | } | ||
1353 | 295 | } | ||
1354 | 296 | |||
1355 | 297 | /* ASCII comparison */ | ||
1356 | 298 | if (strcmp(path0, path1) < 0) | ||
1357 | 299 | return 0; | ||
1358 | 300 | else | ||
1359 | 301 | return 1; | ||
1360 | 302 | } | ||
1361 | 303 | |||
1362 | 304 | static int _add_alias(struct device *dev, const char *path) | ||
1363 | 305 | { | ||
1364 | 306 | struct str_list *sl = _alloc(sizeof(*sl)); | ||
1365 | 307 | struct str_list *strl; | ||
1366 | 308 | const char *oldpath; | ||
1367 | 309 | int prefer_old = 1; | ||
1368 | 310 | |||
1369 | 311 | if (!sl) | ||
1370 | 312 | return_0; | ||
1371 | 313 | |||
1372 | 314 | /* Is name already there? */ | ||
1373 | 315 | dm_list_iterate_items(strl, &dev->aliases) { | ||
1374 | 316 | if (!strcmp(strl->str, path)) { | ||
1375 | 317 | log_debug("%s: Already in device cache", path); | ||
1376 | 318 | return 1; | ||
1377 | 319 | } | ||
1378 | 320 | } | ||
1379 | 321 | |||
1380 | 322 | sl->str = path; | ||
1381 | 323 | |||
1382 | 324 | if (!dm_list_empty(&dev->aliases)) { | ||
1383 | 325 | oldpath = dm_list_item(dev->aliases.n, struct str_list)->str; | ||
1384 | 326 | prefer_old = _compare_paths(path, oldpath); | ||
1385 | 327 | log_debug("%s: Aliased to %s in device cache%s", | ||
1386 | 328 | path, oldpath, prefer_old ? "" : " (preferred name)"); | ||
1387 | 329 | |||
1388 | 330 | } else | ||
1389 | 331 | log_debug("%s: Added to device cache", path); | ||
1390 | 332 | |||
1391 | 333 | if (prefer_old) | ||
1392 | 334 | dm_list_add(&dev->aliases, &sl->list); | ||
1393 | 335 | else | ||
1394 | 336 | dm_list_add_h(&dev->aliases, &sl->list); | ||
1395 | 337 | |||
1396 | 338 | return 1; | ||
1397 | 339 | } | ||
1398 | 340 | |||
1399 | 341 | /* | ||
1400 | 342 | * Either creates a new dev, or adds an alias to | ||
1401 | 343 | * an existing dev. | ||
1402 | 344 | */ | ||
1403 | 345 | static int _insert_dev(const char *path, dev_t d) | ||
1404 | 346 | { | ||
1405 | 347 | struct device *dev; | ||
1406 | 348 | static dev_t loopfile_count = 0; | ||
1407 | 349 | int loopfile = 0; | ||
1408 | 350 | char *path_copy; | ||
1409 | 351 | |||
1410 | 352 | /* Generate pretend device numbers for loopfiles */ | ||
1411 | 353 | if (!d) { | ||
1412 | 354 | if (dm_hash_lookup(_cache.names, path)) | ||
1413 | 355 | return 1; | ||
1414 | 356 | d = ++loopfile_count; | ||
1415 | 357 | loopfile = 1; | ||
1416 | 358 | } | ||
1417 | 359 | |||
1418 | 360 | /* is this device already registered ? */ | ||
1419 | 361 | if (!(dev = (struct device *) btree_lookup(_cache.devices, | ||
1420 | 362 | (uint32_t) d))) { | ||
1421 | 363 | /* create new device */ | ||
1422 | 364 | if (loopfile) { | ||
1423 | 365 | if (!(dev = dev_create_file(path, NULL, NULL, 0))) | ||
1424 | 366 | return_0; | ||
1425 | 367 | } else if (!(dev = _dev_create(d))) | ||
1426 | 368 | return_0; | ||
1427 | 369 | |||
1428 | 370 | if (!(btree_insert(_cache.devices, (uint32_t) d, dev))) { | ||
1429 | 371 | log_error("Couldn't insert device into binary tree."); | ||
1430 | 372 | _free(dev); | ||
1431 | 373 | return 0; | ||
1432 | 374 | } | ||
1433 | 375 | } | ||
1434 | 376 | |||
1435 | 377 | if (!(path_copy = dm_pool_strdup(_cache.mem, path))) { | ||
1436 | 378 | log_error("Failed to duplicate path string."); | ||
1437 | 379 | return 0; | ||
1438 | 380 | } | ||
1439 | 381 | |||
1440 | 382 | if (!loopfile && !_add_alias(dev, path_copy)) { | ||
1441 | 383 | log_error("Couldn't add alias to dev cache."); | ||
1442 | 384 | return 0; | ||
1443 | 385 | } | ||
1444 | 386 | |||
1445 | 387 | if (!dm_hash_insert(_cache.names, path_copy, dev)) { | ||
1446 | 388 | log_error("Couldn't add name to hash in dev cache."); | ||
1447 | 389 | return 0; | ||
1448 | 390 | } | ||
1449 | 391 | |||
1450 | 392 | return 1; | ||
1451 | 393 | } | ||
1452 | 394 | |||
1453 | 395 | static char *_join(const char *dir, const char *name) | ||
1454 | 396 | { | ||
1455 | 397 | size_t len = strlen(dir) + strlen(name) + 2; | ||
1456 | 398 | char *r = dm_malloc(len); | ||
1457 | 399 | if (r) | ||
1458 | 400 | snprintf(r, len, "%s/%s", dir, name); | ||
1459 | 401 | |||
1460 | 402 | return r; | ||
1461 | 403 | } | ||
1462 | 404 | |||
1463 | 405 | /* | ||
1464 | 406 | * Get rid of extra slashes in the path string. | ||
1465 | 407 | */ | ||
1466 | 408 | static void _collapse_slashes(char *str) | ||
1467 | 409 | { | ||
1468 | 410 | char *ptr; | ||
1469 | 411 | int was_slash = 0; | ||
1470 | 412 | |||
1471 | 413 | for (ptr = str; *ptr; ptr++) { | ||
1472 | 414 | if (*ptr == '/') { | ||
1473 | 415 | if (was_slash) | ||
1474 | 416 | continue; | ||
1475 | 417 | |||
1476 | 418 | was_slash = 1; | ||
1477 | 419 | } else | ||
1478 | 420 | was_slash = 0; | ||
1479 | 421 | *str++ = *ptr; | ||
1480 | 422 | } | ||
1481 | 423 | |||
1482 | 424 | *str = *ptr; | ||
1483 | 425 | } | ||
1484 | 426 | |||
1485 | 427 | static int _insert_dir(const char *dir) | ||
1486 | 428 | { | ||
1487 | 429 | int n, dirent_count, r = 1; | ||
1488 | 430 | struct dirent **dirent; | ||
1489 | 431 | char *path; | ||
1490 | 432 | |||
1491 | 433 | dirent_count = scandir(dir, &dirent, NULL, alphasort); | ||
1492 | 434 | if (dirent_count > 0) { | ||
1493 | 435 | for (n = 0; n < dirent_count; n++) { | ||
1494 | 436 | if (dirent[n]->d_name[0] == '.') { | ||
1495 | 437 | free(dirent[n]); | ||
1496 | 438 | continue; | ||
1497 | 439 | } | ||
1498 | 440 | |||
1499 | 441 | if (!(path = _join(dir, dirent[n]->d_name))) | ||
1500 | 442 | return_0; | ||
1501 | 443 | |||
1502 | 444 | _collapse_slashes(path); | ||
1503 | 445 | r &= _insert(path, 1, 0); | ||
1504 | 446 | dm_free(path); | ||
1505 | 447 | |||
1506 | 448 | free(dirent[n]); | ||
1507 | 449 | } | ||
1508 | 450 | free(dirent); | ||
1509 | 451 | } | ||
1510 | 452 | |||
1511 | 453 | return r; | ||
1512 | 454 | } | ||
1513 | 455 | |||
1514 | 456 | static int _insert_file(const char *path) | ||
1515 | 457 | { | ||
1516 | 458 | struct stat info; | ||
1517 | 459 | |||
1518 | 460 | if (stat(path, &info) < 0) { | ||
1519 | 461 | log_sys_very_verbose("stat", path); | ||
1520 | 462 | return 0; | ||
1521 | 463 | } | ||
1522 | 464 | |||
1523 | 465 | if (!S_ISREG(info.st_mode)) { | ||
1524 | 466 | log_debug("%s: Not a regular file", path); | ||
1525 | 467 | return 0; | ||
1526 | 468 | } | ||
1527 | 469 | |||
1528 | 470 | if (!_insert_dev(path, 0)) | ||
1529 | 471 | return_0; | ||
1530 | 472 | |||
1531 | 473 | return 1; | ||
1532 | 474 | } | ||
1533 | 475 | |||
1534 | 476 | #ifdef UDEV_SYNC_SUPPORT | ||
1535 | 477 | |||
1536 | 478 | static int _device_in_udev_db(const dev_t d) | ||
1537 | 479 | { | ||
1538 | 480 | struct udev *udev; | ||
1539 | 481 | struct udev_device *udev_device; | ||
1540 | 482 | |||
1541 | 483 | if (!(udev = udev_get_library_context())) | ||
1542 | 484 | return_0; | ||
1543 | 485 | |||
1544 | 486 | if ((udev_device = udev_device_new_from_devnum(udev, 'b', d))) { | ||
1545 | 487 | udev_device_unref(udev_device); | ||
1546 | 488 | return 1; | ||
1547 | 489 | } | ||
1548 | 490 | |||
1549 | 491 | return 0; | ||
1550 | 492 | } | ||
1551 | 493 | |||
1552 | 494 | static int _insert_udev_dir(struct udev *udev, const char *dir) | ||
1553 | 495 | { | ||
1554 | 496 | struct udev_enumerate *udev_enum = NULL; | ||
1555 | 497 | struct udev_list_entry *device_entry, *symlink_entry; | ||
1556 | 498 | const char *node_name, *symlink_name; | ||
1557 | 499 | struct udev_device *device; | ||
1558 | 500 | int r = 1; | ||
1559 | 501 | |||
1560 | 502 | if (!(udev_enum = udev_enumerate_new(udev))) | ||
1561 | 503 | goto bad; | ||
1562 | 504 | |||
1563 | 505 | if (udev_enumerate_add_match_subsystem(udev_enum, "block") || | ||
1564 | 506 | udev_enumerate_scan_devices(udev_enum)) | ||
1565 | 507 | goto bad; | ||
1566 | 508 | |||
1567 | 509 | udev_list_entry_foreach(device_entry, udev_enumerate_get_list_entry(udev_enum)) { | ||
1568 | 510 | device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(device_entry)); | ||
1569 | 511 | |||
1570 | 512 | node_name = udev_device_get_devnode(device); | ||
1571 | 513 | r &= _insert(node_name, 0, 0); | ||
1572 | 514 | |||
1573 | 515 | udev_list_entry_foreach(symlink_entry, udev_device_get_devlinks_list_entry(device)) { | ||
1574 | 516 | symlink_name = udev_list_entry_get_name(symlink_entry); | ||
1575 | 517 | r &= _insert(symlink_name, 0, 0); | ||
1576 | 518 | } | ||
1577 | 519 | |||
1578 | 520 | udev_device_unref(device); | ||
1579 | 521 | } | ||
1580 | 522 | |||
1581 | 523 | udev_enumerate_unref(udev_enum); | ||
1582 | 524 | return r; | ||
1583 | 525 | |||
1584 | 526 | bad: | ||
1585 | 527 | log_error("Failed to enumerate udev device list."); | ||
1586 | 528 | udev_enumerate_unref(udev_enum); | ||
1587 | 529 | return 0; | ||
1588 | 530 | } | ||
1589 | 531 | |||
1590 | 532 | static void _insert_dirs(struct dm_list *dirs) | ||
1591 | 533 | { | ||
1592 | 534 | struct dir_list *dl; | ||
1593 | 535 | struct udev *udev; | ||
1594 | 536 | int with_udev; | ||
1595 | 537 | |||
1596 | 538 | with_udev = obtain_device_list_from_udev() && | ||
1597 | 539 | (udev = udev_get_library_context()); | ||
1598 | 540 | |||
1599 | 541 | dm_list_iterate_items(dl, &_cache.dirs) { | ||
1600 | 542 | if (with_udev) { | ||
1601 | 543 | if (!_insert_udev_dir(udev, dl->dir)) | ||
1602 | 544 | log_debug("%s: Failed to insert devices from " | ||
1603 | 545 | "udev-managed directory to device " | ||
1604 | 546 | "cache fully", dl->dir); | ||
1605 | 547 | } | ||
1606 | 548 | else if (!_insert_dir(dl->dir)) | ||
1607 | 549 | log_debug("%s: Failed to insert devices to " | ||
1608 | 550 | "device cache fully", dl->dir); | ||
1609 | 551 | } | ||
1610 | 552 | } | ||
1611 | 553 | |||
1612 | 554 | #else /* UDEV_SYNC_SUPPORT */ | ||
1613 | 555 | |||
1614 | 556 | static int _device_in_udev_db(const dev_t d) | ||
1615 | 557 | { | ||
1616 | 558 | return 0; | ||
1617 | 559 | } | ||
1618 | 560 | |||
1619 | 561 | static void _insert_dirs(struct dm_list *dirs) | ||
1620 | 562 | { | ||
1621 | 563 | struct dir_list *dl; | ||
1622 | 564 | |||
1623 | 565 | dm_list_iterate_items(dl, &_cache.dirs) | ||
1624 | 566 | _insert_dir(dl->dir); | ||
1625 | 567 | } | ||
1626 | 568 | |||
1627 | 569 | #endif /* UDEV_SYNC_SUPPORT */ | ||
1628 | 570 | |||
1629 | 571 | static int _insert(const char *path, int rec, int check_with_udev_db) | ||
1630 | 572 | { | ||
1631 | 573 | struct stat info; | ||
1632 | 574 | int r = 0; | ||
1633 | 575 | |||
1634 | 576 | if (stat(path, &info) < 0) { | ||
1635 | 577 | log_sys_very_verbose("stat", path); | ||
1636 | 578 | return 0; | ||
1637 | 579 | } | ||
1638 | 580 | |||
1639 | 581 | if (check_with_udev_db && !_device_in_udev_db(info.st_rdev)) { | ||
1640 | 582 | log_very_verbose("%s: Not in udev db", path); | ||
1641 | 583 | return 0; | ||
1642 | 584 | } | ||
1643 | 585 | |||
1644 | 586 | if (S_ISDIR(info.st_mode)) { /* add a directory */ | ||
1645 | 587 | /* check it's not a symbolic link */ | ||
1646 | 588 | if (lstat(path, &info) < 0) { | ||
1647 | 589 | log_sys_very_verbose("lstat", path); | ||
1648 | 590 | return 0; | ||
1649 | 591 | } | ||
1650 | 592 | |||
1651 | 593 | if (S_ISLNK(info.st_mode)) { | ||
1652 | 594 | log_debug("%s: Symbolic link to directory", path); | ||
1653 | 595 | return 0; | ||
1654 | 596 | } | ||
1655 | 597 | |||
1656 | 598 | if (rec) | ||
1657 | 599 | r = _insert_dir(path); | ||
1658 | 600 | |||
1659 | 601 | } else { /* add a device */ | ||
1660 | 602 | if (!S_ISBLK(info.st_mode)) { | ||
1661 | 603 | log_debug("%s: Not a block device", path); | ||
1662 | 604 | return 0; | ||
1663 | 605 | } | ||
1664 | 606 | |||
1665 | 607 | if (!_insert_dev(path, info.st_rdev)) | ||
1666 | 608 | return_0; | ||
1667 | 609 | |||
1668 | 610 | r = 1; | ||
1669 | 611 | } | ||
1670 | 612 | |||
1671 | 613 | return r; | ||
1672 | 614 | } | ||
1673 | 615 | |||
1674 | 616 | static void _full_scan(int dev_scan) | ||
1675 | 617 | { | ||
1676 | 618 | struct dir_list *dl; | ||
1677 | 619 | |||
1678 | 620 | if (_cache.has_scanned && !dev_scan) | ||
1679 | 621 | return; | ||
1680 | 622 | |||
1681 | 623 | _insert_dirs(&_cache.dirs); | ||
1682 | 624 | |||
1683 | 625 | dm_list_iterate_items(dl, &_cache.files) | ||
1684 | 626 | _insert_file(dl->dir); | ||
1685 | 627 | |||
1686 | 628 | _cache.has_scanned = 1; | ||
1687 | 629 | init_full_scan_done(1); | ||
1688 | 630 | } | ||
1689 | 631 | |||
1690 | 632 | int dev_cache_has_scanned(void) | ||
1691 | 633 | { | ||
1692 | 634 | return _cache.has_scanned; | ||
1693 | 635 | } | ||
1694 | 636 | |||
1695 | 637 | void dev_cache_scan(int do_scan) | ||
1696 | 638 | { | ||
1697 | 639 | if (!do_scan) | ||
1698 | 640 | _cache.has_scanned = 1; | ||
1699 | 641 | else | ||
1700 | 642 | _full_scan(1); | ||
1701 | 643 | } | ||
1702 | 644 | |||
1703 | 645 | static int _init_preferred_names(struct cmd_context *cmd) | ||
1704 | 646 | { | ||
1705 | 647 | const struct config_node *cn; | ||
1706 | 648 | const struct config_value *v; | ||
1707 | 649 | struct dm_pool *scratch = NULL; | ||
1708 | 650 | const char **regex; | ||
1709 | 651 | unsigned count = 0; | ||
1710 | 652 | int i, r = 0; | ||
1711 | 653 | |||
1712 | 654 | _cache.preferred_names_matcher = NULL; | ||
1713 | 655 | |||
1714 | 656 | if (!(cn = find_config_tree_node(cmd, "devices/preferred_names")) || | ||
1715 | 657 | cn->v->type == CFG_EMPTY_ARRAY) { | ||
1716 | 658 | log_very_verbose("devices/preferred_names not found in config file: " | ||
1717 | 659 | "using built-in preferences"); | ||
1718 | 660 | return 1; | ||
1719 | 661 | } | ||
1720 | 662 | |||
1721 | 663 | for (v = cn->v; v; v = v->next) { | ||
1722 | 664 | if (v->type != CFG_STRING) { | ||
1723 | 665 | log_error("preferred_names patterns must be enclosed in quotes"); | ||
1724 | 666 | return 0; | ||
1725 | 667 | } | ||
1726 | 668 | |||
1727 | 669 | count++; | ||
1728 | 670 | } | ||
1729 | 671 | |||
1730 | 672 | if (!(scratch = dm_pool_create("preferred device name matcher", 1024))) | ||
1731 | 673 | return_0; | ||
1732 | 674 | |||
1733 | 675 | if (!(regex = dm_pool_alloc(scratch, sizeof(*regex) * count))) { | ||
1734 | 676 | log_error("Failed to allocate preferred device name " | ||
1735 | 677 | "pattern list."); | ||
1736 | 678 | goto out; | ||
1737 | 679 | } | ||
1738 | 680 | |||
1739 | 681 | for (v = cn->v, i = count - 1; v; v = v->next, i--) { | ||
1740 | 682 | if (!(regex[i] = dm_pool_strdup(scratch, v->v.str))) { | ||
1741 | 683 | log_error("Failed to allocate a preferred device name " | ||
1742 | 684 | "pattern."); | ||
1743 | 685 | goto out; | ||
1744 | 686 | } | ||
1745 | 687 | } | ||
1746 | 688 | |||
1747 | 689 | if (!(_cache.preferred_names_matcher = | ||
1748 | 690 | dm_regex_create(_cache.mem, regex, count))) { | ||
1749 | 691 | log_error("Preferred device name pattern matcher creation failed."); | ||
1750 | 692 | goto out; | ||
1751 | 693 | } | ||
1752 | 694 | |||
1753 | 695 | r = 1; | ||
1754 | 696 | |||
1755 | 697 | out: | ||
1756 | 698 | dm_pool_destroy(scratch); | ||
1757 | 699 | |||
1758 | 700 | return r; | ||
1759 | 701 | } | ||
1760 | 702 | |||
1761 | 703 | int dev_cache_init(struct cmd_context *cmd) | ||
1762 | 704 | { | ||
1763 | 705 | _cache.names = NULL; | ||
1764 | 706 | _cache.has_scanned = 0; | ||
1765 | 707 | |||
1766 | 708 | if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024))) | ||
1767 | 709 | return_0; | ||
1768 | 710 | |||
1769 | 711 | if (!(_cache.names = dm_hash_create(128))) { | ||
1770 | 712 | dm_pool_destroy(_cache.mem); | ||
1771 | 713 | _cache.mem = 0; | ||
1772 | 714 | return_0; | ||
1773 | 715 | } | ||
1774 | 716 | |||
1775 | 717 | if (!(_cache.devices = btree_create(_cache.mem))) { | ||
1776 | 718 | log_error("Couldn't create binary tree for dev-cache."); | ||
1777 | 719 | goto bad; | ||
1778 | 720 | } | ||
1779 | 721 | |||
1780 | 722 | if (!(_cache.dev_dir = _strdup(cmd->dev_dir))) { | ||
1781 | 723 | log_error("strdup dev_dir failed."); | ||
1782 | 724 | goto bad; | ||
1783 | 725 | } | ||
1784 | 726 | |||
1785 | 727 | dm_list_init(&_cache.dirs); | ||
1786 | 728 | dm_list_init(&_cache.files); | ||
1787 | 729 | |||
1788 | 730 | if (!_init_preferred_names(cmd)) | ||
1789 | 731 | goto_bad; | ||
1790 | 732 | |||
1791 | 733 | return 1; | ||
1792 | 734 | |||
1793 | 735 | bad: | ||
1794 | 736 | dev_cache_exit(); | ||
1795 | 737 | return 0; | ||
1796 | 738 | } | ||
1797 | 739 | |||
1798 | 740 | static void _check_closed(struct device *dev) | ||
1799 | 741 | { | ||
1800 | 742 | if (dev->fd >= 0) | ||
1801 | 743 | log_error("Device '%s' has been left open.", dev_name(dev)); | ||
1802 | 744 | } | ||
1803 | 745 | |||
1804 | 746 | static void _check_for_open_devices(void) | ||
1805 | 747 | { | ||
1806 | 748 | dm_hash_iter(_cache.names, (dm_hash_iterate_fn) _check_closed); | ||
1807 | 749 | } | ||
1808 | 750 | |||
1809 | 751 | void dev_cache_exit(void) | ||
1810 | 752 | { | ||
1811 | 753 | if (_cache.names) | ||
1812 | 754 | _check_for_open_devices(); | ||
1813 | 755 | |||
1814 | 756 | if (_cache.preferred_names_matcher) | ||
1815 | 757 | _cache.preferred_names_matcher = NULL; | ||
1816 | 758 | |||
1817 | 759 | if (_cache.mem) { | ||
1818 | 760 | dm_pool_destroy(_cache.mem); | ||
1819 | 761 | _cache.mem = NULL; | ||
1820 | 762 | } | ||
1821 | 763 | |||
1822 | 764 | if (_cache.names) { | ||
1823 | 765 | dm_hash_destroy(_cache.names); | ||
1824 | 766 | _cache.names = NULL; | ||
1825 | 767 | } | ||
1826 | 768 | |||
1827 | 769 | _cache.devices = NULL; | ||
1828 | 770 | _cache.has_scanned = 0; | ||
1829 | 771 | dm_list_init(&_cache.dirs); | ||
1830 | 772 | dm_list_init(&_cache.files); | ||
1831 | 773 | } | ||
1832 | 774 | |||
1833 | 775 | int dev_cache_add_dir(const char *path) | ||
1834 | 776 | { | ||
1835 | 777 | struct dir_list *dl; | ||
1836 | 778 | struct stat st; | ||
1837 | 779 | |||
1838 | 780 | if (stat(path, &st)) { | ||
1839 | 781 | log_error("Ignoring %s: %s", path, strerror(errno)); | ||
1840 | 782 | /* But don't fail */ | ||
1841 | 783 | return 1; | ||
1842 | 784 | } | ||
1843 | 785 | |||
1844 | 786 | if (!S_ISDIR(st.st_mode)) { | ||
1845 | 787 | log_error("Ignoring %s: Not a directory", path); | ||
1846 | 788 | return 1; | ||
1847 | 789 | } | ||
1848 | 790 | |||
1849 | 791 | if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1))) { | ||
1850 | 792 | log_error("dir_list allocation failed"); | ||
1851 | 793 | return 0; | ||
1852 | 794 | } | ||
1853 | 795 | |||
1854 | 796 | strcpy(dl->dir, path); | ||
1855 | 797 | dm_list_add(&_cache.dirs, &dl->list); | ||
1856 | 798 | return 1; | ||
1857 | 799 | } | ||
1858 | 800 | |||
1859 | 801 | int dev_cache_add_loopfile(const char *path) | ||
1860 | 802 | { | ||
1861 | 803 | struct dir_list *dl; | ||
1862 | 804 | struct stat st; | ||
1863 | 805 | |||
1864 | 806 | if (stat(path, &st)) { | ||
1865 | 807 | log_error("Ignoring %s: %s", path, strerror(errno)); | ||
1866 | 808 | /* But don't fail */ | ||
1867 | 809 | return 1; | ||
1868 | 810 | } | ||
1869 | 811 | |||
1870 | 812 | if (!S_ISREG(st.st_mode)) { | ||
1871 | 813 | log_error("Ignoring %s: Not a regular file", path); | ||
1872 | 814 | return 1; | ||
1873 | 815 | } | ||
1874 | 816 | |||
1875 | 817 | if (!(dl = _alloc(sizeof(*dl) + strlen(path) + 1))) { | ||
1876 | 818 | log_error("dir_list allocation failed for file"); | ||
1877 | 819 | return 0; | ||
1878 | 820 | } | ||
1879 | 821 | |||
1880 | 822 | strcpy(dl->dir, path); | ||
1881 | 823 | dm_list_add(&_cache.files, &dl->list); | ||
1882 | 824 | return 1; | ||
1883 | 825 | } | ||
1884 | 826 | |||
1885 | 827 | /* Check cached device name is still valid before returning it */ | ||
1886 | 828 | /* This should be a rare occurrence */ | ||
1887 | 829 | /* set quiet if the cache is expected to be out-of-date */ | ||
1888 | 830 | /* FIXME Make rest of code pass/cache struct device instead of dev_name */ | ||
1889 | 831 | const char *dev_name_confirmed(struct device *dev, int quiet) | ||
1890 | 832 | { | ||
1891 | 833 | struct stat buf; | ||
1892 | 834 | const char *name; | ||
1893 | 835 | int r; | ||
1894 | 836 | |||
1895 | 837 | if ((dev->flags & DEV_REGULAR)) | ||
1896 | 838 | return dev_name(dev); | ||
1897 | 839 | |||
1898 | 840 | while ((r = stat(name = dm_list_item(dev->aliases.n, | ||
1899 | 841 | struct str_list)->str, &buf)) || | ||
1900 | 842 | (buf.st_rdev != dev->dev)) { | ||
1901 | 843 | if (r < 0) { | ||
1902 | 844 | if (quiet) | ||
1903 | 845 | log_sys_debug("stat", name); | ||
1904 | 846 | else | ||
1905 | 847 | log_sys_error("stat", name); | ||
1906 | 848 | } | ||
1907 | 849 | if (quiet) | ||
1908 | 850 | log_debug("Path %s no longer valid for device(%d,%d)", | ||
1909 | 851 | name, (int) MAJOR(dev->dev), | ||
1910 | 852 | (int) MINOR(dev->dev)); | ||
1911 | 853 | else | ||
1912 | 854 | log_error("Path %s no longer valid for device(%d,%d)", | ||
1913 | 855 | name, (int) MAJOR(dev->dev), | ||
1914 | 856 | (int) MINOR(dev->dev)); | ||
1915 | 857 | |||
1916 | 858 | /* Remove the incorrect hash entry */ | ||
1917 | 859 | dm_hash_remove(_cache.names, name); | ||
1918 | 860 | |||
1919 | 861 | /* Leave list alone if there isn't an alternative name */ | ||
1920 | 862 | /* so dev_name will always find something to return. */ | ||
1921 | 863 | /* Otherwise add the name to the correct device. */ | ||
1922 | 864 | if (dm_list_size(&dev->aliases) > 1) { | ||
1923 | 865 | dm_list_del(dev->aliases.n); | ||
1924 | 866 | if (!r) | ||
1925 | 867 | _insert(name, 0, obtain_device_list_from_udev()); | ||
1926 | 868 | continue; | ||
1927 | 869 | } | ||
1928 | 870 | |||
1929 | 871 | /* Scanning issues this inappropriately sometimes. */ | ||
1930 | 872 | log_debug("Aborting - please provide new pathname for what " | ||
1931 | 873 | "used to be %s", name); | ||
1932 | 874 | return NULL; | ||
1933 | 875 | } | ||
1934 | 876 | |||
1935 | 877 | return dev_name(dev); | ||
1936 | 878 | } | ||
1937 | 879 | |||
1938 | 880 | struct device *dev_cache_get(const char *name, struct dev_filter *f) | ||
1939 | 881 | { | ||
1940 | 882 | struct stat buf; | ||
1941 | 883 | struct device *d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
1942 | 884 | |||
1943 | 885 | if (d && (d->flags & DEV_REGULAR)) | ||
1944 | 886 | return d; | ||
1945 | 887 | |||
1946 | 888 | /* If the entry's wrong, remove it */ | ||
1947 | 889 | if (d && (stat(name, &buf) || (buf.st_rdev != d->dev))) { | ||
1948 | 890 | dm_hash_remove(_cache.names, name); | ||
1949 | 891 | d = NULL; | ||
1950 | 892 | } | ||
1951 | 893 | |||
1952 | 894 | if (!d) { | ||
1953 | 895 | _insert(name, 0, obtain_device_list_from_udev()); | ||
1954 | 896 | d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
1955 | 897 | if (!d) { | ||
1956 | 898 | _full_scan(0); | ||
1957 | 899 | d = (struct device *) dm_hash_lookup(_cache.names, name); | ||
1958 | 900 | } | ||
1959 | 901 | } | ||
1960 | 902 | |||
1961 | 903 | return (d && (!f || (d->flags & DEV_REGULAR) || | ||
1962 | 904 | f->passes_filter(f, d))) ? d : NULL; | ||
1963 | 905 | } | ||
1964 | 906 | |||
1965 | 907 | struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan) | ||
1966 | 908 | { | ||
1967 | 909 | struct dev_iter *di = dm_malloc(sizeof(*di)); | ||
1968 | 910 | |||
1969 | 911 | if (!di) { | ||
1970 | 912 | log_error("dev_iter allocation failed"); | ||
1971 | 913 | return NULL; | ||
1972 | 914 | } | ||
1973 | 915 | |||
1974 | 916 | if (dev_scan && !trust_cache()) { | ||
1975 | 917 | /* Flag gets reset between each command */ | ||
1976 | 918 | if (!full_scan_done()) | ||
1977 | 919 | persistent_filter_wipe(f); /* Calls _full_scan(1) */ | ||
1978 | 920 | } else | ||
1979 | 921 | _full_scan(0); | ||
1980 | 922 | |||
1981 | 923 | di->current = btree_first(_cache.devices); | ||
1982 | 924 | di->filter = f; | ||
1983 | 925 | di->filter->use_count++; | ||
1984 | 926 | |||
1985 | 927 | return di; | ||
1986 | 928 | } | ||
1987 | 929 | |||
1988 | 930 | void dev_iter_destroy(struct dev_iter *iter) | ||
1989 | 931 | { | ||
1990 | 932 | iter->filter->use_count--; | ||
1991 | 933 | dm_free(iter); | ||
1992 | 934 | } | ||
1993 | 935 | |||
1994 | 936 | static struct device *_iter_next(struct dev_iter *iter) | ||
1995 | 937 | { | ||
1996 | 938 | struct device *d = btree_get_data(iter->current); | ||
1997 | 939 | iter->current = btree_next(iter->current); | ||
1998 | 940 | return d; | ||
1999 | 941 | } | ||
2000 | 942 | |||
2001 | 943 | struct device *dev_iter_get(struct dev_iter *iter) | ||
2002 | 944 | { | ||
2003 | 945 | while (iter->current) { | ||
2004 | 946 | struct device *d = _iter_next(iter); | ||
2005 | 947 | if (!iter->filter || (d->flags & DEV_REGULAR) || | ||
2006 | 948 | iter->filter->passes_filter(iter->filter, d)) | ||
2007 | 949 | return d; | ||
2008 | 950 | } | ||
2009 | 951 | |||
2010 | 952 | return NULL; | ||
2011 | 953 | } | ||
2012 | 954 | |||
2013 | 955 | void dev_reset_error_count(struct cmd_context *cmd) | ||
2014 | 956 | { | ||
2015 | 957 | struct dev_iter iter; | ||
2016 | 958 | |||
2017 | 959 | if (!_cache.devices) | ||
2018 | 960 | return; | ||
2019 | 961 | |||
2020 | 962 | iter.current = btree_first(_cache.devices); | ||
2021 | 963 | while (iter.current) | ||
2022 | 964 | _iter_next(&iter)->error_count = 0; | ||
2023 | 965 | } | ||
2024 | 966 | |||
2025 | 967 | int dev_fd(struct device *dev) | ||
2026 | 968 | { | ||
2027 | 969 | return dev->fd; | ||
2028 | 970 | } | ||
2029 | 971 | |||
2030 | 972 | const char *dev_name(const struct device *dev) | ||
2031 | 973 | { | ||
2032 | 974 | return (dev) ? dm_list_item(dev->aliases.n, struct str_list)->str : | ||
2033 | 975 | "unknown device"; | ||
2034 | 976 | } | ||
2035 | 977 | 0 | ||
2036 | === added directory '.pc/dirs.patch' | |||
2037 | === removed directory '.pc/dirs.patch' | |||
2038 | === added directory '.pc/dirs.patch/daemons' | |||
2039 | === added directory '.pc/dirs.patch/daemons/dmeventd' | |||
2040 | === added file '.pc/dirs.patch/daemons/dmeventd/Makefile.in' | |||
2041 | --- .pc/dirs.patch/daemons/dmeventd/Makefile.in 1970-01-01 00:00:00 +0000 | |||
2042 | +++ .pc/dirs.patch/daemons/dmeventd/Makefile.in 2012-08-21 10:18:22 +0000 | |||
2043 | @@ -0,0 +1,108 @@ | |||
2044 | 1 | # | ||
2045 | 2 | # Copyright (C) 2005-2011 Red Hat, Inc. All rights reserved. | ||
2046 | 3 | # | ||
2047 | 4 | # This file is part of the device-mapper userspace tools. | ||
2048 | 5 | # | ||
2049 | 6 | # This copyrighted material is made available to anyone wishing to use, | ||
2050 | 7 | # modify, copy, or redistribute it subject to the terms and conditions | ||
2051 | 8 | # of the GNU Lesser General Public License v.2.1. | ||
2052 | 9 | # | ||
2053 | 10 | # You should have received a copy of the GNU Lesser General Public License | ||
2054 | 11 | # along with this program; if not, write to the Free Software Foundation, | ||
2055 | 12 | # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
2056 | 13 | |||
2057 | 14 | srcdir = @srcdir@ | ||
2058 | 15 | top_srcdir = @top_srcdir@ | ||
2059 | 16 | top_builddir = @top_builddir@ | ||
2060 | 17 | |||
2061 | 18 | SOURCES = libdevmapper-event.c | ||
2062 | 19 | SOURCES2 = dmeventd.c | ||
2063 | 20 | |||
2064 | 21 | TARGETS = dmeventd | ||
2065 | 22 | |||
2066 | 23 | .PHONY: install_lib_dynamic install_lib_static install_include \ | ||
2067 | 24 | install_pkgconfig install_dmeventd_dynamic install_dmeventd_static \ | ||
2068 | 25 | install_lib install_dmeventd | ||
2069 | 26 | |||
2070 | 27 | INSTALL_DMEVENTD_TARGETS = install_dmeventd_dynamic | ||
2071 | 28 | INSTALL_LIB_TARGETS = install_lib_dynamic | ||
2072 | 29 | |||
2073 | 30 | LIB_NAME = libdevmapper-event | ||
2074 | 31 | ifeq ("@STATIC_LINK@", "yes") | ||
2075 | 32 | LIB_STATIC = $(LIB_NAME).a | ||
2076 | 33 | TARGETS += $(LIB_STATIC) dmeventd.static | ||
2077 | 34 | INSTALL_DMEVENTD_TARGETS += install_dmeventd_static | ||
2078 | 35 | INSTALL_LIB_TARGETS += install_lib_static | ||
2079 | 36 | endif | ||
2080 | 37 | |||
2081 | 38 | LIB_VERSION = $(LIB_VERSION_DM) | ||
2082 | 39 | LIB_SHARED = $(LIB_NAME).$(LIB_SUFFIX) | ||
2083 | 40 | |||
2084 | 41 | CLEAN_TARGETS = dmeventd.static $(LIB_NAME).a | ||
2085 | 42 | |||
2086 | 43 | ifneq ($(MAKECMDGOALS),device-mapper) | ||
2087 | 44 | SUBDIRS+=plugins | ||
2088 | 45 | endif | ||
2089 | 46 | |||
2090 | 47 | CFLOW_LIST = $(SOURCES) | ||
2091 | 48 | CFLOW_LIST_TARGET = $(LIB_NAME).cflow | ||
2092 | 49 | CFLOW_TARGET = dmeventd | ||
2093 | 50 | |||
2094 | 51 | EXPORTED_HEADER = $(srcdir)/libdevmapper-event.h | ||
2095 | 52 | EXPORTED_FN_PREFIX = dm_event | ||
2096 | 53 | |||
2097 | 54 | include $(top_builddir)/make.tmpl | ||
2098 | 55 | |||
2099 | 56 | all: device-mapper | ||
2100 | 57 | device-mapper: $(TARGETS) | ||
2101 | 58 | |||
2102 | 59 | LIBS += -ldevmapper | ||
2103 | 60 | LVMLIBS += -ldevmapper-event $(PTHREAD_LIBS) | ||
2104 | 61 | |||
2105 | 62 | dmeventd: $(LIB_SHARED) dmeventd.o | ||
2106 | 63 | $(CC) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) -L. -o $@ dmeventd.o \ | ||
2107 | 64 | $(DL_LIBS) $(LVMLIBS) $(LIBS) -rdynamic | ||
2108 | 65 | |||
2109 | 66 | dmeventd.static: $(LIB_STATIC) dmeventd.o $(interfacebuilddir)/libdevmapper.a | ||
2110 | 67 | $(CC) $(CFLAGS) $(LDFLAGS) $(ELDFLAGS) -static -L. -L$(interfacebuilddir) -o $@ \ | ||
2111 | 68 | dmeventd.o $(DL_LIBS) $(LVMLIBS) $(LIBS) $(STATIC_LIBS) | ||
2112 | 69 | |||
2113 | 70 | ifeq ("@PKGCONFIG@", "yes") | ||
2114 | 71 | INSTALL_LIB_TARGETS += install_pkgconfig | ||
2115 | 72 | endif | ||
2116 | 73 | |||
2117 | 74 | ifneq ("$(CFLOW_CMD)", "") | ||
2118 | 75 | CFLOW_SOURCES = $(addprefix $(srcdir)/, $(SOURCES)) | ||
2119 | 76 | -include $(top_builddir)/libdm/libdevmapper.cflow | ||
2120 | 77 | -include $(top_builddir)/lib/liblvm-internal.cflow | ||
2121 | 78 | -include $(top_builddir)/lib/liblvm2cmd.cflow | ||
2122 | 79 | -include $(top_builddir)/daemons/dmeventd/$(LIB_NAME).cflow | ||
2123 | 80 | -include $(top_builddir)/daemons/dmeventd/plugins/mirror/$(LIB_NAME)-lvm2mirror.cflow | ||
2124 | 81 | endif | ||
2125 | 82 | |||
2126 | 83 | install_include: $(srcdir)/libdevmapper-event.h | ||
2127 | 84 | $(INSTALL_DATA) -D $< $(includedir)/$(<F) | ||
2128 | 85 | |||
2129 | 86 | install_pkgconfig: libdevmapper-event.pc | ||
2130 | 87 | $(INSTALL_DATA) -D $< $(pkgconfigdir)/devmapper-event.pc | ||
2131 | 88 | |||
2132 | 89 | install_lib_dynamic: install_lib_shared | ||
2133 | 90 | |||
2134 | 91 | install_lib_static: $(LIB_STATIC) | ||
2135 | 92 | $(INSTALL_DATA) -D $< $(usrlibdir)/$(<F) | ||
2136 | 93 | |||
2137 | 94 | install_lib: $(INSTALL_LIB_TARGETS) | ||
2138 | 95 | |||
2139 | 96 | install_dmeventd_dynamic: dmeventd | ||
2140 | 97 | $(INSTALL_PROGRAM) -D $< $(sbindir)/$(<F) | ||
2141 | 98 | |||
2142 | 99 | install_dmeventd_static: dmeventd.static | ||
2143 | 100 | $(INSTALL_PROGRAM) -D $< $(staticdir)/$(<F) | ||
2144 | 101 | |||
2145 | 102 | install_dmeventd: $(INSTALL_DMEVENTD_TARGETS) | ||
2146 | 103 | |||
2147 | 104 | install: install_include install_lib install_dmeventd | ||
2148 | 105 | |||
2149 | 106 | install_device-mapper: install_include install_lib install_dmeventd | ||
2150 | 107 | |||
2151 | 108 | DISTCLEAN_TARGETS += libdevmapper-event.pc | ||
2152 | 0 | 109 | ||
2153 | === added file '.pc/dirs.patch/daemons/dmeventd/dmeventd.c' | |||
2154 | --- .pc/dirs.patch/daemons/dmeventd/dmeventd.c 1970-01-01 00:00:00 +0000 | |||
2155 | +++ .pc/dirs.patch/daemons/dmeventd/dmeventd.c 2012-08-21 10:18:22 +0000 | |||
2156 | @@ -0,0 +1,2009 @@ | |||
2157 | 1 | /* | ||
2158 | 2 | * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved. | ||
2159 | 3 | * | ||
2160 | 4 | * This file is part of the device-mapper userspace tools. | ||
2161 | 5 | * | ||
2162 | 6 | * This copyrighted material is made available to anyone wishing to use, | ||
2163 | 7 | * modify, copy, or redistribute it subject to the terms and conditions | ||
2164 | 8 | * of the GNU Lesser General Public License v.2.1. | ||
2165 | 9 | * | ||
2166 | 10 | * You should have received a copy of the GNU Lesser General Public License | ||
2167 | 11 | * along with this program; if not, write to the Free Software Foundation, | ||
2168 | 12 | * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
2169 | 13 | */ | ||
2170 | 14 | |||
2171 | 15 | /* | ||
2172 | 16 | * dmeventd - dm event daemon to monitor active mapped devices | ||
2173 | 17 | */ | ||
2174 | 18 | |||
2175 | 19 | #define _GNU_SOURCE | ||
2176 | 20 | #define _FILE_OFFSET_BITS 64 | ||
2177 | 21 | |||
2178 | 22 | #include "configure.h" | ||
2179 | 23 | #include "libdevmapper.h" | ||
2180 | 24 | #include "libdevmapper-event.h" | ||
2181 | 25 | #include "dmeventd.h" | ||
2182 | 26 | //#include "libmultilog.h" | ||
2183 | 27 | #include "dm-logging.h" | ||
2184 | 28 | |||
2185 | 29 | #include <dlfcn.h> | ||
2186 | 30 | #include <errno.h> | ||
2187 | 31 | #include <pthread.h> | ||
2188 | 32 | #include <sys/file.h> | ||
2189 | 33 | #include <sys/stat.h> | ||
2190 | 34 | #include <sys/wait.h> | ||
2191 | 35 | #include <sys/time.h> | ||
2192 | 36 | #include <sys/resource.h> | ||
2193 | 37 | #include <unistd.h> | ||
2194 | 38 | #include <signal.h> | ||
2195 | 39 | #include <arpa/inet.h> /* for htonl, ntohl */ | ||
2196 | 40 | |||
2197 | 41 | #ifdef linux | ||
2198 | 42 | # include <malloc.h> | ||
2199 | 43 | |||
2200 | 44 | /* | ||
2201 | 45 | * Kernel version 2.6.36 and higher has | ||
2202 | 46 | * new OOM killer adjustment interface. | ||
2203 | 47 | */ | ||
2204 | 48 | # define OOM_ADJ_FILE_OLD "/proc/self/oom_adj" | ||
2205 | 49 | # define OOM_ADJ_FILE "/proc/self/oom_score_adj" | ||
2206 | 50 | |||
2207 | 51 | /* From linux/oom.h */ | ||
2208 | 52 | /* Old interface */ | ||
2209 | 53 | # define OOM_DISABLE (-17) | ||
2210 | 54 | # define OOM_ADJUST_MIN (-16) | ||
2211 | 55 | /* New interface */ | ||
2212 | 56 | # define OOM_SCORE_ADJ_MIN (-1000) | ||
2213 | 57 | |||
2214 | 58 | /* Systemd on-demand activation support */ | ||
2215 | 59 | # define SD_LISTEN_PID_ENV_VAR_NAME "LISTEN_PID" | ||
2216 | 60 | # define SD_LISTEN_FDS_ENV_VAR_NAME "LISTEN_FDS" | ||
2217 | 61 | # define SD_LISTEN_FDS_START 3 | ||
2218 | 62 | # define SD_FD_FIFO_SERVER SD_LISTEN_FDS_START | ||
2219 | 63 | # define SD_FD_FIFO_CLIENT (SD_LISTEN_FDS_START + 1) | ||
2220 | 64 | |||
2221 | 65 | #endif | ||
2222 | 66 | |||
2223 | 67 | /* FIXME We use syslog for now, because multilog is not yet implemented */ | ||
2224 | 68 | #include <syslog.h> | ||
2225 | 69 | |||
2226 | 70 | static volatile sig_atomic_t _exit_now = 0; /* set to '1' when signal is given to exit */ | ||
2227 | 71 | static volatile sig_atomic_t _thread_registries_empty = 1; /* registries are empty initially */ | ||
2228 | 72 | |||
2229 | 73 | /* List (un)link macros. */ | ||
2230 | 74 | #define LINK(x, head) dm_list_add(head, &(x)->list) | ||
2231 | 75 | #define LINK_DSO(dso) LINK(dso, &_dso_registry) | ||
2232 | 76 | #define LINK_THREAD(thread) LINK(thread, &_thread_registry) | ||
2233 | 77 | |||
2234 | 78 | #define UNLINK(x) dm_list_del(&(x)->list) | ||
2235 | 79 | #define UNLINK_DSO(x) UNLINK(x) | ||
2236 | 80 | #define UNLINK_THREAD(x) UNLINK(x) | ||
2237 | 81 | |||
2238 | 82 | #define DAEMON_NAME "dmeventd" | ||
2239 | 83 | |||
2240 | 84 | /* | ||
2241 | 85 | Global mutex for thread list access. Has to be held when: | ||
2242 | 86 | - iterating thread list | ||
2243 | 87 | - adding or removing elements from thread list | ||
2244 | 88 | - changing or reading thread_status's fields: | ||
2245 | 89 | processing, status, events | ||
2246 | 90 | Use _lock_mutex() and _unlock_mutex() to hold/release it | ||
2247 | 91 | */ | ||
2248 | 92 | static pthread_mutex_t _global_mutex; | ||
2249 | 93 | |||
2250 | 94 | /* | ||
2251 | 95 | There are three states a thread can attain (see struct | ||
2252 | 96 | thread_status, field int status): | ||
2253 | 97 | |||
2254 | 98 | - DM_THREAD_RUNNING: thread has started up and is either working or | ||
2255 | 99 | waiting for events... transitions to either SHUTDOWN or DONE | ||
2256 | 100 | - DM_THREAD_SHUTDOWN: thread is still doing something, but it is | ||
2257 | 101 | supposed to terminate (and transition to DONE) as soon as it | ||
2258 | 102 | finishes whatever it was doing at the point of flipping state to | ||
2259 | 103 | SHUTDOWN... the thread is still on the thread list | ||
2260 | 104 | - DM_THREAD_DONE: thread has terminated and has been moved over to | ||
2261 | 105 | unused thread list, cleanup pending | ||
2262 | 106 | */ | ||
2263 | 107 | #define DM_THREAD_RUNNING 0 | ||
2264 | 108 | #define DM_THREAD_SHUTDOWN 1 | ||
2265 | 109 | #define DM_THREAD_DONE 2 | ||
2266 | 110 | |||
2267 | 111 | #define THREAD_STACK_SIZE (300*1024) | ||
2268 | 112 | |||
2269 | 113 | int dmeventd_debug = 0; | ||
2270 | 114 | static int _systemd_activation = 0; | ||
2271 | 115 | static int _foreground = 0; | ||
2272 | 116 | static int _restart = 0; | ||
2273 | 117 | static char **_initial_registrations = 0; | ||
2274 | 118 | |||
2275 | 119 | /* Data kept about a DSO. */ | ||
2276 | 120 | struct dso_data { | ||
2277 | 121 | struct dm_list list; | ||
2278 | 122 | |||
2279 | 123 | char *dso_name; /* DSO name (eg, "evms", "dmraid", "lvm2"). */ | ||
2280 | 124 | |||
2281 | 125 | void *dso_handle; /* Opaque handle as returned from dlopen(). */ | ||
2282 | 126 | unsigned int ref_count; /* Library reference count. */ | ||
2283 | 127 | |||
2284 | 128 | /* | ||
2285 | 129 | * Event processing. | ||
2286 | 130 | * | ||
2287 | 131 | * The DSO can do whatever appropriate steps if an event | ||
2288 | 132 | * happens such as changing the mapping in case a mirror | ||
2289 | 133 | * fails, update the application metadata etc. | ||
2290 | 134 | * | ||
2291 | 135 | * This function gets a dm_task that is a result of | ||
2292 | 136 | * DM_DEVICE_WAITEVENT ioctl (results equivalent to | ||
2293 | 137 | * DM_DEVICE_STATUS). It should not destroy it. | ||
2294 | 138 | * The caller must dispose of the task. | ||
2295 | 139 | */ | ||
2296 | 140 | void (*process_event)(struct dm_task *dmt, enum dm_event_mask event, void **user); | ||
2297 | 141 | |||
2298 | 142 | /* | ||
2299 | 143 | * Device registration. | ||
2300 | 144 | * | ||
2301 | 145 | * When an application registers a device for an event, the DSO | ||
2302 | 146 | * can carry out appropriate steps so that a later call to | ||
2303 | 147 | * the process_event() function is sane (eg, read metadata | ||
2304 | 148 | * and activate a mapping). | ||
2305 | 149 | */ | ||
2306 | 150 | int (*register_device)(const char *device, const char *uuid, int major, | ||
2307 | 151 | int minor, void **user); | ||
2308 | 152 | |||
2309 | 153 | /* | ||
2310 | 154 | * Device unregistration. | ||
2311 | 155 | * | ||
2312 | 156 | * In case all devices of a mapping (eg, RAID10) are unregistered | ||
2313 | 157 | * for events, the DSO can recognize this and carry out appropriate | ||
2314 | 158 | * steps (eg, deactivate mapping, metadata update). | ||
2315 | 159 | */ | ||
2316 | 160 | int (*unregister_device)(const char *device, const char *uuid, | ||
2317 | 161 | int major, int minor, void **user); | ||
2318 | 162 | }; | ||
2319 | 163 | static DM_LIST_INIT(_dso_registry); | ||
2320 | 164 | |||
2321 | 165 | /* Structure to keep parsed register variables from client message. */ | ||
2322 | 166 | struct message_data { | ||
2323 | 167 | char *id; | ||
2324 | 168 | char *dso_name; /* Name of DSO. */ | ||
2325 | 169 | char *device_uuid; /* Mapped device path. */ | ||
2326 | 170 | union { | ||
2327 | 171 | char *str; /* Events string as fetched from message. */ | ||
2328 | 172 | enum dm_event_mask field; /* Events bitfield. */ | ||
2329 | 173 | } events; | ||
2330 | 174 | union { | ||
2331 | 175 | char *str; | ||
2332 | 176 | uint32_t secs; | ||
2333 | 177 | } timeout; | ||
2334 | 178 | struct dm_event_daemon_message *msg; /* Pointer to message buffer. */ | ||
2335 | 179 | }; | ||
2336 | 180 | |||
2337 | 181 | /* | ||
2338 | 182 | * Housekeeping of thread+device states. | ||
2339 | 183 | * | ||
2340 | 184 | * One thread per mapped device which can block on it until an event | ||
2341 | 185 | * occurs and the event processing function of the DSO gets called. | ||
2342 | 186 | */ | ||
2343 | 187 | struct thread_status { | ||
2344 | 188 | struct dm_list list; | ||
2345 | 189 | |||
2346 | 190 | pthread_t thread; | ||
2347 | 191 | |||
2348 | 192 | struct dso_data *dso_data; /* DSO this thread accesses. */ | ||
2349 | 193 | |||
2350 | 194 | struct { | ||
2351 | 195 | char *uuid; | ||
2352 | 196 | char *name; | ||
2353 | 197 | int major, minor; | ||
2354 | 198 | } device; | ||
2355 | 199 | uint32_t event_nr; /* event number */ | ||
2356 | 200 | int processing; /* Set when event is being processed */ | ||
2357 | 201 | |||
2358 | 202 | int status; /* see DM_THREAD_{RUNNING,SHUTDOWN,DONE} | ||
2359 | 203 | constants above */ | ||
2360 | 204 | enum dm_event_mask events; /* bitfield for event filter. */ | ||
2361 | 205 | enum dm_event_mask current_events; /* bitfield for occured events. */ | ||
2362 | 206 | struct dm_task *current_task; | ||
2363 | 207 | time_t next_time; | ||
2364 | 208 | uint32_t timeout; | ||
2365 | 209 | struct dm_list timeout_list; | ||
2366 | 210 | void *dso_private; /* dso per-thread status variable */ | ||
2367 | 211 | }; | ||
2368 | 212 | static DM_LIST_INIT(_thread_registry); | ||
2369 | 213 | static DM_LIST_INIT(_thread_registry_unused); | ||
2370 | 214 | |||
2371 | 215 | static int _timeout_running; | ||
2372 | 216 | static DM_LIST_INIT(_timeout_registry); | ||
2373 | 217 | static pthread_mutex_t _timeout_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
2374 | 218 | static pthread_cond_t _timeout_cond = PTHREAD_COND_INITIALIZER; | ||
2375 | 219 | |||
2376 | 220 | /* Allocate/free the status structure for a monitoring thread. */ | ||
2377 | 221 | static struct thread_status *_alloc_thread_status(struct message_data *data, | ||
2378 | 222 | struct dso_data *dso_data) | ||
2379 | 223 | { | ||
2380 | 224 | struct thread_status *ret = (typeof(ret)) dm_zalloc(sizeof(*ret)); | ||
2381 | 225 | |||
2382 | 226 | if (!ret) | ||
2383 | 227 | return NULL; | ||
2384 | 228 | |||
2385 | 229 | if (!(ret->device.uuid = dm_strdup(data->device_uuid))) { | ||
2386 | 230 | dm_free(ret); | ||
2387 | 231 | return NULL; | ||
2388 | 232 | } | ||
2389 | 233 | |||
2390 | 234 | ret->current_task = NULL; | ||
2391 | 235 | ret->device.name = NULL; | ||
2392 | 236 | ret->device.major = ret->device.minor = 0; | ||
2393 | 237 | ret->dso_data = dso_data; | ||
2394 | 238 | ret->events = data->events.field; | ||
2395 | 239 | ret->timeout = data->timeout.secs; | ||
2396 | 240 | dm_list_init(&ret->timeout_list); | ||
2397 | 241 | |||
2398 | 242 | return ret; | ||
2399 | 243 | } | ||
2400 | 244 | |||
2401 | 245 | static void _lib_put(struct dso_data *data); | ||
2402 | 246 | static void _free_thread_status(struct thread_status *thread) | ||
2403 | 247 | { | ||
2404 | 248 | _lib_put(thread->dso_data); | ||
2405 | 249 | if (thread->current_task) | ||
2406 | 250 | dm_task_destroy(thread->current_task); | ||
2407 | 251 | dm_free(thread->device.uuid); | ||
2408 | 252 | dm_free(thread->device.name); | ||
2409 | 253 | dm_free(thread); | ||
2410 | 254 | } | ||
2411 | 255 | |||
2412 | 256 | /* Allocate/free DSO data. */ | ||
2413 | 257 | static struct dso_data *_alloc_dso_data(struct message_data *data) | ||
2414 | 258 | { | ||
2415 | 259 | struct dso_data *ret = (typeof(ret)) dm_zalloc(sizeof(*ret)); | ||
2416 | 260 | |||
2417 | 261 | if (!ret) | ||
2418 | 262 | return NULL; | ||
2419 | 263 | |||
2420 | 264 | if (!(ret->dso_name = dm_strdup(data->dso_name))) { | ||
2421 | 265 | dm_free(ret); | ||
2422 | 266 | return NULL; | ||
2423 | 267 | } | ||
2424 | 268 | |||
2425 | 269 | return ret; | ||
2426 | 270 | } | ||
2427 | 271 | |||
2428 | 272 | /* Create a device monitoring thread. */ | ||
2429 | 273 | static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *arg) | ||
2430 | 274 | { | ||
2431 | 275 | pthread_attr_t attr; | ||
2432 | 276 | pthread_attr_init(&attr); | ||
2433 | 277 | /* | ||
2434 | 278 | * We use a smaller stack since it gets preallocated in its entirety | ||
2435 | 279 | */ | ||
2436 | 280 | pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE); | ||
2437 | 281 | return pthread_create(t, &attr, fun, arg); | ||
2438 | 282 | } | ||
2439 | 283 | |||
2440 | 284 | static void _free_dso_data(struct dso_data *data) | ||
2441 | 285 | { | ||
2442 | 286 | dm_free(data->dso_name); | ||
2443 | 287 | dm_free(data); | ||
2444 | 288 | } | ||
2445 | 289 | |||
2446 | 290 | /* | ||
2447 | 291 | * Fetch a string off src and duplicate it into *ptr. | ||
2448 | 292 | * Pay attention to zero-length strings. | ||
2449 | 293 | */ | ||
2450 | 294 | /* FIXME? move to libdevmapper to share with the client lib (need to | ||
2451 | 295 | make delimiter a parameter then) */ | ||
2452 | 296 | static int _fetch_string(char **ptr, char **src, const int delimiter) | ||
2453 | 297 | { | ||
2454 | 298 | int ret = 0; | ||
2455 | 299 | char *p; | ||
2456 | 300 | size_t len; | ||
2457 | 301 | |||
2458 | 302 | if ((p = strchr(*src, delimiter))) | ||
2459 | 303 | *p = 0; | ||
2460 | 304 | |||
2461 | 305 | if ((*ptr = dm_strdup(*src))) { | ||
2462 | 306 | if ((len = strlen(*ptr))) | ||
2463 | 307 | *src += len; | ||
2464 | 308 | else { | ||
2465 | 309 | dm_free(*ptr); | ||
2466 | 310 | *ptr = NULL; | ||
2467 | 311 | } | ||
2468 | 312 | |||
2469 | 313 | (*src)++; | ||
2470 | 314 | ret = 1; | ||
2471 | 315 | } | ||
2472 | 316 | |||
2473 | 317 | if (p) | ||
2474 | 318 | *p = delimiter; | ||
2475 | 319 | |||
2476 | 320 | return ret; | ||
2477 | 321 | } | ||
2478 | 322 | |||
2479 | 323 | /* Free message memory. */ | ||
2480 | 324 | static void _free_message(struct message_data *message_data) | ||
2481 | 325 | { | ||
2482 | 326 | dm_free(message_data->id); | ||
2483 | 327 | dm_free(message_data->dso_name); | ||
2484 | 328 | |||
2485 | 329 | dm_free(message_data->device_uuid); | ||
2486 | 330 | |||
2487 | 331 | } | ||
2488 | 332 | |||
2489 | 333 | /* Parse a register message from the client. */ | ||
2490 | 334 | static int _parse_message(struct message_data *message_data) | ||
2491 | 335 | { | ||
2492 | 336 | int ret = 0; | ||
2493 | 337 | char *p = message_data->msg->data; | ||
2494 | 338 | struct dm_event_daemon_message *msg = message_data->msg; | ||
2495 | 339 | |||
2496 | 340 | if (!msg->data) | ||
2497 | 341 | return 0; | ||
2498 | 342 | |||
2499 | 343 | /* | ||
2500 | 344 | * Retrieve application identifier, mapped device | ||
2501 | 345 | * path and events # string from message. | ||
2502 | 346 | */ | ||
2503 | 347 | if (_fetch_string(&message_data->id, &p, ' ') && | ||
2504 | 348 | _fetch_string(&message_data->dso_name, &p, ' ') && | ||
2505 | 349 | _fetch_string(&message_data->device_uuid, &p, ' ') && | ||
2506 | 350 | _fetch_string(&message_data->events.str, &p, ' ') && | ||
2507 | 351 | _fetch_string(&message_data->timeout.str, &p, ' ')) { | ||
2508 | 352 | if (message_data->events.str) { | ||
2509 | 353 | enum dm_event_mask i = atoi(message_data->events.str); | ||
2510 | 354 | |||
2511 | 355 | /* | ||
2512 | 356 | * Free string representaion of events. | ||
2513 | 357 | * Not needed an more. | ||
2514 | 358 | */ | ||
2515 | 359 | dm_free(message_data->events.str); | ||
2516 | 360 | message_data->events.field = i; | ||
2517 | 361 | } | ||
2518 | 362 | if (message_data->timeout.str) { | ||
2519 | 363 | uint32_t secs = atoi(message_data->timeout.str); | ||
2520 | 364 | dm_free(message_data->timeout.str); | ||
2521 | 365 | message_data->timeout.secs = secs ? secs : | ||
2522 | 366 | DM_EVENT_DEFAULT_TIMEOUT; | ||
2523 | 367 | } | ||
2524 | 368 | |||
2525 | 369 | ret = 1; | ||
2526 | 370 | } | ||
2527 | 371 | |||
2528 | 372 | dm_free(msg->data); | ||
2529 | 373 | msg->data = NULL; | ||
2530 | 374 | msg->size = 0; | ||
2531 | 375 | return ret; | ||
2532 | 376 | }; | ||
2533 | 377 | |||
2534 | 378 | /* Global mutex to lock access to lists et al. See _global_mutex | ||
2535 | 379 | above. */ | ||
2536 | 380 | static int _lock_mutex(void) | ||
2537 | 381 | { | ||
2538 | 382 | return pthread_mutex_lock(&_global_mutex); | ||
2539 | 383 | } | ||
2540 | 384 | |||
2541 | 385 | static int _unlock_mutex(void) | ||
2542 | 386 | { | ||
2543 | 387 | return pthread_mutex_unlock(&_global_mutex); | ||
2544 | 388 | } | ||
2545 | 389 | |||
2546 | 390 | /* Check, if a device exists. */ | ||
2547 | 391 | static int _fill_device_data(struct thread_status *ts) | ||
2548 | 392 | { | ||
2549 | 393 | struct dm_task *dmt; | ||
2550 | 394 | struct dm_info dmi; | ||
2551 | 395 | |||
2552 | 396 | if (!ts->device.uuid) | ||
2553 | 397 | return 0; | ||
2554 | 398 | |||
2555 | 399 | ts->device.name = NULL; | ||
2556 | 400 | ts->device.major = ts->device.minor = 0; | ||
2557 | 401 | |||
2558 | 402 | dmt = dm_task_create(DM_DEVICE_INFO); | ||
2559 | 403 | if (!dmt) | ||
2560 | 404 | return 0; | ||
2561 | 405 | |||
2562 | 406 | if (!dm_task_set_uuid(dmt, ts->device.uuid)) | ||
2563 | 407 | goto fail; | ||
2564 | 408 | |||
2565 | 409 | if (!dm_task_run(dmt)) | ||
2566 | 410 | goto fail; | ||
2567 | 411 | |||
2568 | 412 | ts->device.name = dm_strdup(dm_task_get_name(dmt)); | ||
2569 | 413 | if (!ts->device.name) | ||
2570 | 414 | goto fail; | ||
2571 | 415 | |||
2572 | 416 | if (!dm_task_get_info(dmt, &dmi)) | ||
2573 | 417 | goto fail; | ||
2574 | 418 | |||
2575 | 419 | ts->device.major = dmi.major; | ||
2576 | 420 | ts->device.minor = dmi.minor; | ||
2577 | 421 | |||
2578 | 422 | dm_task_destroy(dmt); | ||
2579 | 423 | return 1; | ||
2580 | 424 | |||
2581 | 425 | fail: | ||
2582 | 426 | dm_task_destroy(dmt); | ||
2583 | 427 | dm_free(ts->device.name); | ||
2584 | 428 | return 0; | ||
2585 | 429 | } | ||
2586 | 430 | |||
2587 | 431 | /* | ||
2588 | 432 | * Find an existing thread for a device. | ||
2589 | 433 | * | ||
2590 | 434 | * Mutex must be held when calling this. | ||
2591 | 435 | */ | ||
2592 | 436 | static struct thread_status *_lookup_thread_status(struct message_data *data) | ||
2593 | 437 | { | ||
2594 | 438 | struct thread_status *thread; | ||
2595 | 439 | |||
2596 | 440 | dm_list_iterate_items(thread, &_thread_registry) | ||
2597 | 441 | if (!strcmp(data->device_uuid, thread->device.uuid)) | ||
2598 | 442 | return thread; | ||
2599 | 443 | |||
2600 | 444 | return NULL; | ||
2601 | 445 | } | ||
2602 | 446 | |||
2603 | 447 | static int _get_status(struct message_data *message_data) | ||
2604 | 448 | { | ||
2605 | 449 | struct dm_event_daemon_message *msg = message_data->msg; | ||
2606 | 450 | struct thread_status *thread; | ||
2607 | 451 | int i, j; | ||
2608 | 452 | int ret = -1; | ||
2609 | 453 | int count = dm_list_size(&_thread_registry); | ||
2610 | 454 | int size = 0, current = 0; | ||
2611 | 455 | char *buffers[count]; | ||
2612 | 456 | char *message; | ||
2613 | 457 | |||
2614 | 458 | dm_free(msg->data); | ||
2615 | 459 | |||
2616 | 460 | for (i = 0; i < count; ++i) | ||
2617 | 461 | buffers[i] = NULL; | ||
2618 | 462 | |||
2619 | 463 | i = 0; | ||
2620 | 464 | _lock_mutex(); | ||
2621 | 465 | dm_list_iterate_items(thread, &_thread_registry) { | ||
2622 | 466 | if ((current = dm_asprintf(buffers + i, "0:%d %s %s %u %" PRIu32 ";", | ||
2623 | 467 | i, thread->dso_data->dso_name, | ||
2624 | 468 | thread->device.uuid, thread->events, | ||
2625 | 469 | thread->timeout)) < 0) { | ||
2626 | 470 | _unlock_mutex(); | ||
2627 | 471 | goto out; | ||
2628 | 472 | } | ||
2629 | 473 | ++ i; | ||
2630 | 474 | size += current; | ||
2631 | 475 | } | ||
2632 | 476 | _unlock_mutex(); | ||
2633 | 477 | |||
2634 | 478 | msg->size = size + strlen(message_data->id) + 1; | ||
2635 | 479 | msg->data = dm_malloc(msg->size); | ||
2636 | 480 | if (!msg->data) | ||
2637 | 481 | goto out; | ||
2638 | 482 | *msg->data = 0; | ||
2639 | 483 | |||
2640 | 484 | message = msg->data; | ||
2641 | 485 | strcpy(message, message_data->id); | ||
2642 | 486 | message += strlen(message_data->id); | ||
2643 | 487 | *message = ' '; | ||
2644 | 488 | message ++; | ||
2645 | 489 | for (j = 0; j < i; ++j) { | ||
2646 | 490 | strcpy(message, buffers[j]); | ||
2647 | 491 | message += strlen(buffers[j]); | ||
2648 | 492 | } | ||
2649 | 493 | |||
2650 | 494 | ret = 0; | ||
2651 | 495 | out: | ||
2652 | 496 | for (j = 0; j < i; ++j) | ||
2653 | 497 | dm_free(buffers[j]); | ||
2654 | 498 | return ret; | ||
2655 | 499 | |||
2656 | 500 | } | ||
2657 | 501 | |||
2658 | 502 | /* Cleanup at exit. */ | ||
2659 | 503 | static void _exit_dm_lib(void) | ||
2660 | 504 | { | ||
2661 | 505 | dm_lib_release(); | ||
2662 | 506 | dm_lib_exit(); | ||
2663 | 507 | } | ||
2664 | 508 | |||
2665 | 509 | static void _exit_timeout(void *unused __attribute__((unused))) | ||
2666 | 510 | { | ||
2667 | 511 | _timeout_running = 0; | ||
2668 | 512 | pthread_mutex_unlock(&_timeout_mutex); | ||
2669 | 513 | } | ||
2670 | 514 | |||
2671 | 515 | /* Wake up monitor threads every so often. */ | ||
2672 | 516 | static void *_timeout_thread(void *unused __attribute__((unused))) | ||
2673 | 517 | { | ||
2674 | 518 | struct timespec timeout; | ||
2675 | 519 | time_t curr_time; | ||
2676 | 520 | |||
2677 | 521 | timeout.tv_nsec = 0; | ||
2678 | 522 | pthread_cleanup_push(_exit_timeout, NULL); | ||
2679 | 523 | pthread_mutex_lock(&_timeout_mutex); | ||
2680 | 524 | |||
2681 | 525 | while (!dm_list_empty(&_timeout_registry)) { | ||
2682 | 526 | struct thread_status *thread; | ||
2683 | 527 | |||
2684 | 528 | timeout.tv_sec = 0; | ||
2685 | 529 | curr_time = time(NULL); | ||
2686 | 530 | |||
2687 | 531 | dm_list_iterate_items_gen(thread, &_timeout_registry, timeout_list) { | ||
2688 | 532 | if (thread->next_time <= curr_time) { | ||
2689 | 533 | thread->next_time = curr_time + thread->timeout; | ||
2690 | 534 | pthread_kill(thread->thread, SIGALRM); | ||
2691 | 535 | } | ||
2692 | 536 | |||
2693 | 537 | if (thread->next_time < timeout.tv_sec || !timeout.tv_sec) | ||
2694 | 538 | timeout.tv_sec = thread->next_time; | ||
2695 | 539 | } | ||
2696 | 540 | |||
2697 | 541 | pthread_cond_timedwait(&_timeout_cond, &_timeout_mutex, | ||
2698 | 542 | &timeout); | ||
2699 | 543 | } | ||
2700 | 544 | |||
2701 | 545 | pthread_cleanup_pop(1); | ||
2702 | 546 | |||
2703 | 547 | return NULL; | ||
2704 | 548 | } | ||
2705 | 549 | |||
2706 | 550 | static int _register_for_timeout(struct thread_status *thread) | ||
2707 | 551 | { | ||
2708 | 552 | int ret = 0; | ||
2709 | 553 | |||
2710 | 554 | pthread_mutex_lock(&_timeout_mutex); | ||
2711 | 555 | |||
2712 | 556 | thread->next_time = time(NULL) + thread->timeout; | ||
2713 | 557 | |||
2714 | 558 | if (dm_list_empty(&thread->timeout_list)) { | ||
2715 | 559 | dm_list_add(&_timeout_registry, &thread->timeout_list); | ||
2716 | 560 | if (_timeout_running) | ||
2717 | 561 | pthread_cond_signal(&_timeout_cond); | ||
2718 | 562 | } | ||
2719 | 563 | |||
2720 | 564 | if (!_timeout_running) { | ||
2721 | 565 | pthread_t timeout_id; | ||
2722 | 566 | |||
2723 | 567 | if (!(ret = -_pthread_create_smallstack(&timeout_id, _timeout_thread, NULL))) | ||
2724 | 568 | _timeout_running = 1; | ||
2725 | 569 | } | ||
2726 | 570 | |||
2727 | 571 | pthread_mutex_unlock(&_timeout_mutex); | ||
2728 | 572 | |||
2729 | 573 | return ret; | ||
2730 | 574 | } | ||
2731 | 575 | |||
2732 | 576 | static void _unregister_for_timeout(struct thread_status *thread) | ||
2733 | 577 | { | ||
2734 | 578 | pthread_mutex_lock(&_timeout_mutex); | ||
2735 | 579 | if (!dm_list_empty(&thread->timeout_list)) { | ||
2736 | 580 | dm_list_del(&thread->timeout_list); | ||
2737 | 581 | dm_list_init(&thread->timeout_list); | ||
2738 | 582 | } | ||
2739 | 583 | pthread_mutex_unlock(&_timeout_mutex); | ||
2740 | 584 | } | ||
2741 | 585 | |||
2742 | 586 | __attribute__((format(printf, 4, 5))) | ||
2743 | 587 | static void _no_intr_log(int level, const char *file, int line, | ||
2744 | 588 | const char *f, ...) | ||
2745 | 589 | { | ||
2746 | 590 | va_list ap; | ||
2747 | 591 | |||
2748 | 592 | if (errno == EINTR) | ||
2749 | 593 | return; | ||
2750 | 594 | if (level > _LOG_WARN) | ||
2751 | 595 | return; | ||
2752 | 596 | |||
2753 | 597 | va_start(ap, f); | ||
2754 | 598 | |||
2755 | 599 | if (level < _LOG_WARN) | ||
2756 | 600 | vfprintf(stderr, f, ap); | ||
2757 | 601 | else | ||
2758 | 602 | vprintf(f, ap); | ||
2759 | 603 | |||
2760 | 604 | va_end(ap); | ||
2761 | 605 | |||
2762 | 606 | if (level < _LOG_WARN) | ||
2763 | 607 | fprintf(stderr, "\n"); | ||
2764 | 608 | else | ||
2765 | 609 | fprintf(stdout, "\n"); | ||
2766 | 610 | } | ||
2767 | 611 | |||
2768 | 612 | static sigset_t _unblock_sigalrm(void) | ||
2769 | 613 | { | ||
2770 | 614 | sigset_t set, old; | ||
2771 | 615 | |||
2772 | 616 | sigemptyset(&set); | ||
2773 | 617 | sigaddset(&set, SIGALRM); | ||
2774 | 618 | pthread_sigmask(SIG_UNBLOCK, &set, &old); | ||
2775 | 619 | return old; | ||
2776 | 620 | } | ||
2777 | 621 | |||
2778 | 622 | #define DM_WAIT_RETRY 0 | ||
2779 | 623 | #define DM_WAIT_INTR 1 | ||
2780 | 624 | #define DM_WAIT_FATAL 2 | ||
2781 | 625 | |||
2782 | 626 | /* Wait on a device until an event occurs. */ | ||
2783 | 627 | static int _event_wait(struct thread_status *thread, struct dm_task **task) | ||
2784 | 628 | { | ||
2785 | 629 | sigset_t set; | ||
2786 | 630 | int ret = DM_WAIT_RETRY; | ||
2787 | 631 | struct dm_task *dmt; | ||
2788 | 632 | struct dm_info info; | ||
2789 | 633 | |||
2790 | 634 | *task = 0; | ||
2791 | 635 | |||
2792 | 636 | if (!(dmt = dm_task_create(DM_DEVICE_WAITEVENT))) | ||
2793 | 637 | return DM_WAIT_RETRY; | ||
2794 | 638 | |||
2795 | 639 | thread->current_task = dmt; | ||
2796 | 640 | |||
2797 | 641 | if (!dm_task_set_uuid(dmt, thread->device.uuid) || | ||
2798 | 642 | !dm_task_set_event_nr(dmt, thread->event_nr)) | ||
2799 | 643 | goto out; | ||
2800 | 644 | |||
2801 | 645 | /* | ||
2802 | 646 | * This is so that you can break out of waiting on an event, | ||
2803 | 647 | * either for a timeout event, or to cancel the thread. | ||
2804 | 648 | */ | ||
2805 | 649 | set = _unblock_sigalrm(); | ||
2806 | 650 | dm_log_init(_no_intr_log); | ||
2807 | 651 | errno = 0; | ||
2808 | 652 | if (dm_task_run(dmt)) { | ||
2809 | 653 | thread->current_events |= DM_EVENT_DEVICE_ERROR; | ||
2810 | 654 | ret = DM_WAIT_INTR; | ||
2811 | 655 | |||
2812 | 656 | if ((ret = dm_task_get_info(dmt, &info))) | ||
2813 | 657 | thread->event_nr = info.event_nr; | ||
2814 | 658 | } else if (thread->events & DM_EVENT_TIMEOUT && errno == EINTR) { | ||
2815 | 659 | thread->current_events |= DM_EVENT_TIMEOUT; | ||
2816 | 660 | ret = DM_WAIT_INTR; | ||
2817 | 661 | } else if (thread->status == DM_THREAD_SHUTDOWN && errno == EINTR) { | ||
2818 | 662 | ret = DM_WAIT_FATAL; | ||
2819 | 663 | } else { | ||
2820 | 664 | syslog(LOG_NOTICE, "dm_task_run failed, errno = %d, %s", | ||
2821 | 665 | errno, strerror(errno)); | ||
2822 | 666 | if (errno == ENXIO) { | ||
2823 | 667 | syslog(LOG_ERR, "%s disappeared, detaching", | ||
2824 | 668 | thread->device.name); | ||
2825 | 669 | ret = DM_WAIT_FATAL; | ||
2826 | 670 | } | ||
2827 | 671 | } | ||
2828 | 672 | |||
2829 | 673 | pthread_sigmask(SIG_SETMASK, &set, NULL); | ||
2830 | 674 | dm_log_init(NULL); | ||
2831 | 675 | |||
2832 | 676 | out: | ||
2833 | 677 | if (ret == DM_WAIT_FATAL || ret == DM_WAIT_RETRY) { | ||
2834 | 678 | dm_task_destroy(dmt); | ||
2835 | 679 | thread->current_task = NULL; | ||
2836 | 680 | } else | ||
2837 | 681 | *task = dmt; | ||
2838 | 682 | |||
2839 | 683 | return ret; | ||
2840 | 684 | } | ||
2841 | 685 | |||
2842 | 686 | /* Register a device with the DSO. */ | ||
2843 | 687 | static int _do_register_device(struct thread_status *thread) | ||
2844 | 688 | { | ||
2845 | 689 | return thread->dso_data->register_device(thread->device.name, | ||
2846 | 690 | thread->device.uuid, | ||
2847 | 691 | thread->device.major, | ||
2848 | 692 | thread->device.minor, | ||
2849 | 693 | &(thread->dso_private)); | ||
2850 | 694 | } | ||
2851 | 695 | |||
2852 | 696 | /* Unregister a device with the DSO. */ | ||
2853 | 697 | static int _do_unregister_device(struct thread_status *thread) | ||
2854 | 698 | { | ||
2855 | 699 | return thread->dso_data->unregister_device(thread->device.name, | ||
2856 | 700 | thread->device.uuid, | ||
2857 | 701 | thread->device.major, | ||
2858 | 702 | thread->device.minor, | ||
2859 | 703 | &(thread->dso_private)); | ||
2860 | 704 | } | ||
2861 | 705 | |||
2862 | 706 | /* Process an event in the DSO. */ | ||
2863 | 707 | static void _do_process_event(struct thread_status *thread, struct dm_task *task) | ||
2864 | 708 | { | ||
2865 | 709 | thread->dso_data->process_event(task, thread->current_events, &(thread->dso_private)); | ||
2866 | 710 | } | ||
2867 | 711 | |||
2868 | 712 | /* Thread cleanup handler to unregister device. */ | ||
2869 | 713 | static void _monitor_unregister(void *arg) | ||
2870 | 714 | { | ||
2871 | 715 | struct thread_status *thread = arg, *thread_iter; | ||
2872 | 716 | |||
2873 | 717 | if (!_do_unregister_device(thread)) | ||
2874 | 718 | syslog(LOG_ERR, "%s: %s unregister failed\n", __func__, | ||
2875 | 719 | thread->device.name); | ||
2876 | 720 | if (thread->current_task) | ||
2877 | 721 | dm_task_destroy(thread->current_task); | ||
2878 | 722 | thread->current_task = NULL; | ||
2879 | 723 | |||
2880 | 724 | _lock_mutex(); | ||
2881 | 725 | if (thread->events & DM_EVENT_TIMEOUT) { | ||
2882 | 726 | /* _unregister_for_timeout locks another mutex, we | ||
2883 | 727 | don't want to deadlock so we release our mutex for | ||
2884 | 728 | a bit */ | ||
2885 | 729 | _unlock_mutex(); | ||
2886 | 730 | _unregister_for_timeout(thread); | ||
2887 | 731 | _lock_mutex(); | ||
2888 | 732 | } | ||
2889 | 733 | /* we may have been relinked to unused registry since we were | ||
2890 | 734 | called, so check that */ | ||
2891 | 735 | dm_list_iterate_items(thread_iter, &_thread_registry_unused) | ||
2892 | 736 | if (thread_iter == thread) { | ||
2893 | 737 | thread->status = DM_THREAD_DONE; | ||
2894 | 738 | _unlock_mutex(); | ||
2895 | 739 | return; | ||
2896 | 740 | } | ||
2897 | 741 | thread->status = DM_THREAD_DONE; | ||
2898 | 742 | pthread_mutex_lock(&_timeout_mutex); | ||
2899 | 743 | UNLINK_THREAD(thread); | ||
2900 | 744 | LINK(thread, &_thread_registry_unused); | ||
2901 | 745 | pthread_mutex_unlock(&_timeout_mutex); | ||
2902 | 746 | _unlock_mutex(); | ||
2903 | 747 | } | ||
2904 | 748 | |||
2905 | 749 | static struct dm_task *_get_device_status(struct thread_status *ts) | ||
2906 | 750 | { | ||
2907 | 751 | struct dm_task *dmt = dm_task_create(DM_DEVICE_STATUS); | ||
2908 | 752 | |||
2909 | 753 | if (!dmt) | ||
2910 | 754 | return NULL; | ||
2911 | 755 | |||
2912 | 756 | if (!dm_task_set_uuid(dmt, ts->device.uuid)) { | ||
2913 | 757 | dm_task_destroy(dmt); | ||
2914 | 758 | return NULL; | ||
2915 | 759 | } | ||
2916 | 760 | |||
2917 | 761 | if (!dm_task_run(dmt)) { | ||
2918 | 762 | dm_task_destroy(dmt); | ||
2919 | 763 | return NULL; | ||
2920 | 764 | } | ||
2921 | 765 | |||
2922 | 766 | return dmt; | ||
2923 | 767 | } | ||
2924 | 768 | |||
2925 | 769 | /* Device monitoring thread. */ | ||
2926 | 770 | static void *_monitor_thread(void *arg) | ||
2927 | 771 | { | ||
2928 | 772 | struct thread_status *thread = arg; | ||
2929 | 773 | int wait_error = 0; | ||
2930 | 774 | struct dm_task *task; | ||
2931 | 775 | |||
2932 | 776 | pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); | ||
2933 | 777 | pthread_cleanup_push(_monitor_unregister, thread); | ||
2934 | 778 | |||
2935 | 779 | /* Wait for do_process_request() to finish its task. */ | ||
2936 | 780 | _lock_mutex(); | ||
2937 | 781 | thread->status = DM_THREAD_RUNNING; | ||
2938 | 782 | _unlock_mutex(); | ||
2939 | 783 | |||
2940 | 784 | /* Loop forever awaiting/analyzing device events. */ | ||
2941 | 785 | while (1) { | ||
2942 | 786 | thread->current_events = 0; | ||
2943 | 787 | |||
2944 | 788 | wait_error = _event_wait(thread, &task); | ||
2945 | 789 | if (wait_error == DM_WAIT_RETRY) | ||
2946 | 790 | continue; | ||
2947 | 791 | |||
2948 | 792 | if (wait_error == DM_WAIT_FATAL) | ||
2949 | 793 | break; | ||
2950 | 794 | |||
2951 | 795 | /* Timeout occurred, task is not filled properly. | ||
2952 | 796 | * We get device status here for processing it in DSO. | ||
2953 | 797 | */ | ||
2954 | 798 | if (wait_error == DM_WAIT_INTR && | ||
2955 | 799 | thread->current_events & DM_EVENT_TIMEOUT) { | ||
2956 | 800 | dm_task_destroy(task); | ||
2957 | 801 | task = _get_device_status(thread); | ||
2958 | 802 | /* FIXME: syslog fail here ? */ | ||
2959 | 803 | if (!(thread->current_task = task)) | ||
2960 | 804 | continue; | ||
2961 | 805 | } | ||
2962 | 806 | |||
2963 | 807 | /* | ||
2964 | 808 | * We know that wait succeeded and stored a | ||
2965 | 809 | * pointer to dm_task with device status into task. | ||
2966 | 810 | */ | ||
2967 | 811 | |||
2968 | 812 | /* | ||
2969 | 813 | * Check against filter. | ||
2970 | 814 | * | ||
2971 | 815 | * If there's current events delivered from _event_wait() AND | ||
2972 | 816 | * the device got registered for those events AND | ||
2973 | 817 | * those events haven't been processed yet, call | ||
2974 | 818 | * the DSO's process_event() handler. | ||
2975 | 819 | */ | ||
2976 | 820 | _lock_mutex(); | ||
2977 | 821 | if (thread->status == DM_THREAD_SHUTDOWN) { | ||
2978 | 822 | _unlock_mutex(); | ||
2979 | 823 | break; | ||
2980 | 824 | } | ||
2981 | 825 | _unlock_mutex(); | ||
2982 | 826 | |||
2983 | 827 | if (thread->events & thread->current_events) { | ||
2984 | 828 | _lock_mutex(); | ||
2985 | 829 | thread->processing = 1; | ||
2986 | 830 | _unlock_mutex(); | ||
2987 | 831 | |||
2988 | 832 | _do_process_event(thread, task); | ||
2989 | 833 | dm_task_destroy(task); | ||
2990 | 834 | thread->current_task = NULL; | ||
2991 | 835 | |||
2992 | 836 | _lock_mutex(); | ||
2993 | 837 | thread->processing = 0; | ||
2994 | 838 | _unlock_mutex(); | ||
2995 | 839 | } else { | ||
2996 | 840 | dm_task_destroy(task); | ||
2997 | 841 | thread->current_task = NULL; | ||
2998 | 842 | } | ||
2999 | 843 | } | ||
3000 | 844 | |||
3001 | 845 | pthread_cleanup_pop(1); | ||
3002 | 846 | |||
3003 | 847 | return NULL; | ||
3004 | 848 | } | ||
3005 | 849 | |||
3006 | 850 | /* Create a device monitoring thread. */ | ||
3007 | 851 | static int _create_thread(struct thread_status *thread) | ||
3008 | 852 | { | ||
3009 | 853 | return _pthread_create_smallstack(&thread->thread, _monitor_thread, thread); | ||
3010 | 854 | } | ||
3011 | 855 | |||
3012 | 856 | static int _terminate_thread(struct thread_status *thread) | ||
3013 | 857 | { | ||
3014 | 858 | return pthread_kill(thread->thread, SIGALRM); | ||
3015 | 859 | } | ||
3016 | 860 | |||
3017 | 861 | /* DSO reference counting. Call with _global_mutex locked! */ | ||
3018 | 862 | static void _lib_get(struct dso_data *data) | ||
3019 | 863 | { | ||
3020 | 864 | data->ref_count++; | ||
3021 | 865 | } | ||
3022 | 866 | |||
3023 | 867 | static void _lib_put(struct dso_data *data) | ||
3024 | 868 | { | ||
3025 | 869 | if (!--data->ref_count) { | ||
3026 | 870 | dlclose(data->dso_handle); | ||
3027 | 871 | UNLINK_DSO(data); | ||
3028 | 872 | _free_dso_data(data); | ||
3029 | 873 | } | ||
3030 | 874 | } | ||
3031 | 875 | |||
3032 | 876 | /* Find DSO data. */ | ||
3033 | 877 | static struct dso_data *_lookup_dso(struct message_data *data) | ||
3034 | 878 | { | ||
3035 | 879 | struct dso_data *dso_data, *ret = NULL; | ||
3036 | 880 | |||
3037 | 881 | dm_list_iterate_items(dso_data, &_dso_registry) | ||
3038 | 882 | if (!strcmp(data->dso_name, dso_data->dso_name)) { | ||
3039 | 883 | _lib_get(dso_data); | ||
3040 | 884 | ret = dso_data; | ||
3041 | 885 | break; | ||
3042 | 886 | } | ||
3043 | 887 | |||
3044 | 888 | return ret; | ||
3045 | 889 | } | ||
3046 | 890 | |||
3047 | 891 | /* Lookup DSO symbols we need. */ | ||
3048 | 892 | static int _lookup_symbol(void *dl, void **symbol, const char *name) | ||
3049 | 893 | { | ||
3050 | 894 | if ((*symbol = dlsym(dl, name))) | ||
3051 | 895 | return 1; | ||
3052 | 896 | |||
3053 | 897 | return 0; | ||
3054 | 898 | } | ||
3055 | 899 | |||
3056 | 900 | static int lookup_symbols(void *dl, struct dso_data *data) | ||
3057 | 901 | { | ||
3058 | 902 | return _lookup_symbol(dl, (void *) &data->process_event, | ||
3059 | 903 | "process_event") && | ||
3060 | 904 | _lookup_symbol(dl, (void *) &data->register_device, | ||
3061 | 905 | "register_device") && | ||
3062 | 906 | _lookup_symbol(dl, (void *) &data->unregister_device, | ||
3063 | 907 | "unregister_device"); | ||
3064 | 908 | } | ||
3065 | 909 | |||
3066 | 910 | /* Load an application specific DSO. */ | ||
3067 | 911 | static struct dso_data *_load_dso(struct message_data *data) | ||
3068 | 912 | { | ||
3069 | 913 | void *dl; | ||
3070 | 914 | struct dso_data *ret = NULL; | ||
3071 | 915 | |||
3072 | 916 | if (!(dl = dlopen(data->dso_name, RTLD_NOW))) { | ||
3073 | 917 | const char *dlerr = dlerror(); | ||
3074 | 918 | syslog(LOG_ERR, "dmeventd %s dlopen failed: %s", data->dso_name, | ||
3075 | 919 | dlerr); | ||
3076 | 920 | data->msg->size = | ||
3077 | 921 | dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s", | ||
3078 | 922 | data->id, data->dso_name, dlerr); | ||
3079 | 923 | return NULL; | ||
3080 | 924 | } | ||
3081 | 925 | |||
3082 | 926 | if (!(ret = _alloc_dso_data(data))) { | ||
3083 | 927 | dlclose(dl); | ||
3084 | 928 | return NULL; | ||
3085 | 929 | } | ||
3086 | 930 | |||
3087 | 931 | if (!(lookup_symbols(dl, ret))) { | ||
3088 | 932 | _free_dso_data(ret); | ||
3089 | 933 | dlclose(dl); | ||
3090 | 934 | return NULL; | ||
3091 | 935 | } | ||
3092 | 936 | |||
3093 | 937 | /* | ||
3094 | 938 | * Keep handle to close the library once | ||
3095 | 939 | * we've got no references to it any more. | ||
3096 | 940 | */ | ||
3097 | 941 | ret->dso_handle = dl; | ||
3098 | 942 | _lib_get(ret); | ||
3099 | 943 | |||
3100 | 944 | _lock_mutex(); | ||
3101 | 945 | LINK_DSO(ret); | ||
3102 | 946 | _unlock_mutex(); | ||
3103 | 947 | |||
3104 | 948 | return ret; | ||
3105 | 949 | } | ||
3106 | 950 | |||
3107 | 951 | /* Return success on daemon active check. */ | ||
3108 | 952 | static int _active(struct message_data *message_data) | ||
3109 | 953 | { | ||
3110 | 954 | return 0; | ||
3111 | 955 | } | ||
3112 | 956 | |||
3113 | 957 | /* | ||
3114 | 958 | * Register for an event. | ||
3115 | 959 | * | ||
3116 | 960 | * Only one caller at a time here, because we use | ||
3117 | 961 | * a FIFO and lock it against multiple accesses. | ||
3118 | 962 | */ | ||
3119 | 963 | static int _register_for_event(struct message_data *message_data) | ||
3120 | 964 | { | ||
3121 | 965 | int ret = 0; | ||
3122 | 966 | struct thread_status *thread, *thread_new = NULL; | ||
3123 | 967 | struct dso_data *dso_data; | ||
3124 | 968 | |||
3125 | 969 | if (!(dso_data = _lookup_dso(message_data)) && | ||
3126 | 970 | !(dso_data = _load_dso(message_data))) { | ||
3127 | 971 | stack; | ||
3128 | 972 | #ifdef ELIBACC | ||
3129 | 973 | ret = -ELIBACC; | ||
3130 | 974 | #else | ||
3131 | 975 | ret = -ENODEV; | ||
3132 | 976 | #endif | ||
3133 | 977 | goto out; | ||
3134 | 978 | } | ||
3135 | 979 | |||
3136 | 980 | /* Preallocate thread status struct to avoid deadlock. */ | ||
3137 | 981 | if (!(thread_new = _alloc_thread_status(message_data, dso_data))) { | ||
3138 | 982 | stack; | ||
3139 | 983 | ret = -ENOMEM; | ||
3140 | 984 | goto out; | ||
3141 | 985 | } | ||
3142 | 986 | |||
3143 | 987 | if (!_fill_device_data(thread_new)) { | ||
3144 | 988 | stack; | ||
3145 | 989 | ret = -ENODEV; | ||
3146 | 990 | goto out; | ||
3147 | 991 | } | ||
3148 | 992 | |||
3149 | 993 | _lock_mutex(); | ||
3150 | 994 | |||
3151 | 995 | /* If creation of timeout thread fails (as it may), we fail | ||
3152 | 996 | here completely. The client is responsible for either | ||
3153 | 997 | retrying later or trying to register without timeout | ||
3154 | 998 | events. However, if timeout thread cannot be started, it | ||
3155 | 999 | usually means we are so starved on resources that we are | ||
3156 | 1000 | almost as good as dead already... */ | ||
3157 | 1001 | if (thread_new->events & DM_EVENT_TIMEOUT) { | ||
3158 | 1002 | ret = -_register_for_timeout(thread_new); | ||
3159 | 1003 | if (ret) | ||
3160 | 1004 | goto outth; | ||
3161 | 1005 | } | ||
3162 | 1006 | |||
3163 | 1007 | if (!(thread = _lookup_thread_status(message_data))) { | ||
3164 | 1008 | _unlock_mutex(); | ||
3165 | 1009 | |||
3166 | 1010 | if (!(ret = _do_register_device(thread_new))) | ||
3167 | 1011 | goto out; | ||
3168 | 1012 | |||
3169 | 1013 | thread = thread_new; | ||
3170 | 1014 | thread_new = NULL; | ||
3171 | 1015 | |||
3172 | 1016 | /* Try to create the monitoring thread for this device. */ | ||
3173 | 1017 | _lock_mutex(); | ||
3174 | 1018 | if ((ret = -_create_thread(thread))) { | ||
3175 | 1019 | _unlock_mutex(); | ||
3176 | 1020 | _do_unregister_device(thread); | ||
3177 | 1021 | _free_thread_status(thread); | ||
3178 | 1022 | goto out; | ||
3179 | 1023 | } else | ||
3180 | 1024 | LINK_THREAD(thread); | ||
3181 | 1025 | } | ||
3182 | 1026 | |||
3183 | 1027 | /* Or event # into events bitfield. */ | ||
3184 | 1028 | thread->events |= message_data->events.field; | ||
3185 | 1029 | |||
3186 | 1030 | outth: | ||
3187 | 1031 | _unlock_mutex(); | ||
3188 | 1032 | |||
3189 | 1033 | out: | ||
3190 | 1034 | /* | ||
3191 | 1035 | * Deallocate thread status after releasing | ||
3192 | 1036 | * the lock in case we haven't used it. | ||
3193 | 1037 | */ | ||
3194 | 1038 | if (thread_new) | ||
3195 | 1039 | _free_thread_status(thread_new); | ||
3196 | 1040 | |||
3197 | 1041 | return ret; | ||
3198 | 1042 | } | ||
3199 | 1043 | |||
3200 | 1044 | /* | ||
3201 | 1045 | * Unregister for an event. | ||
3202 | 1046 | * | ||
3203 | 1047 | * Only one caller at a time here as with register_for_event(). | ||
3204 | 1048 | */ | ||
3205 | 1049 | static int _unregister_for_event(struct message_data *message_data) | ||
3206 | 1050 | { | ||
3207 | 1051 | int ret = 0; | ||
3208 | 1052 | struct thread_status *thread; | ||
3209 | 1053 | |||
3210 | 1054 | /* | ||
3211 | 1055 | * Clear event in bitfield and deactivate | ||
3212 | 1056 | * monitoring thread in case bitfield is 0. | ||
3213 | 1057 | */ | ||
3214 | 1058 | _lock_mutex(); | ||
3215 | 1059 | |||
3216 | 1060 | if (!(thread = _lookup_thread_status(message_data))) { | ||
3217 | 1061 | _unlock_mutex(); | ||
3218 | 1062 | ret = -ENODEV; | ||
3219 | 1063 | goto out; | ||
3220 | 1064 | } | ||
3221 | 1065 | |||
3222 | 1066 | if (thread->status == DM_THREAD_DONE) { | ||
3223 | 1067 | /* the thread has terminated while we were not | ||
3224 | 1068 | watching */ | ||
3225 | 1069 | _unlock_mutex(); | ||
3226 | 1070 | return 0; | ||
3227 | 1071 | } | ||
3228 | 1072 | |||
3229 | 1073 | thread->events &= ~message_data->events.field; | ||
3230 | 1074 | |||
3231 | 1075 | if (!(thread->events & DM_EVENT_TIMEOUT)) | ||
3232 | 1076 | _unregister_for_timeout(thread); | ||
3233 | 1077 | /* | ||
3234 | 1078 | * In case there's no events to monitor on this device -> | ||
3235 | 1079 | * unlink and terminate its monitoring thread. | ||
3236 | 1080 | */ | ||
3237 | 1081 | if (!thread->events) { | ||
3238 | 1082 | pthread_mutex_lock(&_timeout_mutex); | ||
3239 | 1083 | UNLINK_THREAD(thread); | ||
3240 | 1084 | LINK(thread, &_thread_registry_unused); | ||
3241 | 1085 | pthread_mutex_unlock(&_timeout_mutex); | ||
3242 | 1086 | } | ||
3243 | 1087 | _unlock_mutex(); | ||
3244 | 1088 | |||
3245 | 1089 | out: | ||
3246 | 1090 | return ret; | ||
3247 | 1091 | } | ||
3248 | 1092 | |||
3249 | 1093 | /* | ||
3250 | 1094 | * Get registered device. | ||
3251 | 1095 | * | ||
3252 | 1096 | * Only one caller at a time here as with register_for_event(). | ||
3253 | 1097 | */ | ||
3254 | 1098 | static int _registered_device(struct message_data *message_data, | ||
3255 | 1099 | struct thread_status *thread) | ||
3256 | 1100 | { | ||
3257 | 1101 | struct dm_event_daemon_message *msg = message_data->msg; | ||
3258 | 1102 | |||
3259 | 1103 | const char *fmt = "%s %s %s %u"; | ||
3260 | 1104 | const char *id = message_data->id; | ||
3261 | 1105 | const char *dso = thread->dso_data->dso_name; | ||
3262 | 1106 | const char *dev = thread->device.uuid; | ||
3263 | 1107 | int r; | ||
3264 | 1108 | unsigned events = ((thread->status == DM_THREAD_RUNNING) | ||
3265 | 1109 | && (thread->events)) ? thread->events : thread-> | ||
3266 | 1110 | events | DM_EVENT_REGISTRATION_PENDING; | ||
3267 | 1111 | |||
3268 | 1112 | dm_free(msg->data); | ||
3269 | 1113 | |||
3270 | 1114 | if ((r = dm_asprintf(&(msg->data), fmt, id, dso, dev, events)) < 0) { | ||
3271 | 1115 | msg->size = 0; | ||
3272 | 1116 | return -ENOMEM; | ||
3273 | 1117 | } | ||
3274 | 1118 | |||
3275 | 1119 | msg->size = (uint32_t) r; | ||
3276 | 1120 | |||
3277 | 1121 | return 0; | ||
3278 | 1122 | } | ||
3279 | 1123 | |||
3280 | 1124 | static int _want_registered_device(char *dso_name, char *device_uuid, | ||
3281 | 1125 | struct thread_status *thread) | ||
3282 | 1126 | { | ||
3283 | 1127 | /* If DSO names and device paths are equal. */ | ||
3284 | 1128 | if (dso_name && device_uuid) | ||
3285 | 1129 | return !strcmp(dso_name, thread->dso_data->dso_name) && | ||
3286 | 1130 | !strcmp(device_uuid, thread->device.uuid) && | ||
3287 | 1131 | (thread->status == DM_THREAD_RUNNING || | ||
3288 | 1132 | (thread->events & DM_EVENT_REGISTRATION_PENDING)); | ||
3289 | 1133 | |||
3290 | 1134 | /* If DSO names are equal. */ | ||
3291 | 1135 | if (dso_name) | ||
3292 | 1136 | return !strcmp(dso_name, thread->dso_data->dso_name) && | ||
3293 | 1137 | (thread->status == DM_THREAD_RUNNING || | ||
3294 | 1138 | (thread->events & DM_EVENT_REGISTRATION_PENDING)); | ||
3295 | 1139 | |||
3296 | 1140 | /* If device paths are equal. */ | ||
3297 | 1141 | if (device_uuid) | ||
3298 | 1142 | return !strcmp(device_uuid, thread->device.uuid) && | ||
3299 | 1143 | (thread->status == DM_THREAD_RUNNING || | ||
3300 | 1144 | (thread->events & DM_EVENT_REGISTRATION_PENDING)); | ||
3301 | 1145 | |||
3302 | 1146 | return 1; | ||
3303 | 1147 | } | ||
3304 | 1148 | |||
3305 | 1149 | static int _get_registered_dev(struct message_data *message_data, int next) | ||
3306 | 1150 | { | ||
3307 | 1151 | struct thread_status *thread, *hit = NULL; | ||
3308 | 1152 | int ret = -ENOENT; | ||
3309 | 1153 | |||
3310 | 1154 | _lock_mutex(); | ||
3311 | 1155 | |||
3312 | 1156 | /* Iterate list of threads checking if we want a particular one. */ | ||
3313 | 1157 | dm_list_iterate_items(thread, &_thread_registry) | ||
3314 | 1158 | if (_want_registered_device(message_data->dso_name, | ||
3315 | 1159 | message_data->device_uuid, | ||
3316 | 1160 | thread)) { | ||
3317 | 1161 | hit = thread; | ||
3318 | 1162 | break; | ||
3319 | 1163 | } | ||
3320 | 1164 | |||
3321 | 1165 | /* | ||
3322 | 1166 | * If we got a registered device and want the next one -> | ||
3323 | 1167 | * fetch next conforming element off the list. | ||
3324 | 1168 | */ | ||
3325 | 1169 | if (hit && !next) | ||
3326 | 1170 | goto reg; | ||
3327 | 1171 | |||
3328 | 1172 | if (!hit) | ||
3329 | 1173 | goto out; | ||
3330 | 1174 | |||
3331 | 1175 | while (1) { | ||
3332 | 1176 | if (dm_list_end(&_thread_registry, &thread->list)) | ||
3333 | 1177 | goto out; | ||
3334 | 1178 | |||
3335 | 1179 | thread = dm_list_item(thread->list.n, struct thread_status); | ||
3336 | 1180 | if (_want_registered_device(message_data->dso_name, NULL, thread)) { | ||
3337 | 1181 | hit = thread; | ||
3338 | 1182 | break; | ||
3339 | 1183 | } | ||
3340 | 1184 | } | ||
3341 | 1185 | |||
3342 | 1186 | reg: | ||
3343 | 1187 | ret = _registered_device(message_data, hit); | ||
3344 | 1188 | |||
3345 | 1189 | out: | ||
3346 | 1190 | _unlock_mutex(); | ||
3347 | 1191 | |||
3348 | 1192 | return ret; | ||
3349 | 1193 | } | ||
3350 | 1194 | |||
3351 | 1195 | static int _get_registered_device(struct message_data *message_data) | ||
3352 | 1196 | { | ||
3353 | 1197 | return _get_registered_dev(message_data, 0); | ||
3354 | 1198 | } | ||
3355 | 1199 | |||
3356 | 1200 | static int _get_next_registered_device(struct message_data *message_data) | ||
3357 | 1201 | { | ||
3358 | 1202 | return _get_registered_dev(message_data, 1); | ||
3359 | 1203 | } | ||
3360 | 1204 | |||
3361 | 1205 | static int _set_timeout(struct message_data *message_data) | ||
3362 | 1206 | { | ||
3363 | 1207 | struct thread_status *thread; | ||
3364 | 1208 | |||
3365 | 1209 | _lock_mutex(); | ||
3366 | 1210 | if ((thread = _lookup_thread_status(message_data))) | ||
3367 | 1211 | thread->timeout = message_data->timeout.secs; | ||
3368 | 1212 | _unlock_mutex(); | ||
3369 | 1213 | |||
3370 | 1214 | return thread ? 0 : -ENODEV; | ||
3371 | 1215 | } | ||
3372 | 1216 | |||
3373 | 1217 | static int _get_timeout(struct message_data *message_data) | ||
3374 | 1218 | { | ||
3375 | 1219 | struct thread_status *thread; | ||
3376 | 1220 | struct dm_event_daemon_message *msg = message_data->msg; | ||
3377 | 1221 | |||
3378 | 1222 | dm_free(msg->data); | ||
3379 | 1223 | |||
3380 | 1224 | _lock_mutex(); | ||
3381 | 1225 | if ((thread = _lookup_thread_status(message_data))) { | ||
3382 | 1226 | msg->size = | ||
3383 | 1227 | dm_asprintf(&(msg->data), "%s %" PRIu32, message_data->id, | ||
3384 | 1228 | thread->timeout); | ||
3385 | 1229 | } else { | ||
3386 | 1230 | msg->data = NULL; | ||
3387 | 1231 | msg->size = 0; | ||
3388 | 1232 | } | ||
3389 | 1233 | _unlock_mutex(); | ||
3390 | 1234 | |||
3391 | 1235 | return thread ? 0 : -ENODEV; | ||
3392 | 1236 | } | ||
3393 | 1237 | |||
3394 | 1238 | /* Initialize a fifos structure with path names. */ | ||
3395 | 1239 | static void _init_fifos(struct dm_event_fifos *fifos) | ||
3396 | 1240 | { | ||
3397 | 1241 | memset(fifos, 0, sizeof(*fifos)); | ||
3398 | 1242 | |||
3399 | 1243 | fifos->client_path = DM_EVENT_FIFO_CLIENT; | ||
3400 | 1244 | fifos->server_path = DM_EVENT_FIFO_SERVER; | ||
3401 | 1245 | } | ||
3402 | 1246 | |||
3403 | 1247 | /* Open fifos used for client communication. */ | ||
3404 | 1248 | static int _open_fifos(struct dm_event_fifos *fifos) | ||
3405 | 1249 | { | ||
3406 | 1250 | struct stat st; | ||
3407 | 1251 | |||
3408 | 1252 | /* Create client fifo. */ | ||
3409 | 1253 | (void) dm_prepare_selinux_context(fifos->client_path, S_IFIFO); | ||
3410 | 1254 | if ((mkfifo(fifos->client_path, 0600) == -1) && errno != EEXIST) { | ||
3411 | 1255 | syslog(LOG_ERR, "%s: Failed to create client fifo %s: %m.\n", | ||
3412 | 1256 | __func__, fifos->client_path); | ||
3413 | 1257 | (void) dm_prepare_selinux_context(NULL, 0); | ||
3414 | 1258 | return 0; | ||
3415 | 1259 | } | ||
3416 | 1260 | |||
3417 | 1261 | /* Create server fifo. */ | ||
3418 | 1262 | (void) dm_prepare_selinux_context(fifos->server_path, S_IFIFO); | ||
3419 | 1263 | if ((mkfifo(fifos->server_path, 0600) == -1) && errno != EEXIST) { | ||
3420 | 1264 | syslog(LOG_ERR, "%s: Failed to create server fifo %s: %m.\n", | ||
3421 | 1265 | __func__, fifos->server_path); | ||
3422 | 1266 | (void) dm_prepare_selinux_context(NULL, 0); | ||
3423 | 1267 | return 0; | ||
3424 | 1268 | } | ||
3425 | 1269 | |||
3426 | 1270 | (void) dm_prepare_selinux_context(NULL, 0); | ||
3427 | 1271 | |||
3428 | 1272 | /* Warn about wrong permissions if applicable */ | ||
3429 | 1273 | if ((!stat(fifos->client_path, &st)) && (st.st_mode & 0777) != 0600) | ||
3430 | 1274 | syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", | ||
3431 | 1275 | fifos->client_path); | ||
3432 | 1276 | |||
3433 | 1277 | if ((!stat(fifos->server_path, &st)) && (st.st_mode & 0777) != 0600) | ||
3434 | 1278 | syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", | ||
3435 | 1279 | fifos->server_path); | ||
3436 | 1280 | |||
3437 | 1281 | /* If they were already there, make sure permissions are ok. */ | ||
3438 | 1282 | if (chmod(fifos->client_path, 0600)) { | ||
3439 | 1283 | syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", | ||
3440 | 1284 | fifos->client_path); | ||
3441 | 1285 | return 0; | ||
3442 | 1286 | } | ||
3443 | 1287 | |||
3444 | 1288 | if (chmod(fifos->server_path, 0600)) { | ||
3445 | 1289 | syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", | ||
3446 | 1290 | fifos->server_path); | ||
3447 | 1291 | return 0; | ||
3448 | 1292 | } | ||
3449 | 1293 | |||
3450 | 1294 | /* Need to open read+write or we will block or fail */ | ||
3451 | 1295 | if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) { | ||
3452 | 1296 | syslog(LOG_ERR, "Failed to open fifo server %s: %m.\n", | ||
3453 | 1297 | fifos->server_path); | ||
3454 | 1298 | return 0; | ||
3455 | 1299 | } | ||
3456 | 1300 | |||
3457 | 1301 | /* Need to open read+write for select() to work. */ | ||
3458 | 1302 | if ((fifos->client = open(fifos->client_path, O_RDWR)) < 0) { | ||
3459 | 1303 | syslog(LOG_ERR, "Failed to open fifo client %s: %m", fifos->client_path); | ||
3460 | 1304 | if (close(fifos->server)) | ||
3461 | 1305 | syslog(LOG_ERR, "Failed to close fifo server %s: %m", fifos->server_path); | ||
3462 | 1306 | return 0; | ||
3463 | 1307 | } | ||
3464 | 1308 | |||
3465 | 1309 | return 1; | ||
3466 | 1310 | } | ||
3467 | 1311 | |||
3468 | 1312 | /* | ||
3469 | 1313 | * Read message from client making sure that data is available | ||
3470 | 1314 | * and a complete message is read. Must not block indefinitely. | ||
3471 | 1315 | */ | ||
3472 | 1316 | static int _client_read(struct dm_event_fifos *fifos, | ||
3473 | 1317 | struct dm_event_daemon_message *msg) | ||
3474 | 1318 | { | ||
3475 | 1319 | struct timeval t; | ||
3476 | 1320 | unsigned bytes = 0; | ||
3477 | 1321 | int ret = 0; | ||
3478 | 1322 | fd_set fds; | ||
3479 | 1323 | size_t size = 2 * sizeof(uint32_t); /* status + size */ | ||
3480 | 1324 | uint32_t *header = alloca(size); | ||
3481 | 1325 | char *buf = (char *)header; | ||
3482 | 1326 | |||
3483 | 1327 | msg->data = NULL; | ||
3484 | 1328 | |||
3485 | 1329 | errno = 0; | ||
3486 | 1330 | while (bytes < size && errno != EOF) { | ||
3487 | 1331 | /* Watch client read FIFO for input. */ | ||
3488 | 1332 | FD_ZERO(&fds); | ||
3489 | 1333 | FD_SET(fifos->client, &fds); | ||
3490 | 1334 | t.tv_sec = 1; | ||
3491 | 1335 | t.tv_usec = 0; | ||
3492 | 1336 | ret = select(fifos->client + 1, &fds, NULL, NULL, &t); | ||
3493 | 1337 | |||
3494 | 1338 | if (!ret && !bytes) /* nothing to read */ | ||
3495 | 1339 | return 0; | ||
3496 | 1340 | |||
3497 | 1341 | if (!ret) /* trying to finish read */ | ||
3498 | 1342 | continue; | ||
3499 | 1343 | |||
3500 | 1344 | if (ret < 0) /* error */ | ||
3501 | 1345 | return 0; | ||
3502 | 1346 | |||
3503 | 1347 | ret = read(fifos->client, buf + bytes, size - bytes); | ||
3504 | 1348 | bytes += ret > 0 ? ret : 0; | ||
3505 | 1349 | if (header && (bytes == 2 * sizeof(uint32_t))) { | ||
3506 | 1350 | msg->cmd = ntohl(header[0]); | ||
3507 | 1351 | msg->size = ntohl(header[1]); | ||
3508 | 1352 | buf = msg->data = dm_malloc(msg->size); | ||
3509 | 1353 | size = msg->size; | ||
3510 | 1354 | bytes = 0; | ||
3511 | 1355 | header = 0; | ||
3512 | 1356 | } | ||
3513 | 1357 | } | ||
3514 | 1358 | |||
3515 | 1359 | if (bytes != size) { | ||
3516 | 1360 | dm_free(msg->data); | ||
3517 | 1361 | msg->data = NULL; | ||
3518 | 1362 | msg->size = 0; | ||
3519 | 1363 | } | ||
3520 | 1364 | |||
3521 | 1365 | return bytes == size; | ||
3522 | 1366 | } | ||
3523 | 1367 | |||
3524 | 1368 | /* | ||
3525 | 1369 | * Write a message to the client making sure that it is ready to write. | ||
3526 | 1370 | */ | ||
3527 | 1371 | static int _client_write(struct dm_event_fifos *fifos, | ||
3528 | 1372 | struct dm_event_daemon_message *msg) | ||
3529 | 1373 | { | ||
3530 | 1374 | unsigned bytes = 0; | ||
3531 | 1375 | int ret = 0; | ||
3532 | 1376 | fd_set fds; | ||
3533 | 1377 | |||
3534 | 1378 | size_t size = 2 * sizeof(uint32_t) + msg->size; | ||
3535 | 1379 | uint32_t *header = alloca(size); | ||
3536 | 1380 | char *buf = (char *)header; | ||
3537 | 1381 | |||
3538 | 1382 | header[0] = htonl(msg->cmd); | ||
3539 | 1383 | header[1] = htonl(msg->size); | ||
3540 | 1384 | if (msg->data) | ||
3541 | 1385 | memcpy(buf + 2 * sizeof(uint32_t), msg->data, msg->size); | ||
3542 | 1386 | |||
3543 | 1387 | errno = 0; | ||
3544 | 1388 | while (bytes < size && errno != EIO) { | ||
3545 | 1389 | do { | ||
3546 | 1390 | /* Watch client write FIFO to be ready for output. */ | ||
3547 | 1391 | FD_ZERO(&fds); | ||
3548 | 1392 | FD_SET(fifos->server, &fds); | ||
3549 | 1393 | } while (select(fifos->server + 1, NULL, &fds, NULL, NULL) != | ||
3550 | 1394 | 1); | ||
3551 | 1395 | |||
3552 | 1396 | ret = write(fifos->server, buf + bytes, size - bytes); | ||
3553 | 1397 | bytes += ret > 0 ? ret : 0; | ||
3554 | 1398 | } | ||
3555 | 1399 | |||
3556 | 1400 | return bytes == size; | ||
3557 | 1401 | } | ||
3558 | 1402 | |||
3559 | 1403 | /* | ||
3560 | 1404 | * Handle a client request. | ||
3561 | 1405 | * | ||
3562 | 1406 | * We put the request handling functions into | ||
3563 | 1407 | * a list because of the growing number. | ||
3564 | 1408 | */ | ||
3565 | 1409 | static int _handle_request(struct dm_event_daemon_message *msg, | ||
3566 | 1410 | struct message_data *message_data) | ||
3567 | 1411 | { | ||
3568 | 1412 | static struct request { | ||
3569 | 1413 | unsigned int cmd; | ||
3570 | 1414 | int (*f)(struct message_data *); | ||
3571 | 1415 | } requests[] = { | ||
3572 | 1416 | { DM_EVENT_CMD_REGISTER_FOR_EVENT, _register_for_event}, | ||
3573 | 1417 | { DM_EVENT_CMD_UNREGISTER_FOR_EVENT, _unregister_for_event}, | ||
3574 | 1418 | { DM_EVENT_CMD_GET_REGISTERED_DEVICE, _get_registered_device}, | ||
3575 | 1419 | { DM_EVENT_CMD_GET_NEXT_REGISTERED_DEVICE, | ||
3576 | 1420 | _get_next_registered_device}, | ||
3577 | 1421 | { DM_EVENT_CMD_SET_TIMEOUT, _set_timeout}, | ||
3578 | 1422 | { DM_EVENT_CMD_GET_TIMEOUT, _get_timeout}, | ||
3579 | 1423 | { DM_EVENT_CMD_ACTIVE, _active}, | ||
3580 | 1424 | { DM_EVENT_CMD_GET_STATUS, _get_status}, | ||
3581 | 1425 | }, *req; | ||
3582 | 1426 | |||
3583 | 1427 | for (req = requests; req < requests + sizeof(requests) / sizeof(struct request); req++) | ||
3584 | 1428 | if (req->cmd == msg->cmd) | ||
3585 | 1429 | return req->f(message_data); | ||
3586 | 1430 | |||
3587 | 1431 | return -EINVAL; | ||
3588 | 1432 | } | ||
3589 | 1433 | |||
3590 | 1434 | /* Process a request passed from the communication thread. */ | ||
3591 | 1435 | static int _do_process_request(struct dm_event_daemon_message *msg) | ||
3592 | 1436 | { | ||
3593 | 1437 | int ret; | ||
3594 | 1438 | char *answer; | ||
3595 | 1439 | static struct message_data message_data; | ||
3596 | 1440 | |||
3597 | 1441 | /* Parse the message. */ | ||
3598 | 1442 | memset(&message_data, 0, sizeof(message_data)); | ||
3599 | 1443 | message_data.msg = msg; | ||
3600 | 1444 | if (msg->cmd == DM_EVENT_CMD_HELLO || msg->cmd == DM_EVENT_CMD_DIE) { | ||
3601 | 1445 | ret = 0; | ||
3602 | 1446 | answer = msg->data; | ||
3603 | 1447 | if (answer) { | ||
3604 | 1448 | msg->size = dm_asprintf(&(msg->data), "%s %s %d", answer, | ||
3605 | 1449 | msg->cmd == DM_EVENT_CMD_DIE ? "DYING" : "HELLO", | ||
3606 | 1450 | DM_EVENT_PROTOCOL_VERSION); | ||
3607 | 1451 | dm_free(answer); | ||
3608 | 1452 | } else { | ||
3609 | 1453 | msg->size = 0; | ||
3610 | 1454 | msg->data = NULL; | ||
3611 | 1455 | } | ||
3612 | 1456 | } else if (msg->cmd != DM_EVENT_CMD_ACTIVE && !_parse_message(&message_data)) { | ||
3613 | 1457 | stack; | ||
3614 | 1458 | ret = -EINVAL; | ||
3615 | 1459 | } else | ||
3616 | 1460 | ret = _handle_request(msg, &message_data); | ||
3617 | 1461 | |||
3618 | 1462 | msg->cmd = ret; | ||
3619 | 1463 | if (!msg->data) | ||
3620 | 1464 | msg->size = dm_asprintf(&(msg->data), "%s %s", message_data.id, strerror(-ret)); | ||
3621 | 1465 | |||
3622 | 1466 | _free_message(&message_data); | ||
3623 | 1467 | |||
3624 | 1468 | return ret; | ||
3625 | 1469 | } | ||
3626 | 1470 | |||
3627 | 1471 | /* Only one caller at a time. */ | ||
3628 | 1472 | static void _process_request(struct dm_event_fifos *fifos) | ||
3629 | 1473 | { | ||
3630 | 1474 | int die = 0; | ||
3631 | 1475 | struct dm_event_daemon_message msg; | ||
3632 | 1476 | |||
3633 | 1477 | memset(&msg, 0, sizeof(msg)); | ||
3634 | 1478 | |||
3635 | 1479 | /* | ||
3636 | 1480 | * Read the request from the client (client_read, client_write | ||
3637 | 1481 | * give true on success and false on failure). | ||
3638 | 1482 | */ | ||
3639 | 1483 | if (!_client_read(fifos, &msg)) | ||
3640 | 1484 | return; | ||
3641 | 1485 | |||
3642 | 1486 | if (msg.cmd == DM_EVENT_CMD_DIE) | ||
3643 | 1487 | die = 1; | ||
3644 | 1488 | |||
3645 | 1489 | /* _do_process_request fills in msg (if memory allows for | ||
3646 | 1490 | data, otherwise just cmd and size = 0) */ | ||
3647 | 1491 | _do_process_request(&msg); | ||
3648 | 1492 | |||
3649 | 1493 | if (!_client_write(fifos, &msg)) | ||
3650 | 1494 | stack; | ||
3651 | 1495 | |||
3652 | 1496 | dm_free(msg.data); | ||
3653 | 1497 | |||
3654 | 1498 | if (die) raise(9); | ||
3655 | 1499 | } | ||
3656 | 1500 | |||
3657 | 1501 | static void _process_initial_registrations(void) | ||
3658 | 1502 | { | ||
3659 | 1503 | int i = 0; | ||
3660 | 1504 | char *reg; | ||
3661 | 1505 | struct dm_event_daemon_message msg = { 0, 0, NULL }; | ||
3662 | 1506 | |||
3663 | 1507 | while ((reg = _initial_registrations[i])) { | ||
3664 | 1508 | msg.cmd = DM_EVENT_CMD_REGISTER_FOR_EVENT; | ||
3665 | 1509 | if ((msg.size = strlen(reg))) { | ||
3666 | 1510 | msg.data = reg; | ||
3667 | 1511 | _do_process_request(&msg); | ||
3668 | 1512 | } | ||
3669 | 1513 | ++ i; | ||
3670 | 1514 | } | ||
3671 | 1515 | } | ||
3672 | 1516 | |||
3673 | 1517 | static void _cleanup_unused_threads(void) | ||
3674 | 1518 | { | ||
3675 | 1519 | int ret; | ||
3676 | 1520 | struct dm_list *l; | ||
3677 | 1521 | struct thread_status *thread; | ||
3678 | 1522 | int join_ret = 0; | ||
3679 | 1523 | |||
3680 | 1524 | _lock_mutex(); | ||
3681 | 1525 | while ((l = dm_list_first(&_thread_registry_unused))) { | ||
3682 | 1526 | thread = dm_list_item(l, struct thread_status); | ||
3683 | 1527 | if (thread->processing) | ||
3684 | 1528 | break; /* cleanup on the next round */ | ||
3685 | 1529 | |||
3686 | 1530 | if (thread->status == DM_THREAD_RUNNING) { | ||
3687 | 1531 | thread->status = DM_THREAD_SHUTDOWN; | ||
3688 | 1532 | break; | ||
3689 | 1533 | } | ||
3690 | 1534 | |||
3691 | 1535 | if (thread->status == DM_THREAD_SHUTDOWN) { | ||
3692 | 1536 | if (!thread->events) { | ||
3693 | 1537 | /* turn codes negative -- should we be returning this? */ | ||
3694 | 1538 | ret = _terminate_thread(thread); | ||
3695 | 1539 | |||
3696 | 1540 | if (ret == ESRCH) { | ||
3697 | 1541 | thread->status = DM_THREAD_DONE; | ||
3698 | 1542 | } else if (ret) { | ||
3699 | 1543 | syslog(LOG_ERR, | ||
3700 | 1544 | "Unable to terminate thread: %s\n", | ||
3701 | 1545 | strerror(-ret)); | ||
3702 | 1546 | stack; | ||
3703 | 1547 | } | ||
3704 | 1548 | break; | ||
3705 | 1549 | } | ||
3706 | 1550 | |||
3707 | 1551 | dm_list_del(l); | ||
3708 | 1552 | syslog(LOG_ERR, | ||
3709 | 1553 | "thread can't be on unused list unless !thread->events"); | ||
3710 | 1554 | thread->status = DM_THREAD_RUNNING; | ||
3711 | 1555 | LINK_THREAD(thread); | ||
3712 | 1556 | |||
3713 | 1557 | continue; | ||
3714 | 1558 | } | ||
3715 | 1559 | |||
3716 | 1560 | if (thread->status == DM_THREAD_DONE) { | ||
3717 | 1561 | dm_list_del(l); | ||
3718 | 1562 | join_ret = pthread_join(thread->thread, NULL); | ||
3719 | 1563 | _free_thread_status(thread); | ||
3720 | 1564 | } | ||
3721 | 1565 | } | ||
3722 | 1566 | |||
3723 | 1567 | _unlock_mutex(); | ||
3724 | 1568 | |||
3725 | 1569 | if (join_ret) | ||
3726 | 1570 | syslog(LOG_ERR, "Failed pthread_join: %s\n", strerror(join_ret)); | ||
3727 | 1571 | } | ||
3728 | 1572 | |||
3729 | 1573 | static void _sig_alarm(int signum __attribute__((unused))) | ||
3730 | 1574 | { | ||
3731 | 1575 | pthread_testcancel(); | ||
3732 | 1576 | } | ||
3733 | 1577 | |||
3734 | 1578 | /* Init thread signal handling. */ | ||
3735 | 1579 | static void _init_thread_signals(void) | ||
3736 | 1580 | { | ||
3737 | 1581 | sigset_t my_sigset; | ||
3738 | 1582 | struct sigaction act; | ||
3739 | 1583 | |||
3740 | 1584 | memset(&act, 0, sizeof(act)); | ||
3741 | 1585 | act.sa_handler = _sig_alarm; | ||
3742 | 1586 | sigaction(SIGALRM, &act, NULL); | ||
3743 | 1587 | sigfillset(&my_sigset); | ||
3744 | 1588 | |||
3745 | 1589 | /* These are used for exiting */ | ||
3746 | 1590 | sigdelset(&my_sigset, SIGTERM); | ||
3747 | 1591 | sigdelset(&my_sigset, SIGINT); | ||
3748 | 1592 | sigdelset(&my_sigset, SIGHUP); | ||
3749 | 1593 | sigdelset(&my_sigset, SIGQUIT); | ||
3750 | 1594 | |||
3751 | 1595 | pthread_sigmask(SIG_BLOCK, &my_sigset, NULL); | ||
3752 | 1596 | } | ||
3753 | 1597 | |||
3754 | 1598 | /* | ||
3755 | 1599 | * exit_handler | ||
3756 | 1600 | * @sig | ||
3757 | 1601 | * | ||
3758 | 1602 | * Set the global variable which the process should | ||
3759 | 1603 | * be watching to determine when to exit. | ||
3760 | 1604 | */ | ||
3761 | 1605 | static void _exit_handler(int sig __attribute__((unused))) | ||
3762 | 1606 | { | ||
3763 | 1607 | /* | ||
3764 | 1608 | * We exit when '_exit_now' is set. | ||
3765 | 1609 | * That is, when a signal has been received. | ||
3766 | 1610 | * | ||
3767 | 1611 | * We can not simply set '_exit_now' unless all | ||
3768 | 1612 | * threads are done processing. | ||
3769 | 1613 | */ | ||
3770 | 1614 | if (!_thread_registries_empty) { | ||
3771 | 1615 | syslog(LOG_ERR, "There are still devices being monitored."); | ||
3772 | 1616 | syslog(LOG_ERR, "Refusing to exit."); | ||
3773 | 1617 | } else | ||
3774 | 1618 | _exit_now = 1; | ||
3775 | 1619 | |||
3776 | 1620 | } | ||
3777 | 1621 | |||
3778 | 1622 | #ifdef linux | ||
3779 | 1623 | static int _set_oom_adj(const char *oom_adj_path, int val) | ||
3780 | 1624 | { | ||
3781 | 1625 | FILE *fp; | ||
3782 | 1626 | |||
3783 | 1627 | if (!(fp = fopen(oom_adj_path, "w"))) { | ||
3784 | 1628 | perror("oom_adj: fopen failed"); | ||
3785 | 1629 | return 0; | ||
3786 | 1630 | } | ||
3787 | 1631 | |||
3788 | 1632 | fprintf(fp, "%i", val); | ||
3789 | 1633 | |||
3790 | 1634 | if (dm_fclose(fp)) | ||
3791 | 1635 | perror("oom_adj: fclose failed"); | ||
3792 | 1636 | |||
3793 | 1637 | return 1; | ||
3794 | 1638 | } | ||
3795 | 1639 | |||
3796 | 1640 | /* | ||
3797 | 1641 | * Protection against OOM killer if kernel supports it | ||
3798 | 1642 | */ | ||
3799 | 1643 | static int _protect_against_oom_killer(void) | ||
3800 | 1644 | { | ||
3801 | 1645 | struct stat st; | ||
3802 | 1646 | |||
3803 | 1647 | if (stat(OOM_ADJ_FILE, &st) == -1) { | ||
3804 | 1648 | if (errno != ENOENT) | ||
3805 | 1649 | perror(OOM_ADJ_FILE ": stat failed"); | ||
3806 | 1650 | |||
3807 | 1651 | /* Try old oom_adj interface as a fallback */ | ||
3808 | 1652 | if (stat(OOM_ADJ_FILE_OLD, &st) == -1) { | ||
3809 | 1653 | if (errno == ENOENT) | ||
3810 | 1654 | perror(OOM_ADJ_FILE_OLD " not found"); | ||
3811 | 1655 | else | ||
3812 | 1656 | perror(OOM_ADJ_FILE_OLD ": stat failed"); | ||
3813 | 1657 | return 1; | ||
3814 | 1658 | } | ||
3815 | 1659 | |||
3816 | 1660 | return _set_oom_adj(OOM_ADJ_FILE_OLD, OOM_DISABLE) || | ||
3817 | 1661 | _set_oom_adj(OOM_ADJ_FILE_OLD, OOM_ADJUST_MIN); | ||
3818 | 1662 | } | ||
3819 | 1663 | |||
3820 | 1664 | return _set_oom_adj(OOM_ADJ_FILE, OOM_SCORE_ADJ_MIN); | ||
3821 | 1665 | } | ||
3822 | 1666 | |||
3823 | 1667 | static int _handle_preloaded_fifo(int fd, const char *path) | ||
3824 | 1668 | { | ||
3825 | 1669 | struct stat st_fd, st_path; | ||
3826 | 1670 | int flags; | ||
3827 | 1671 | |||
3828 | 1672 | if ((flags = fcntl(fd, F_GETFD)) < 0) | ||
3829 | 1673 | return 0; | ||
3830 | 1674 | |||
3831 | 1675 | if (flags & FD_CLOEXEC) | ||
3832 | 1676 | return 0; | ||
3833 | 1677 | |||
3834 | 1678 | if (fstat(fd, &st_fd) < 0 || !S_ISFIFO(st_fd.st_mode)) | ||
3835 | 1679 | return 0; | ||
3836 | 1680 | |||
3837 | 1681 | if (stat(path, &st_path) < 0 || | ||
3838 | 1682 | st_path.st_dev != st_fd.st_dev || | ||
3839 | 1683 | st_path.st_ino != st_fd.st_ino) | ||
3840 | 1684 | return 0; | ||
3841 | 1685 | |||
3842 | 1686 | if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) | ||
3843 | 1687 | return 0; | ||
3844 | 1688 | |||
3845 | 1689 | return 1; | ||
3846 | 1690 | } | ||
3847 | 1691 | |||
3848 | 1692 | static int _systemd_handover(struct dm_event_fifos *fifos) | ||
3849 | 1693 | { | ||
3850 | 1694 | const char *e; | ||
3851 | 1695 | char *p; | ||
3852 | 1696 | unsigned long env_pid, env_listen_fds; | ||
3853 | 1697 | int r = 0; | ||
3854 | 1698 | |||
3855 | 1699 | memset(fifos, 0, sizeof(*fifos)); | ||
3856 | 1700 | |||
3857 | 1701 | /* LISTEN_PID must be equal to our PID! */ | ||
3858 | 1702 | if (!(e = getenv(SD_LISTEN_PID_ENV_VAR_NAME))) | ||
3859 | 1703 | goto out; | ||
3860 | 1704 | |||
3861 | 1705 | errno = 0; | ||
3862 | 1706 | env_pid = strtoul(e, &p, 10); | ||
3863 | 1707 | if (errno || !p || *p || env_pid <= 0 || | ||
3864 | 1708 | getpid() != (pid_t) env_pid) | ||
3865 | 1709 | goto out; | ||
3866 | 1710 | |||
3867 | 1711 | /* LISTEN_FDS must be 2 and the fds must be FIFOSs! */ | ||
3868 | 1712 | if (!(e = getenv(SD_LISTEN_FDS_ENV_VAR_NAME))) | ||
3869 | 1713 | goto out; | ||
3870 | 1714 | |||
3871 | 1715 | errno = 0; | ||
3872 | 1716 | env_listen_fds = strtoul(e, &p, 10); | ||
3873 | 1717 | if (errno || !p || *p || env_listen_fds != 2) | ||
3874 | 1718 | goto out; | ||
3875 | 1719 | |||
3876 | 1720 | /* Check and handle the FIFOs passed in */ | ||
3877 | 1721 | r = (_handle_preloaded_fifo(SD_FD_FIFO_SERVER, DM_EVENT_FIFO_SERVER) && | ||
3878 | 1722 | _handle_preloaded_fifo(SD_FD_FIFO_CLIENT, DM_EVENT_FIFO_CLIENT)); | ||
3879 | 1723 | |||
3880 | 1724 | if (r) { | ||
3881 | 1725 | fifos->server = SD_FD_FIFO_SERVER; | ||
3882 | 1726 | fifos->server_path = DM_EVENT_FIFO_SERVER; | ||
3883 | 1727 | fifos->client = SD_FD_FIFO_CLIENT; | ||
3884 | 1728 | fifos->client_path = DM_EVENT_FIFO_CLIENT; | ||
3885 | 1729 | } | ||
3886 | 1730 | |||
3887 | 1731 | out: | ||
3888 | 1732 | unsetenv(SD_LISTEN_PID_ENV_VAR_NAME); | ||
3889 | 1733 | unsetenv(SD_LISTEN_FDS_ENV_VAR_NAME); | ||
3890 | 1734 | return r; | ||
3891 | 1735 | } | ||
3892 | 1736 | #endif | ||
3893 | 1737 | |||
3894 | 1738 | static void remove_lockfile(void) | ||
3895 | 1739 | { | ||
3896 | 1740 | if (unlink(DMEVENTD_PIDFILE)) | ||
3897 | 1741 | perror(DMEVENTD_PIDFILE ": unlink failed"); | ||
3898 | 1742 | } | ||
3899 | 1743 | |||
3900 | 1744 | static void _daemonize(void) | ||
3901 | 1745 | { | ||
3902 | 1746 | int child_status; | ||
3903 | 1747 | int fd; | ||
3904 | 1748 | pid_t pid; | ||
3905 | 1749 | struct rlimit rlim; | ||
3906 | 1750 | struct timeval tval; | ||
3907 | 1751 | sigset_t my_sigset; | ||
3908 | 1752 | |||
3909 | 1753 | sigemptyset(&my_sigset); | ||
3910 | 1754 | if (sigprocmask(SIG_SETMASK, &my_sigset, NULL) < 0) { | ||
3911 | 1755 | fprintf(stderr, "Unable to restore signals.\n"); | ||
3912 | 1756 | exit(EXIT_FAILURE); | ||
3913 | 1757 | } | ||
3914 | 1758 | signal(SIGTERM, &_exit_handler); | ||
3915 | 1759 | |||
3916 | 1760 | switch (pid = fork()) { | ||
3917 | 1761 | case -1: | ||
3918 | 1762 | perror("fork failed:"); | ||
3919 | 1763 | exit(EXIT_FAILURE); | ||
3920 | 1764 | |||
3921 | 1765 | case 0: /* Child */ | ||
3922 | 1766 | break; | ||
3923 | 1767 | |||
3924 | 1768 | default: | ||
3925 | 1769 | /* Wait for response from child */ | ||
3926 | 1770 | while (!waitpid(pid, &child_status, WNOHANG) && !_exit_now) { | ||
3927 | 1771 | tval.tv_sec = 0; | ||
3928 | 1772 | tval.tv_usec = 250000; /* .25 sec */ | ||
3929 | 1773 | select(0, NULL, NULL, NULL, &tval); | ||
3930 | 1774 | } | ||
3931 | 1775 | |||
3932 | 1776 | if (_exit_now) /* Child has signaled it is ok - we can exit now */ | ||
3933 | 1777 | exit(EXIT_SUCCESS); | ||
3934 | 1778 | |||
3935 | 1779 | /* Problem with child. Determine what it is by exit code */ | ||
3936 | 1780 | switch (WEXITSTATUS(child_status)) { | ||
3937 | 1781 | case EXIT_DESC_CLOSE_FAILURE: | ||
3938 | 1782 | case EXIT_DESC_OPEN_FAILURE: | ||
3939 | 1783 | case EXIT_FIFO_FAILURE: | ||
3940 | 1784 | case EXIT_CHDIR_FAILURE: | ||
3941 | 1785 | default: | ||
3942 | 1786 | fprintf(stderr, "Child exited with code %d\n", WEXITSTATUS(child_status)); | ||
3943 | 1787 | break; | ||
3944 | 1788 | } | ||
3945 | 1789 | |||
3946 | 1790 | exit(WEXITSTATUS(child_status)); | ||
3947 | 1791 | } | ||
3948 | 1792 | |||
3949 | 1793 | if (chdir("/")) | ||
3950 | 1794 | exit(EXIT_CHDIR_FAILURE); | ||
3951 | 1795 | |||
3952 | 1796 | if (getrlimit(RLIMIT_NOFILE, &rlim) < 0) | ||
3953 | 1797 | fd = 256; /* just have to guess */ | ||
3954 | 1798 | else | ||
3955 | 1799 | fd = rlim.rlim_cur; | ||
3956 | 1800 | |||
3957 | 1801 | for (--fd; fd >= 0; fd--) { | ||
3958 | 1802 | #ifdef linux | ||
3959 | 1803 | /* Do not close fds preloaded by systemd! */ | ||
3960 | 1804 | if (_systemd_activation && | ||
3961 | 1805 | (fd == SD_FD_FIFO_SERVER || fd == SD_FD_FIFO_CLIENT)) | ||
3962 | 1806 | continue; | ||
3963 | 1807 | #endif | ||
3964 | 1808 | (void) close(fd); | ||
3965 | 1809 | } | ||
3966 | 1810 | |||
3967 | 1811 | if ((open("/dev/null", O_RDONLY) < 0) || | ||
3968 | 1812 | (open("/dev/null", O_WRONLY) < 0) || | ||
3969 | 1813 | (open("/dev/null", O_WRONLY) < 0)) | ||
3970 | 1814 | exit(EXIT_DESC_OPEN_FAILURE); | ||
3971 | 1815 | |||
3972 | 1816 | setsid(); | ||
3973 | 1817 | } | ||
3974 | 1818 | |||
3975 | 1819 | static void restart(void) | ||
3976 | 1820 | { | ||
3977 | 1821 | struct dm_event_fifos fifos; | ||
3978 | 1822 | struct dm_event_daemon_message msg = { 0, 0, NULL }; | ||
3979 | 1823 | int i, count = 0; | ||
3980 | 1824 | char *message; | ||
3981 | 1825 | int length; | ||
3982 | 1826 | int version; | ||
3983 | 1827 | |||
3984 | 1828 | /* Get the list of registrations from the running daemon. */ | ||
3985 | 1829 | |||
3986 | 1830 | if (!init_fifos(&fifos)) { | ||
3987 | 1831 | fprintf(stderr, "WARNING: Could not initiate communication with existing dmeventd.\n"); | ||
3988 | 1832 | return; | ||
3989 | 1833 | } | ||
3990 | 1834 | |||
3991 | 1835 | if (!dm_event_get_version(&fifos, &version)) { | ||
3992 | 1836 | fprintf(stderr, "WARNING: Could not communicate with existing dmeventd.\n"); | ||
3993 | 1837 | fini_fifos(&fifos); | ||
3994 | 1838 | return; | ||
3995 | 1839 | } | ||
3996 | 1840 | |||
3997 | 1841 | if (version < 1) { | ||
3998 | 1842 | fprintf(stderr, "WARNING: The running dmeventd instance is too old.\n" | ||
3999 | 1843 | "Protocol version %d (required: 1). Action cancelled.\n", | ||
4000 | 1844 | version); | ||
4001 | 1845 | exit(EXIT_FAILURE); | ||
4002 | 1846 | } | ||
4003 | 1847 | |||
4004 | 1848 | if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) { | ||
4005 | 1849 | exit(EXIT_FAILURE); | ||
4006 | 1850 | } | ||
4007 | 1851 | |||
4008 | 1852 | message = msg.data; | ||
4009 | 1853 | message = strchr(message, ' '); | ||
4010 | 1854 | ++ message; | ||
4011 | 1855 | length = strlen(msg.data); | ||
4012 | 1856 | for (i = 0; i < length; ++i) { | ||
4013 | 1857 | if (msg.data[i] == ';') { | ||
4014 | 1858 | msg.data[i] = 0; | ||
4015 | 1859 | ++count; | ||
4016 | 1860 | } | ||
4017 | 1861 | } | ||
4018 | 1862 | |||
4019 | 1863 | if (!(_initial_registrations = dm_malloc(sizeof(char*) * (count + 1)))) { | ||
4020 | 1864 | fprintf(stderr, "Memory allocation registration failed.\n"); | ||
4021 | 1865 | exit(EXIT_FAILURE); | ||
4022 | 1866 | } | ||
4023 | 1867 | |||
4024 | 1868 | for (i = 0; i < count; ++i) { | ||
4025 | 1869 | if (!(_initial_registrations[i] = dm_strdup(message))) { | ||
4026 | 1870 | fprintf(stderr, "Memory allocation for message failed.\n"); | ||
4027 | 1871 | exit(EXIT_FAILURE); | ||
4028 | 1872 | } | ||
4029 | 1873 | message += strlen(message) + 1; | ||
4030 | 1874 | } | ||
4031 | 1875 | _initial_registrations[count] = 0; | ||
4032 | 1876 | |||
4033 | 1877 | if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_DIE, "-", "-", 0, 0)) { | ||
4034 | 1878 | fprintf(stderr, "Old dmeventd refused to die.\n"); | ||
4035 | 1879 | exit(EXIT_FAILURE); | ||
4036 | 1880 | } | ||
4037 | 1881 | |||
4038 | 1882 | fini_fifos(&fifos); | ||
4039 | 1883 | } | ||
4040 | 1884 | |||
4041 | 1885 | static void usage(char *prog, FILE *file) | ||
4042 | 1886 | { | ||
4043 | 1887 | fprintf(file, "Usage:\n" | ||
4044 | 1888 | "%s [-d [-d [-d]]] [-f] [-h] [-R] [-V] [-?]\n\n" | ||
4045 | 1889 | " -d Log debug messages to syslog (-d, -dd, -ddd)\n" | ||
4046 | 1890 | " -f Don't fork, run in the foreground\n" | ||
4047 | 1891 | " -h -? Show this help information\n" | ||
4048 | 1892 | " -R Restart dmeventd\n" | ||
4049 | 1893 | " -V Show version of dmeventd\n\n", prog); | ||
4050 | 1894 | } | ||
4051 | 1895 | |||
4052 | 1896 | int main(int argc, char *argv[]) | ||
4053 | 1897 | { | ||
4054 | 1898 | signed char opt; | ||
4055 | 1899 | struct dm_event_fifos fifos; | ||
4056 | 1900 | //struct sys_log logdata = {DAEMON_NAME, LOG_DAEMON}; | ||
4057 | 1901 | |||
4058 | 1902 | opterr = 0; | ||
4059 | 1903 | optind = 0; | ||
4060 | 1904 | |||
4061 | 1905 | while ((opt = getopt(argc, argv, "?fhVdR")) != EOF) { | ||
4062 | 1906 | switch (opt) { | ||
4063 | 1907 | case 'h': | ||
4064 | 1908 | usage(argv[0], stdout); | ||
4065 | 1909 | exit(0); | ||
4066 | 1910 | case '?': | ||
4067 | 1911 | usage(argv[0], stderr); | ||
4068 | 1912 | exit(0); | ||
4069 | 1913 | case 'R': | ||
4070 | 1914 | _restart++; | ||
4071 | 1915 | break; | ||
4072 | 1916 | case 'f': | ||
4073 | 1917 | _foreground++; | ||
4074 | 1918 | break; | ||
4075 | 1919 | case 'd': | ||
4076 | 1920 | dmeventd_debug++; | ||
4077 | 1921 | break; | ||
4078 | 1922 | case 'V': | ||
4079 | 1923 | printf("dmeventd version: %s\n", DM_LIB_VERSION); | ||
4080 | 1924 | exit(1); | ||
4081 | 1925 | } | ||
4082 | 1926 | } | ||
4083 | 1927 | |||
4084 | 1928 | /* | ||
4085 | 1929 | * Switch to C locale to avoid reading large locale-archive file | ||
4086 | 1930 | * used by some glibc (on some distributions it takes over 100MB). | ||
4087 | 1931 | * Daemon currently needs to use mlockall(). | ||
4088 | 1932 | */ | ||
4089 | 1933 | if (setenv("LANG", "C", 1)) | ||
4090 | 1934 | perror("Cannot set LANG to C"); | ||
4091 | 1935 | |||
4092 | 1936 | if (_restart) | ||
4093 | 1937 | restart(); | ||
4094 | 1938 | |||
4095 | 1939 | #ifdef linux | ||
4096 | 1940 | _systemd_activation = _systemd_handover(&fifos); | ||
4097 | 1941 | #endif | ||
4098 | 1942 | |||
4099 | 1943 | if (!_foreground) | ||
4100 | 1944 | _daemonize(); | ||
4101 | 1945 | |||
4102 | 1946 | openlog("dmeventd", LOG_PID, LOG_DAEMON); | ||
4103 | 1947 | |||
4104 | 1948 | (void) dm_prepare_selinux_context(DMEVENTD_PIDFILE, S_IFREG); | ||
4105 | 1949 | if (dm_create_lockfile(DMEVENTD_PIDFILE) == 0) | ||
4106 | 1950 | exit(EXIT_FAILURE); | ||
4107 | 1951 | |||
4108 | 1952 | atexit(remove_lockfile); | ||
4109 | 1953 | (void) dm_prepare_selinux_context(NULL, 0); | ||
4110 | 1954 | |||
4111 | 1955 | /* Set the rest of the signals to cause '_exit_now' to be set */ | ||
4112 | 1956 | signal(SIGINT, &_exit_handler); | ||
4113 | 1957 | signal(SIGHUP, &_exit_handler); | ||
4114 | 1958 | signal(SIGQUIT, &_exit_handler); | ||
4115 | 1959 | |||
4116 | 1960 | #ifdef linux | ||
4117 | 1961 | /* Systemd has adjusted oom killer for us already */ | ||
4118 | 1962 | if (!_systemd_activation && !_protect_against_oom_killer()) | ||
4119 | 1963 | syslog(LOG_ERR, "Failed to protect against OOM killer"); | ||
4120 | 1964 | #endif | ||
4121 | 1965 | |||
4122 | 1966 | _init_thread_signals(); | ||
4123 | 1967 | |||
4124 | 1968 | //multilog_clear_logging(); | ||
4125 | 1969 | //multilog_add_type(std_syslog, &logdata); | ||
4126 | 1970 | //multilog_init_verbose(std_syslog, _LOG_DEBUG); | ||
4127 | 1971 | //multilog_async(1); | ||
4128 | 1972 | |||
4129 | 1973 | if (!_systemd_activation) | ||
4130 | 1974 | _init_fifos(&fifos); | ||
4131 | 1975 | |||
4132 | 1976 | pthread_mutex_init(&_global_mutex, NULL); | ||
4133 | 1977 | |||
4134 | 1978 | if (!_systemd_activation && !_open_fifos(&fifos)) | ||
4135 | 1979 | exit(EXIT_FIFO_FAILURE); | ||
4136 | 1980 | |||
4137 | 1981 | /* Signal parent, letting them know we are ready to go. */ | ||
4138 | 1982 | if (!_foreground) | ||
4139 | 1983 | kill(getppid(), SIGTERM); | ||
4140 | 1984 | syslog(LOG_NOTICE, "dmeventd ready for processing."); | ||
4141 | 1985 | |||
4142 | 1986 | if (_initial_registrations) | ||
4143 | 1987 | _process_initial_registrations(); | ||
4144 | 1988 | |||
4145 | 1989 | while (!_exit_now) { | ||
4146 | 1990 | _process_request(&fifos); | ||
4147 | 1991 | _cleanup_unused_threads(); | ||
4148 | 1992 | _lock_mutex(); | ||
4149 | 1993 | if (!dm_list_empty(&_thread_registry) | ||
4150 | 1994 | || !dm_list_empty(&_thread_registry_unused)) | ||
4151 | 1995 | _thread_registries_empty = 0; | ||
4152 | 1996 | else | ||
4153 | 1997 | _thread_registries_empty = 1; | ||
4154 | 1998 | _unlock_mutex(); | ||
4155 | 1999 | } | ||
4156 | 2000 | |||
4157 | 2001 | _exit_dm_lib(); | ||
4158 | 2002 | |||
4159 | 2003 | pthread_mutex_destroy(&_global_mutex); | ||
4160 | 2004 | |||
4161 | 2005 | syslog(LOG_NOTICE, "dmeventd shutting down."); | ||
4162 | 2006 | closelog(); | ||
4163 | 2007 | |||
4164 | 2008 | exit(EXIT_SUCCESS); | ||
4165 | 2009 | } | ||
4166 | 0 | 2010 | ||
4167 | === added directory '.pc/dirs.patch/doc' | |||
4168 | === removed directory '.pc/dirs.patch/doc' | |||
4169 | === added file '.pc/dirs.patch/doc/example.conf.in' | |||
4170 | --- .pc/dirs.patch/doc/example.conf.in 1970-01-01 00:00:00 +0000 | |||
4171 | +++ .pc/dirs.patch/doc/example.conf.in 2012-08-21 10:18:22 +0000 | |||
4172 | @@ -0,0 +1,773 @@ | |||
4173 | 1 | # This is an example configuration file for the LVM2 system. | ||
4174 | 2 | # It contains the default settings that would be used if there was no | ||
4175 | 3 | # @DEFAULT_SYS_DIR@/lvm.conf file. | ||
4176 | 4 | # | ||
4177 | 5 | # Refer to 'man lvm.conf' for further information including the file layout. | ||
4178 | 6 | # | ||
4179 | 7 | # To put this file in a different directory and override @DEFAULT_SYS_DIR@ set | ||
4180 | 8 | # the environment variable LVM_SYSTEM_DIR before running the tools. | ||
4181 | 9 | # | ||
4182 | 10 | # N.B. Take care that each setting only appears once if uncommenting | ||
4183 | 11 | # example settings in this file. | ||
4184 | 12 | |||
4185 | 13 | |||
4186 | 14 | # This section allows you to configure which block devices should | ||
4187 | 15 | # be used by the LVM system. | ||
4188 | 16 | devices { | ||
4189 | 17 | |||
4190 | 18 | # Where do you want your volume groups to appear ? | ||
4191 | 19 | dir = "/dev" | ||
4192 | 20 | |||
4193 | 21 | # An array of directories that contain the device nodes you wish | ||
4194 | 22 | # to use with LVM2. | ||
4195 | 23 | scan = [ "/dev" ] | ||
4196 | 24 | |||
4197 | 25 | # If set, the cache of block device nodes with all associated symlinks | ||
4198 | 26 | # will be constructed out of the existing udev database content. | ||
4199 | 27 | # This avoids using and opening any inapplicable non-block devices or | ||
4200 | 28 | # subdirectories found in the device directory. This setting is applied | ||
4201 | 29 | # to udev-managed device directory only, other directories will be scanned | ||
4202 | 30 | # fully. LVM2 needs to be compiled with udev support for this setting to | ||
4203 | 31 | # take effect. N.B. Any device node or symlink not managed by udev in | ||
4204 | 32 | # udev directory will be ignored with this setting on. | ||
4205 | 33 | obtain_device_list_from_udev = 1 | ||
4206 | 34 | |||
4207 | 35 | # If several entries in the scanned directories correspond to the | ||
4208 | 36 | # same block device and the tools need to display a name for device, | ||
4209 | 37 | # all the pathnames are matched against each item in the following | ||
4210 | 38 | # list of regular expressions in turn and the first match is used. | ||
4211 | 39 | preferred_names = [ ] | ||
4212 | 40 | |||
4213 | 41 | # Try to avoid using undescriptive /dev/dm-N names, if present. | ||
4214 | 42 | # preferred_names = [ "^/dev/mpath/", "^/dev/mapper/mpath", "^/dev/[hs]d" ] | ||
4215 | 43 | |||
4216 | 44 | # A filter that tells LVM2 to only use a restricted set of devices. | ||
4217 | 45 | # The filter consists of an array of regular expressions. These | ||
4218 | 46 | # expressions can be delimited by a character of your choice, and | ||
4219 | 47 | # prefixed with either an 'a' (for accept) or 'r' (for reject). | ||
4220 | 48 | # The first expression found to match a device name determines if | ||
4221 | 49 | # the device will be accepted or rejected (ignored). Devices that | ||
4222 | 50 | # don't match any patterns are accepted. | ||
4223 | 51 | |||
4224 | 52 | # Be careful if there there are symbolic links or multiple filesystem | ||
4225 | 53 | # entries for the same device as each name is checked separately against | ||
4226 | 54 | # the list of patterns. The effect is that if the first pattern in the | ||
4227 | 55 | # list to match a name is an 'a' pattern for any of the names, the device | ||
4228 | 56 | # is accepted; otherwise if the first pattern in the list to match a name | ||
4229 | 57 | # is an 'r' pattern for any of the names it is rejected; otherwise it is | ||
4230 | 58 | # accepted. | ||
4231 | 59 | |||
4232 | 60 | # Don't have more than one filter line active at once: only one gets used. | ||
4233 | 61 | |||
4234 | 62 | # Run vgscan after you change this parameter to ensure that | ||
4235 | 63 | # the cache file gets regenerated (see below). | ||
4236 | 64 | # If it doesn't do what you expect, check the output of 'vgscan -vvvv'. | ||
4237 | 65 | |||
4238 | 66 | |||
4239 | 67 | # By default we accept every block device: | ||
4240 | 68 | filter = [ "a/.*/" ] | ||
4241 | 69 | |||
4242 | 70 | # Exclude the cdrom drive | ||
4243 | 71 | # filter = [ "r|/dev/cdrom|" ] | ||
4244 | 72 | |||
4245 | 73 | # When testing I like to work with just loopback devices: | ||
4246 | 74 | # filter = [ "a/loop/", "r/.*/" ] | ||
4247 | 75 | |||
4248 | 76 | # Or maybe all loops and ide drives except hdc: | ||
4249 | 77 | # filter =[ "a|loop|", "r|/dev/hdc|", "a|/dev/ide|", "r|.*|" ] | ||
4250 | 78 | |||
4251 | 79 | # Use anchors if you want to be really specific | ||
4252 | 80 | # filter = [ "a|^/dev/hda8$|", "r/.*/" ] | ||
4253 | 81 | |||
4254 | 82 | # The results of the filtering are cached on disk to avoid | ||
4255 | 83 | # rescanning dud devices (which can take a very long time). | ||
4256 | 84 | # By default this cache is stored in the @DEFAULT_SYS_DIR@/@DEFAULT_CACHE_SUBDIR@ directory | ||
4257 | 85 | # in a file called '.cache'. | ||
4258 | 86 | # It is safe to delete the contents: the tools regenerate it. | ||
4259 | 87 | # (The old setting 'cache' is still respected if neither of | ||
4260 | 88 | # these new ones is present.) | ||
4261 | 89 | cache_dir = "@DEFAULT_SYS_DIR@/@DEFAULT_CACHE_SUBDIR@" | ||
4262 | 90 | cache_file_prefix = "" | ||
4263 | 91 | |||
4264 | 92 | # You can turn off writing this cache file by setting this to 0. | ||
4265 | 93 | write_cache_state = 1 | ||
4266 | 94 | |||
4267 | 95 | # Advanced settings. | ||
4268 | 96 | |||
4269 | 97 | # List of pairs of additional acceptable block device types found | ||
4270 | 98 | # in /proc/devices with maximum (non-zero) number of partitions. | ||
4271 | 99 | # types = [ "fd", 16 ] | ||
4272 | 100 | |||
4273 | 101 | # If sysfs is mounted (2.6 kernels) restrict device scanning to | ||
4274 | 102 | # the block devices it believes are valid. | ||
4275 | 103 | # 1 enables; 0 disables. | ||
4276 | 104 | sysfs_scan = 1 | ||
4277 | 105 | |||
4278 | 106 | # By default, LVM2 will ignore devices used as component paths | ||
4279 | 107 | # of device-mapper multipath devices. | ||
4280 | 108 | # 1 enables; 0 disables. | ||
4281 | 109 | multipath_component_detection = 1 | ||
4282 | 110 | |||
4283 | 111 | # By default, LVM2 will ignore devices used as components of | ||
4284 | 112 | # software RAID (md) devices by looking for md superblocks. | ||
4285 | 113 | # 1 enables; 0 disables. | ||
4286 | 114 | md_component_detection = 1 | ||
4287 | 115 | |||
4288 | 116 | # By default, if a PV is placed directly upon an md device, LVM2 | ||
4289 | 117 | # will align its data blocks with the md device's stripe-width. | ||
4290 | 118 | # 1 enables; 0 disables. | ||
4291 | 119 | md_chunk_alignment = 1 | ||
4292 | 120 | |||
4293 | 121 | # Default alignment of the start of a data area in MB. If set to 0, | ||
4294 | 122 | # a value of 64KB will be used. Set to 1 for 1MiB, 2 for 2MiB, etc. | ||
4295 | 123 | # default_data_alignment = @DEFAULT_DATA_ALIGNMENT@ | ||
4296 | 124 | |||
4297 | 125 | # By default, the start of a PV's data area will be a multiple of | ||
4298 | 126 | # the 'minimum_io_size' or 'optimal_io_size' exposed in sysfs. | ||
4299 | 127 | # - minimum_io_size - the smallest request the device can perform | ||
4300 | 128 | # w/o incurring a read-modify-write penalty (e.g. MD's chunk size) | ||
4301 | 129 | # - optimal_io_size - the device's preferred unit of receiving I/O | ||
4302 | 130 | # (e.g. MD's stripe width) | ||
4303 | 131 | # minimum_io_size is used if optimal_io_size is undefined (0). | ||
4304 | 132 | # If md_chunk_alignment is enabled, that detects the optimal_io_size. | ||
4305 | 133 | # This setting takes precedence over md_chunk_alignment. | ||
4306 | 134 | # 1 enables; 0 disables. | ||
4307 | 135 | data_alignment_detection = 1 | ||
4308 | 136 | |||
4309 | 137 | # Alignment (in KB) of start of data area when creating a new PV. | ||
4310 | 138 | # md_chunk_alignment and data_alignment_detection are disabled if set. | ||
4311 | 139 | # Set to 0 for the default alignment (see: data_alignment_default) | ||
4312 | 140 | # or page size, if larger. | ||
4313 | 141 | data_alignment = 0 | ||
4314 | 142 | |||
4315 | 143 | # By default, the start of the PV's aligned data area will be shifted by | ||
4316 | 144 | # the 'alignment_offset' exposed in sysfs. This offset is often 0 but | ||
4317 | 145 | # may be non-zero; e.g.: certain 4KB sector drives that compensate for | ||
4318 | 146 | # windows partitioning will have an alignment_offset of 3584 bytes | ||
4319 | 147 | # (sector 7 is the lowest aligned logical block, the 4KB sectors start | ||
4320 | 148 | # at LBA -1, and consequently sector 63 is aligned on a 4KB boundary). | ||
4321 | 149 | # But note that pvcreate --dataalignmentoffset will skip this detection. | ||
4322 | 150 | # 1 enables; 0 disables. | ||
4323 | 151 | data_alignment_offset_detection = 1 | ||
4324 | 152 | |||
4325 | 153 | # If, while scanning the system for PVs, LVM2 encounters a device-mapper | ||
4326 | 154 | # device that has its I/O suspended, it waits for it to become accessible. | ||
4327 | 155 | # Set this to 1 to skip such devices. This should only be needed | ||
4328 | 156 | # in recovery situations. | ||
4329 | 157 | ignore_suspended_devices = 0 | ||
4330 | 158 | |||
4331 | 159 | # During each LVM operation errors received from each device are counted. | ||
4332 | 160 | # If the counter of a particular device exceeds the limit set here, no | ||
4333 | 161 | # further I/O is sent to that device for the remainder of the respective | ||
4334 | 162 | # operation. Setting the parameter to 0 disables the counters altogether. | ||
4335 | 163 | disable_after_error_count = 0 | ||
4336 | 164 | |||
4337 | 165 | # Allow use of pvcreate --uuid without requiring --restorefile. | ||
4338 | 166 | require_restorefile_with_uuid = 1 | ||
4339 | 167 | |||
4340 | 168 | # Minimum size (in KB) of block devices which can be used as PVs. | ||
4341 | 169 | # In a clustered environment all nodes must use the same value. | ||
4342 | 170 | # Any value smaller than 512KB is ignored. | ||
4343 | 171 | |||
4344 | 172 | # Ignore devices smaller than 2MB such as floppy drives. | ||
4345 | 173 | pv_min_size = 2048 | ||
4346 | 174 | |||
4347 | 175 | # The original built-in setting was 512 up to and including version 2.02.84. | ||
4348 | 176 | # pv_min_size = 512 | ||
4349 | 177 | |||
4350 | 178 | # Issue discards to a logical volumes's underlying physical volume(s) when | ||
4351 | 179 | # the logical volume is no longer using the physical volumes' space (e.g. | ||
4352 | 180 | # lvremove, lvreduce, etc). Discards inform the storage that a region is | ||
4353 | 181 | # no longer in use. Storage that supports discards advertise the protocol | ||
4354 | 182 | # specific way discards should be issued by the kernel (TRIM, UNMAP, or | ||
4355 | 183 | # WRITE SAME with UNMAP bit set). Not all storage will support or benefit | ||
4356 | 184 | # from discards but SSDs and thinly provisioned LUNs generally do. If set | ||
4357 | 185 | # to 1, discards will only be issued if both the storage and kernel provide | ||
4358 | 186 | # support. | ||
4359 | 187 | # 1 enables; 0 disables. | ||
4360 | 188 | issue_discards = 0 | ||
4361 | 189 | } | ||
4362 | 190 | |||
4363 | 191 | # This section allows you to configure the way in which LVM selects | ||
4364 | 192 | # free space for its Logical Volumes. | ||
4365 | 193 | #allocation { | ||
4366 | 194 | # When searching for free space to extend an LV, the "cling" | ||
4367 | 195 | # allocation policy will choose space on the same PVs as the last | ||
4368 | 196 | # segment of the existing LV. If there is insufficient space and a | ||
4369 | 197 | # list of tags is defined here, it will check whether any of them are | ||
4370 | 198 | # attached to the PVs concerned and then seek to match those PV tags | ||
4371 | 199 | # between existing extents and new extents. | ||
4372 | 200 | # Use the special tag "@*" as a wildcard to match any PV tag. | ||
4373 | 201 | # | ||
4374 | 202 | # Example: LVs are mirrored between two sites within a single VG. | ||
4375 | 203 | # PVs are tagged with either @site1 or @site2 to indicate where | ||
4376 | 204 | # they are situated. | ||
4377 | 205 | # | ||
4378 | 206 | # cling_tag_list = [ "@site1", "@site2" ] | ||
4379 | 207 | # cling_tag_list = [ "@*" ] | ||
4380 | 208 | # | ||
4381 | 209 | # Changes made in version 2.02.85 extended the reach of the 'cling' | ||
4382 | 210 | # policies to detect more situations where data can be grouped | ||
4383 | 211 | # onto the same disks. Set this to 0 to revert to the previous | ||
4384 | 212 | # algorithm. | ||
4385 | 213 | # | ||
4386 | 214 | # maximise_cling = 1 | ||
4387 | 215 | # | ||
4388 | 216 | # Set to 1 to guarantee that mirror logs will always be placed on | ||
4389 | 217 | # different PVs from the mirror images. This was the default | ||
4390 | 218 | # until version 2.02.85. | ||
4391 | 219 | # | ||
4392 | 220 | # mirror_logs_require_separate_pvs = 0 | ||
4393 | 221 | # | ||
4394 | 222 | # Set to 1 to guarantee that thin pool metadata will always | ||
4395 | 223 | # be placed on different PVs from the pool data. | ||
4396 | 224 | # | ||
4397 | 225 | # thin_pool_metadata_require_separate_pvs = 0 | ||
4398 | 226 | #} | ||
4399 | 227 | |||
4400 | 228 | # This section that allows you to configure the nature of the | ||
4401 | 229 | # information that LVM2 reports. | ||
4402 | 230 | log { | ||
4403 | 231 | |||
4404 | 232 | # Controls the messages sent to stdout or stderr. | ||
4405 | 233 | # There are three levels of verbosity, 3 being the most verbose. | ||
4406 | 234 | verbose = 0 | ||
4407 | 235 | |||
4408 | 236 | # Should we send log messages through syslog? | ||
4409 | 237 | # 1 is yes; 0 is no. | ||
4410 | 238 | syslog = 1 | ||
4411 | 239 | |||
4412 | 240 | # Should we log error and debug messages to a file? | ||
4413 | 241 | # By default there is no log file. | ||
4414 | 242 | #file = "/var/log/lvm2.log" | ||
4415 | 243 | |||
4416 | 244 | # Should we overwrite the log file each time the program is run? | ||
4417 | 245 | # By default we append. | ||
4418 | 246 | overwrite = 0 | ||
4419 | 247 | |||
4420 | 248 | # What level of log messages should we send to the log file and/or syslog? | ||
4421 | 249 | # There are 6 syslog-like log levels currently in use - 2 to 7 inclusive. | ||
4422 | 250 | # 7 is the most verbose (LOG_DEBUG). | ||
4423 | 251 | level = 0 | ||
4424 | 252 | |||
4425 | 253 | # Format of output messages | ||
4426 | 254 | # Whether or not (1 or 0) to indent messages according to their severity | ||
4427 | 255 | indent = 1 | ||
4428 | 256 | |||
4429 | 257 | # Whether or not (1 or 0) to display the command name on each line output | ||
4430 | 258 | command_names = 0 | ||
4431 | 259 | |||
4432 | 260 | # A prefix to use before the message text (but after the command name, | ||
4433 | 261 | # if selected). Default is two spaces, so you can see/grep the severity | ||
4434 | 262 | # of each message. | ||
4435 | 263 | prefix = " " | ||
4436 | 264 | |||
4437 | 265 | # To make the messages look similar to the original LVM tools use: | ||
4438 | 266 | # indent = 0 | ||
4439 | 267 | # command_names = 1 | ||
4440 | 268 | # prefix = " -- " | ||
4441 | 269 | |||
4442 | 270 | # Set this if you want log messages during activation. | ||
4443 | 271 | # Don't use this in low memory situations (can deadlock). | ||
4444 | 272 | # activation = 0 | ||
4445 | 273 | } | ||
4446 | 274 | |||
4447 | 275 | # Configuration of metadata backups and archiving. In LVM2 when we | ||
4448 | 276 | # talk about a 'backup' we mean making a copy of the metadata for the | ||
4449 | 277 | # *current* system. The 'archive' contains old metadata configurations. | ||
4450 | 278 | # Backups are stored in a human readeable text format. | ||
4451 | 279 | backup { | ||
4452 | 280 | |||
4453 | 281 | # Should we maintain a backup of the current metadata configuration ? | ||
4454 | 282 | # Use 1 for Yes; 0 for No. | ||
4455 | 283 | # Think very hard before turning this off! | ||
4456 | 284 | backup = 1 | ||
4457 | 285 | |||
4458 | 286 | # Where shall we keep it ? | ||
4459 | 287 | # Remember to back up this directory regularly! | ||
4460 | 288 | backup_dir = "@DEFAULT_SYS_DIR@/@DEFAULT_BACKUP_SUBDIR@" | ||
4461 | 289 | |||
4462 | 290 | # Should we maintain an archive of old metadata configurations. | ||
4463 | 291 | # Use 1 for Yes; 0 for No. | ||
4464 | 292 | # On by default. Think very hard before turning this off. | ||
4465 | 293 | archive = 1 | ||
4466 | 294 | |||
4467 | 295 | # Where should archived files go ? | ||
4468 | 296 | # Remember to back up this directory regularly! | ||
4469 | 297 | archive_dir = "@DEFAULT_SYS_DIR@/@DEFAULT_ARCHIVE_SUBDIR@" | ||
4470 | 298 | |||
4471 | 299 | # What is the minimum number of archive files you wish to keep ? | ||
4472 | 300 | retain_min = 10 | ||
4473 | 301 | |||
4474 | 302 | # What is the minimum time you wish to keep an archive file for ? | ||
4475 | 303 | retain_days = 30 | ||
4476 | 304 | } | ||
4477 | 305 | |||
4478 | 306 | # Settings for the running LVM2 in shell (readline) mode. | ||
4479 | 307 | shell { | ||
4480 | 308 | |||
4481 | 309 | # Number of lines of history to store in ~/.lvm_history | ||
4482 | 310 | history_size = 100 | ||
4483 | 311 | } | ||
4484 | 312 | |||
4485 | 313 | |||
4486 | 314 | # Miscellaneous global LVM2 settings | ||
4487 | 315 | global { | ||
4488 | 316 | |||
4489 | 317 | # The file creation mask for any files and directories created. | ||
4490 | 318 | # Interpreted as octal if the first digit is zero. | ||
4491 | 319 | umask = 077 | ||
4492 | 320 | |||
4493 | 321 | # Allow other users to read the files | ||
4494 | 322 | #umask = 022 | ||
4495 | 323 | |||
4496 | 324 | # Enabling test mode means that no changes to the on disk metadata | ||
4497 | 325 | # will be made. Equivalent to having the -t option on every | ||
4498 | 326 | # command. Defaults to off. | ||
4499 | 327 | test = 0 | ||
4500 | 328 | |||
4501 | 329 | # Default value for --units argument | ||
4502 | 330 | units = "h" | ||
4503 | 331 | |||
4504 | 332 | # Since version 2.02.54, the tools distinguish between powers of | ||
4505 | 333 | # 1024 bytes (e.g. KiB, MiB, GiB) and powers of 1000 bytes (e.g. | ||
4506 | 334 | # KB, MB, GB). | ||
4507 | 335 | # If you have scripts that depend on the old behaviour, set this to 0 | ||
4508 | 336 | # temporarily until you update them. | ||
4509 | 337 | si_unit_consistency = 1 | ||
4510 | 338 | |||
4511 | 339 | # Whether or not to communicate with the kernel device-mapper. | ||
4512 | 340 | # Set to 0 if you want to use the tools to manipulate LVM metadata | ||
4513 | 341 | # without activating any logical volumes. | ||
4514 | 342 | # If the device-mapper kernel driver is not present in your kernel | ||
4515 | 343 | # setting this to 0 should suppress the error messages. | ||
4516 | 344 | activation = 1 | ||
4517 | 345 | |||
4518 | 346 | # If we can't communicate with device-mapper, should we try running | ||
4519 | 347 | # the LVM1 tools? | ||
4520 | 348 | # This option only applies to 2.4 kernels and is provided to help you | ||
4521 | 349 | # switch between device-mapper kernels and LVM1 kernels. | ||
4522 | 350 | # The LVM1 tools need to be installed with .lvm1 suffices | ||
4523 | 351 | # e.g. vgscan.lvm1 and they will stop working after you start using | ||
4524 | 352 | # the new lvm2 on-disk metadata format. | ||
4525 | 353 | # The default value is set when the tools are built. | ||
4526 | 354 | # fallback_to_lvm1 = 0 | ||
4527 | 355 | |||
4528 | 356 | # The default metadata format that commands should use - "lvm1" or "lvm2". | ||
4529 | 357 | # The command line override is -M1 or -M2. | ||
4530 | 358 | # Defaults to "lvm2". | ||
4531 | 359 | # format = "lvm2" | ||
4532 | 360 | |||
4533 | 361 | # Location of proc filesystem | ||
4534 | 362 | proc = "/proc" | ||
4535 | 363 | |||
4536 | 364 | # Type of locking to use. Defaults to local file-based locking (1). | ||
4537 | 365 | # Turn locking off by setting to 0 (dangerous: risks metadata corruption | ||
4538 | 366 | # if LVM2 commands get run concurrently). | ||
4539 | 367 | # Type 2 uses the external shared library locking_library. | ||
4540 | 368 | # Type 3 uses built-in clustered locking. | ||
4541 | 369 | # Type 4 uses read-only locking which forbids any operations that might | ||
4542 | 370 | # change metadata. | ||
4543 | 371 | locking_type = 1 | ||
4544 | 372 | |||
4545 | 373 | # Set to 0 to fail when a lock request cannot be satisfied immediately. | ||
4546 | 374 | wait_for_locks = 1 | ||
4547 | 375 | |||
4548 | 376 | # If using external locking (type 2) and initialisation fails, | ||
4549 | 377 | # with this set to 1 an attempt will be made to use the built-in | ||
4550 | 378 | # clustered locking. | ||
4551 | 379 | # If you are using a customised locking_library you should set this to 0. | ||
4552 | 380 | fallback_to_clustered_locking = 1 | ||
4553 | 381 | |||
4554 | 382 | # If an attempt to initialise type 2 or type 3 locking failed, perhaps | ||
4555 | 383 | # because cluster components such as clvmd are not running, with this set | ||
4556 | 384 | # to 1 an attempt will be made to use local file-based locking (type 1). | ||
4557 | 385 | # If this succeeds, only commands against local volume groups will proceed. | ||
4558 | 386 | # Volume Groups marked as clustered will be ignored. | ||
4559 | 387 | fallback_to_local_locking = 1 | ||
4560 | 388 | |||
4561 | 389 | # Local non-LV directory that holds file-based locks while commands are | ||
4562 | 390 | # in progress. A directory like /tmp that may get wiped on reboot is OK. | ||
4563 | 391 | locking_dir = "@DEFAULT_LOCK_DIR@" | ||
4564 | 392 | |||
4565 | 393 | # Whenever there are competing read-only and read-write access requests for | ||
4566 | 394 | # a volume group's metadata, instead of always granting the read-only | ||
4567 | 395 | # requests immediately, delay them to allow the read-write requests to be | ||
4568 | 396 | # serviced. Without this setting, write access may be stalled by a high | ||
4569 | 397 | # volume of read-only requests. | ||
4570 | 398 | # NB. This option only affects locking_type = 1 viz. local file-based | ||
4571 | 399 | # locking. | ||
4572 | 400 | prioritise_write_locks = 1 | ||
4573 | 401 | |||
4574 | 402 | # Other entries can go here to allow you to load shared libraries | ||
4575 | 403 | # e.g. if support for LVM1 metadata was compiled as a shared library use | ||
4576 | 404 | # format_libraries = "liblvm2format1.so" | ||
4577 | 405 | # Full pathnames can be given. | ||
4578 | 406 | |||
4579 | 407 | # Search this directory first for shared libraries. | ||
4580 | 408 | # library_dir = "/lib" | ||
4581 | 409 | |||
4582 | 410 | # The external locking library to load if locking_type is set to 2. | ||
4583 | 411 | # locking_library = "liblvm2clusterlock.so" | ||
4584 | 412 | |||
4585 | 413 | # Treat any internal errors as fatal errors, aborting the process that | ||
4586 | 414 | # encountered the internal error. Please only enable for debugging. | ||
4587 | 415 | abort_on_internal_errors = 0 | ||
4588 | 416 | |||
4589 | 417 | # Check whether CRC is matching when parsed VG is used multiple times. | ||
4590 | 418 | # This is useful to catch unexpected internal cached volume group | ||
4591 | 419 | # structure modification. Please only enable for debugging. | ||
4592 | 420 | detect_internal_vg_cache_corruption = 0 | ||
4593 | 421 | |||
4594 | 422 | # If set to 1, no operations that change on-disk metadata will be permitted. | ||
4595 | 423 | # Additionally, read-only commands that encounter metadata in need of repair | ||
4596 | 424 | # will still be allowed to proceed exactly as if the repair had been | ||
4597 | 425 | # performed (except for the unchanged vg_seqno). | ||
4598 | 426 | # Inappropriate use could mess up your system, so seek advice first! | ||
4599 | 427 | metadata_read_only = 0 | ||
4600 | 428 | |||
4601 | 429 | # 'mirror_segtype_default' defines which segtype will be used when the | ||
4602 | 430 | # shorthand '-m' option is used for mirroring. The possible options are: | ||
4603 | 431 | # | ||
4604 | 432 | # "mirror" - The original RAID1 implementation provided by LVM2/DM. It is | ||
4605 | 433 | # characterized by a flexible log solution (core, disk, mirrored) | ||
4606 | 434 | # and by the necessity to block I/O while reconfiguring in the | ||
4607 | 435 | # event of a failure. Snapshots of this type of RAID1 can be | ||
4608 | 436 | # problematic. | ||
4609 | 437 | # | ||
4610 | 438 | # "raid1" - This implementation leverages MD's RAID1 personality through | ||
4611 | 439 | # device-mapper. It is characterized by a lack of log options. | ||
4612 | 440 | # (A log is always allocated for every device and they are placed | ||
4613 | 441 | # on the same device as the image - no separate devices are | ||
4614 | 442 | # required.) This mirror implementation does not require I/O | ||
4615 | 443 | # to be blocked in the kernel in the event of a failure. | ||
4616 | 444 | # | ||
4617 | 445 | # Specify the '--type <mirror|raid1>' option to override this default | ||
4618 | 446 | # setting. | ||
4619 | 447 | mirror_segtype_default = "mirror" | ||
4620 | 448 | |||
4621 | 449 | # The default format for displaying LV names in lvdisplay was changed | ||
4622 | 450 | # in version 2.02.89 to show the LV name and path separately. | ||
4623 | 451 | # Previously this was always shown as /dev/vgname/lvname even when that | ||
4624 | 452 | # was never a valid path in the /dev filesystem. | ||
4625 | 453 | # Set to 1 to reinstate the previous format. | ||
4626 | 454 | # | ||
4627 | 455 | # lvdisplay_shows_full_device_path = 0 | ||
4628 | 456 | |||
4629 | 457 | # Whether to use (trust) a running instance of lvmetad. If this is set to | ||
4630 | 458 | # 0, all commands fall back to the usual scanning mechanisms. When set to 1 | ||
4631 | 459 | # *and* when lvmetad is running (it is not auto-started), the volume group | ||
4632 | 460 | # metadata and PV state flags are obtained from the lvmetad instance and no | ||
4633 | 461 | # scanning is done by the individual commands. In a setup with lvmetad, | ||
4634 | 462 | # lvmetad udev rules *must* be set up for LVM to work correctly. Without | ||
4635 | 463 | # proper udev rules, all changes in block device configuration will be | ||
4636 | 464 | # *ignored* until a manual 'vgscan' is performed. | ||
4637 | 465 | use_lvmetad = 0 | ||
4638 | 466 | } | ||
4639 | 467 | |||
4640 | 468 | activation { | ||
4641 | 469 | # Set to 1 to perform internal checks on the operations issued to | ||
4642 | 470 | # libdevmapper. Useful for debugging problems with activation. | ||
4643 | 471 | # Some of the checks may be expensive, so it's best to use this | ||
4644 | 472 | # only when there seems to be a problem. | ||
4645 | 473 | checks = 0 | ||
4646 | 474 | |||
4647 | 475 | # Set to 0 to disable udev synchronisation (if compiled into the binaries). | ||
4648 | 476 | # Processes will not wait for notification from udev. | ||
4649 | 477 | # They will continue irrespective of any possible udev processing | ||
4650 | 478 | # in the background. You should only use this if udev is not running | ||
4651 | 479 | # or has rules that ignore the devices LVM2 creates. | ||
4652 | 480 | # The command line argument --nodevsync takes precedence over this setting. | ||
4653 | 481 | # If set to 1 when udev is not running, and there are LVM2 processes | ||
4654 | 482 | # waiting for udev, run 'dmsetup udevcomplete_all' manually to wake them up. | ||
4655 | 483 | udev_sync = 1 | ||
4656 | 484 | |||
4657 | 485 | # Set to 0 to disable the udev rules installed by LVM2 (if built with | ||
4658 | 486 | # --enable-udev_rules). LVM2 will then manage the /dev nodes and symlinks | ||
4659 | 487 | # for active logical volumes directly itself. | ||
4660 | 488 | # N.B. Manual intervention may be required if this setting is changed | ||
4661 | 489 | # while any logical volumes are active. | ||
4662 | 490 | udev_rules = 1 | ||
4663 | 491 | |||
4664 | 492 | # Set to 1 for LVM2 to verify operations performed by udev. This turns on | ||
4665 | 493 | # additional checks (and if necessary, repairs) on entries in the device | ||
4666 | 494 | # directory after udev has completed processing its events. | ||
4667 | 495 | # Useful for diagnosing problems with LVM2/udev interactions. | ||
4668 | 496 | verify_udev_operations = 0 | ||
4669 | 497 | |||
4670 | 498 | # If set to 1 and if deactivation of an LV fails, perhaps because | ||
4671 | 499 | # a process run from a quick udev rule temporarily opened the device, | ||
4672 | 500 | # retry the operation for a few seconds before failing. | ||
4673 | 501 | retry_deactivation = 1 | ||
4674 | 502 | |||
4675 | 503 | # How to fill in missing stripes if activating an incomplete volume. | ||
4676 | 504 | # Using "error" will make inaccessible parts of the device return | ||
4677 | 505 | # I/O errors on access. You can instead use a device path, in which | ||
4678 | 506 | # case, that device will be used to in place of missing stripes. | ||
4679 | 507 | # But note that using anything other than "error" with mirrored | ||
4680 | 508 | # or snapshotted volumes is likely to result in data corruption. | ||
4681 | 509 | missing_stripe_filler = "error" | ||
4682 | 510 | |||
4683 | 511 | # The linear target is an optimised version of the striped target | ||
4684 | 512 | # that only handles a single stripe. Set this to 0 to disable this | ||
4685 | 513 | # optimisation and always use the striped target. | ||
4686 | 514 | use_linear_target = 1 | ||
4687 | 515 | |||
4688 | 516 | # How much stack (in KB) to reserve for use while devices suspended | ||
4689 | 517 | # Prior to version 2.02.89 this used to be set to 256KB | ||
4690 | 518 | reserved_stack = 64 | ||
4691 | 519 | |||
4692 | 520 | # How much memory (in KB) to reserve for use while devices suspended | ||
4693 | 521 | reserved_memory = 8192 | ||
4694 | 522 | |||
4695 | 523 | # Nice value used while devices suspended | ||
4696 | 524 | process_priority = -18 | ||
4697 | 525 | |||
4698 | 526 | # If volume_list is defined, each LV is only activated if there is a | ||
4699 | 527 | # match against the list. | ||
4700 | 528 | # "vgname" and "vgname/lvname" are matched exactly. | ||
4701 | 529 | # "@tag" matches any tag set in the LV or VG. | ||
4702 | 530 | # "@*" matches if any tag defined on the host is also set in the LV or VG | ||
4703 | 531 | # | ||
4704 | 532 | # volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ] | ||
4705 | 533 | |||
4706 | 534 | # If read_only_volume_list is defined, each LV that is to be activated | ||
4707 | 535 | # is checked against the list, and if it matches, it as activated | ||
4708 | 536 | # in read-only mode. (This overrides '--permission rw' stored in the | ||
4709 | 537 | # metadata.) | ||
4710 | 538 | # "vgname" and "vgname/lvname" are matched exactly. | ||
4711 | 539 | # "@tag" matches any tag set in the LV or VG. | ||
4712 | 540 | # "@*" matches if any tag defined on the host is also set in the LV or VG | ||
4713 | 541 | # | ||
4714 | 542 | # read_only_volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ] | ||
4715 | 543 | |||
4716 | 544 | # Size (in KB) of each copy operation when mirroring | ||
4717 | 545 | mirror_region_size = 512 | ||
4718 | 546 | |||
4719 | 547 | # Setting to use when there is no readahead value stored in the metadata. | ||
4720 | 548 | # | ||
4721 | 549 | # "none" - Disable readahead. | ||
4722 | 550 | # "auto" - Use default value chosen by kernel. | ||
4723 | 551 | readahead = "auto" | ||
4724 | 552 | |||
4725 | 553 | # 'raid_fault_policy' defines how a device failure in a RAID logical | ||
4726 | 554 | # volume is handled. This includes logical volumes that have the following | ||
4727 | 555 | # segment types: raid1, raid4, raid5*, and raid6*. | ||
4728 | 556 | # | ||
4729 | 557 | # In the event of a failure, the following policies will determine what | ||
4730 | 558 | # actions are performed during the automated response to failures (when | ||
4731 | 559 | # dmeventd is monitoring the RAID logical volume) and when 'lvconvert' is | ||
4732 | 560 | # called manually with the options '--repair' and '--use-policies'. | ||
4733 | 561 | # | ||
4734 | 562 | # "warn" - Use the system log to warn the user that a device in the RAID | ||
4735 | 563 | # logical volume has failed. It is left to the user to run | ||
4736 | 564 | # 'lvconvert --repair' manually to remove or replace the failed | ||
4737 | 565 | # device. As long as the number of failed devices does not | ||
4738 | 566 | # exceed the redundancy of the logical volume (1 device for | ||
4739 | 567 | # raid4/5, 2 for raid6, etc) the logical volume will remain | ||
4740 | 568 | # usable. | ||
4741 | 569 | # | ||
4742 | 570 | # "allocate" - Attempt to use any extra physical volumes in the volume | ||
4743 | 571 | # group as spares and replace faulty devices. | ||
4744 | 572 | # | ||
4745 | 573 | raid_fault_policy = "warn" | ||
4746 | 574 | |||
4747 | 575 | # 'mirror_image_fault_policy' and 'mirror_log_fault_policy' define | ||
4748 | 576 | # how a device failure affecting a mirror (of "mirror" segment type) is | ||
4749 | 577 | # handled. A mirror is composed of mirror images (copies) and a log. | ||
4750 | 578 | # A disk log ensures that a mirror does not need to be re-synced | ||
4751 | 579 | # (all copies made the same) every time a machine reboots or crashes. | ||
4752 | 580 | # | ||
4753 | 581 | # In the event of a failure, the specified policy will be used to determine | ||
4754 | 582 | # what happens. This applies to automatic repairs (when the mirror is being | ||
4755 | 583 | # monitored by dmeventd) and to manual lvconvert --repair when | ||
4756 | 584 | # --use-policies is given. | ||
4757 | 585 | # | ||
4758 | 586 | # "remove" - Simply remove the faulty device and run without it. If | ||
4759 | 587 | # the log device fails, the mirror would convert to using | ||
4760 | 588 | # an in-memory log. This means the mirror will not | ||
4761 | 589 | # remember its sync status across crashes/reboots and | ||
4762 | 590 | # the entire mirror will be re-synced. If a | ||
4763 | 591 | # mirror image fails, the mirror will convert to a | ||
4764 | 592 | # non-mirrored device if there is only one remaining good | ||
4765 | 593 | # copy. | ||
4766 | 594 | # | ||
4767 | 595 | # "allocate" - Remove the faulty device and try to allocate space on | ||
4768 | 596 | # a new device to be a replacement for the failed device. | ||
4769 | 597 | # Using this policy for the log is fast and maintains the | ||
4770 | 598 | # ability to remember sync state through crashes/reboots. | ||
4771 | 599 | # Using this policy for a mirror device is slow, as it | ||
4772 | 600 | # requires the mirror to resynchronize the devices, but it | ||
4773 | 601 | # will preserve the mirror characteristic of the device. | ||
4774 | 602 | # This policy acts like "remove" if no suitable device and | ||
4775 | 603 | # space can be allocated for the replacement. | ||
4776 | 604 | # | ||
4777 | 605 | # "allocate_anywhere" - Not yet implemented. Useful to place the log device | ||
4778 | 606 | # temporarily on same physical volume as one of the mirror | ||
4779 | 607 | # images. This policy is not recommended for mirror devices | ||
4780 | 608 | # since it would break the redundant nature of the mirror. This | ||
4781 | 609 | # policy acts like "remove" if no suitable device and space can | ||
4782 | 610 | # be allocated for the replacement. | ||
4783 | 611 | |||
4784 | 612 | mirror_log_fault_policy = "allocate" | ||
4785 | 613 | mirror_image_fault_policy = "remove" | ||
4786 | 614 | |||
4787 | 615 | # 'snapshot_autoextend_threshold' and 'snapshot_autoextend_percent' define | ||
4788 | 616 | # how to handle automatic snapshot extension. The former defines when the | ||
4789 | 617 | # snapshot should be extended: when its space usage exceeds this many | ||
4790 | 618 | # percent. The latter defines how much extra space should be allocated for | ||
4791 | 619 | # the snapshot, in percent of its current size. | ||
4792 | 620 | # | ||
4793 | 621 | # For example, if you set snapshot_autoextend_threshold to 70 and | ||
4794 | 622 | # snapshot_autoextend_percent to 20, whenever a snapshot exceeds 70% usage, | ||
4795 | 623 | # it will be extended by another 20%. For a 1G snapshot, using up 700M will | ||
4796 | 624 | # trigger a resize to 1.2G. When the usage exceeds 840M, the snapshot will | ||
4797 | 625 | # be extended to 1.44G, and so on. | ||
4798 | 626 | # | ||
4799 | 627 | # Setting snapshot_autoextend_threshold to 100 disables automatic | ||
4800 | 628 | # extensions. The minimum value is 50 (A setting below 50 will be treated | ||
4801 | 629 | # as 50). | ||
4802 | 630 | |||
4803 | 631 | snapshot_autoextend_threshold = 100 | ||
4804 | 632 | snapshot_autoextend_percent = 20 | ||
4805 | 633 | |||
4806 | 634 | # 'thin_pool_autoextend_threshold' and 'thin_pool_autoextend_percent' define | ||
4807 | 635 | # how to handle automatic pool extension. The former defines when the | ||
4808 | 636 | # pool should be extended: when its space usage exceeds this many | ||
4809 | 637 | # percent. The latter defines how much extra space should be allocated for | ||
4810 | 638 | # the pool, in percent of its current size. | ||
4811 | 639 | # | ||
4812 | 640 | # For example, if you set thin_pool_autoextend_threshold to 70 and | ||
4813 | 641 | # thin_pool_autoextend_percent to 20, whenever a pool exceeds 70% usage, | ||
4814 | 642 | # it will be extended by another 20%. For a 1G pool, using up 700M will | ||
4815 | 643 | # trigger a resize to 1.2G. When the usage exceeds 840M, the pool will | ||
4816 | 644 | # be extended to 1.44G, and so on. | ||
4817 | 645 | # | ||
4818 | 646 | # Setting thin_pool_autoextend_threshold to 100 disables automatic | ||
4819 | 647 | # extensions. The minimum value is 50 (A setting below 50 will be treated | ||
4820 | 648 | # as 50). | ||
4821 | 649 | |||
4822 | 650 | thin_pool_autoextend_threshold = 100 | ||
4823 | 651 | thin_pool_autoextend_percent = 20 | ||
4824 | 652 | |||
4825 | 653 | # Full path of the utility called to check that a thin metadata device | ||
4826 | 654 | # is in a state that allows it to be used. | ||
4827 | 655 | # Each time a thin pool needs to be activated, this utility is executed. | ||
4828 | 656 | # The activation will only proceed if the utility has an exit status of 0. | ||
4829 | 657 | # Set to "" to skip this check. (Not recommended.) | ||
4830 | 658 | # The thin tools are available as part of the device-mapper-persistent-data | ||
4831 | 659 | # package from https://github.com/jthornber/thin-provisioning-tools. | ||
4832 | 660 | # | ||
4833 | 661 | thin_check_executable = "/sbin/thin_check -q" | ||
4834 | 662 | |||
4835 | 663 | # While activating devices, I/O to devices being (re)configured is | ||
4836 | 664 | # suspended, and as a precaution against deadlocks, LVM2 needs to pin | ||
4837 | 665 | # any memory it is using so it is not paged out. Groups of pages that | ||
4838 | 666 | # are known not to be accessed during activation need not be pinned | ||
4839 | 667 | # into memory. Each string listed in this setting is compared against | ||
4840 | 668 | # each line in /proc/self/maps, and the pages corresponding to any | ||
4841 | 669 | # lines that match are not pinned. On some systems locale-archive was | ||
4842 | 670 | # found to make up over 80% of the memory used by the process. | ||
4843 | 671 | # mlock_filter = [ "locale/locale-archive", "gconv/gconv-modules.cache" ] | ||
4844 | 672 | |||
4845 | 673 | # Set to 1 to revert to the default behaviour prior to version 2.02.62 | ||
4846 | 674 | # which used mlockall() to pin the whole process's memory while activating | ||
4847 | 675 | # devices. | ||
4848 | 676 | use_mlockall = 0 | ||
4849 | 677 | |||
4850 | 678 | # Monitoring is enabled by default when activating logical volumes. | ||
4851 | 679 | # Set to 0 to disable monitoring or use the --ignoremonitoring option. | ||
4852 | 680 | monitoring = 1 | ||
4853 | 681 | |||
4854 | 682 | # When pvmove or lvconvert must wait for the kernel to finish | ||
4855 | 683 | # synchronising or merging data, they check and report progress | ||
4856 | 684 | # at intervals of this number of seconds. The default is 15 seconds. | ||
4857 | 685 | # If this is set to 0 and there is only one thing to wait for, there | ||
4858 | 686 | # are no progress reports, but the process is awoken immediately the | ||
4859 | 687 | # operation is complete. | ||
4860 | 688 | polling_interval = 15 | ||
4861 | 689 | } | ||
4862 | 690 | |||
4863 | 691 | |||
4864 | 692 | #################### | ||
4865 | 693 | # Advanced section # | ||
4866 | 694 | #################### | ||
4867 | 695 | |||
4868 | 696 | # Metadata settings | ||
4869 | 697 | # | ||
4870 | 698 | # metadata { | ||
4871 | 699 | # Default number of copies of metadata to hold on each PV. 0, 1 or 2. | ||
4872 | 700 | # You might want to override it from the command line with 0 | ||
4873 | 701 | # when running pvcreate on new PVs which are to be added to large VGs. | ||
4874 | 702 | |||
4875 | 703 | # pvmetadatacopies = 1 | ||
4876 | 704 | |||
4877 | 705 | # Default number of copies of metadata to maintain for each VG. | ||
4878 | 706 | # If set to a non-zero value, LVM automatically chooses which of | ||
4879 | 707 | # the available metadata areas to use to achieve the requested | ||
4880 | 708 | # number of copies of the VG metadata. If you set a value larger | ||
4881 | 709 | # than the the total number of metadata areas available then | ||
4882 | 710 | # metadata is stored in them all. | ||
4883 | 711 | # The default value of 0 ("unmanaged") disables this automatic | ||
4884 | 712 | # management and allows you to control which metadata areas | ||
4885 | 713 | # are used at the individual PV level using 'pvchange | ||
4886 | 714 | # --metadataignore y/n'. | ||
4887 | 715 | |||
4888 | 716 | # vgmetadatacopies = 0 | ||
4889 | 717 | |||
4890 | 718 | # Approximate default size of on-disk metadata areas in sectors. | ||
4891 | 719 | # You should increase this if you have large volume groups or | ||
4892 | 720 | # you want to retain a large on-disk history of your metadata changes. | ||
4893 | 721 | |||
4894 | 722 | # pvmetadatasize = 255 | ||
4895 | 723 | |||
4896 | 724 | # List of directories holding live copies of text format metadata. | ||
4897 | 725 | # These directories must not be on logical volumes! | ||
4898 | 726 | # It's possible to use LVM2 with a couple of directories here, | ||
4899 | 727 | # preferably on different (non-LV) filesystems, and with no other | ||
4900 | 728 | # on-disk metadata (pvmetadatacopies = 0). Or this can be in | ||
4901 | 729 | # addition to on-disk metadata areas. | ||
4902 | 730 | # The feature was originally added to simplify testing and is not | ||
4903 | 731 | # supported under low memory situations - the machine could lock up. | ||
4904 | 732 | # | ||
4905 | 733 | # Never edit any files in these directories by hand unless you | ||
4906 | 734 | # you are absolutely sure you know what you are doing! Use | ||
4907 | 735 | # the supplied toolset to make changes (e.g. vgcfgrestore). | ||
4908 | 736 | |||
4909 | 737 | # dirs = [ "/etc/lvm/metadata", "/mnt/disk2/lvm/metadata2" ] | ||
4910 | 738 | #} | ||
4911 | 739 | |||
4912 | 740 | # Event daemon | ||
4913 | 741 | # | ||
4914 | 742 | dmeventd { | ||
4915 | 743 | # mirror_library is the library used when monitoring a mirror device. | ||
4916 | 744 | # | ||
4917 | 745 | # "libdevmapper-event-lvm2mirror.so" attempts to recover from | ||
4918 | 746 | # failures. It removes failed devices from a volume group and | ||
4919 | 747 | # reconfigures a mirror as necessary. If no mirror library is | ||
4920 | 748 | # provided, mirrors are not monitored through dmeventd. | ||
4921 | 749 | |||
4922 | 750 | mirror_library = "libdevmapper-event-lvm2mirror.so" | ||
4923 | 751 | |||
4924 | 752 | # snapshot_library is the library used when monitoring a snapshot device. | ||
4925 | 753 | # | ||
4926 | 754 | # "libdevmapper-event-lvm2snapshot.so" monitors the filling of | ||
4927 | 755 | # snapshots and emits a warning through syslog when the use of | ||
4928 | 756 | # the snapshot exceeds 80%. The warning is repeated when 85%, 90% and | ||
4929 | 757 | # 95% of the snapshot is filled. | ||
4930 | 758 | |||
4931 | 759 | snapshot_library = "libdevmapper-event-lvm2snapshot.so" | ||
4932 | 760 | |||
4933 | 761 | # thin_library is the library used when monitoring a thin device. | ||
4934 | 762 | # | ||
4935 | 763 | # "libdevmapper-event-lvm2thin.so" monitors the filling of | ||
4936 | 764 | # pool and emits a warning through syslog when the use of | ||
4937 | 765 | # the pool exceeds 80%. The warning is repeated when 85%, 90% and | ||
4938 | 766 | # 95% of the pool is filled. | ||
4939 | 767 | |||
4940 | 768 | thin_library = "libdevmapper-event-lvm2thin.so" | ||
4941 | 769 | |||
4942 | 770 | # Full path of the dmeventd binary. | ||
4943 | 771 | # | ||
4944 | 772 | # executable = "@DMEVENTD_PATH@" | ||
4945 | 773 | } | ||
4946 | 0 | 774 | ||
4947 | === removed file '.pc/dirs.patch/doc/example.conf.in' | |||
4948 | --- .pc/dirs.patch/doc/example.conf.in 2012-04-14 02:57:53 +0000 | |||
4949 | +++ .pc/dirs.patch/doc/example.conf.in 1970-01-01 00:00:00 +0000 | |||
4950 | @@ -1,662 +0,0 @@ | |||
4951 | 1 | # This is an example configuration file for the LVM2 system. | ||
4952 | 2 | # It contains the default settings that would be used if there was no | ||
4953 | 3 | # @DEFAULT_SYS_DIR@/lvm.conf file. | ||
4954 | 4 | # | ||
4955 | 5 | # Refer to 'man lvm.conf' for further information including the file layout. | ||
4956 | 6 | # | ||
4957 | 7 | # To put this file in a different directory and override @DEFAULT_SYS_DIR@ set | ||
4958 | 8 | # the environment variable LVM_SYSTEM_DIR before running the tools. | ||
4959 | 9 | # | ||
4960 | 10 | # N.B. Take care that each setting only appears once if uncommenting | ||
4961 | 11 | # example settings in this file. | ||
4962 | 12 | |||
4963 | 13 | |||
4964 | 14 | # This section allows you to configure which block devices should | ||
4965 | 15 | # be used by the LVM system. | ||
4966 | 16 | devices { | ||
4967 | 17 | |||
4968 | 18 | # Where do you want your volume groups to appear ? | ||
4969 | 19 | dir = "/dev" | ||
4970 | 20 | |||
4971 | 21 | # An array of directories that contain the device nodes you wish | ||
4972 | 22 | # to use with LVM2. | ||
4973 | 23 | scan = [ "/dev" ] | ||
4974 | 24 | |||
4975 | 25 | # If set, the cache of block device nodes with all associated symlinks | ||
4976 | 26 | # will be constructed out of the existing udev database content. | ||
4977 | 27 | # This avoids using and opening any inapplicable non-block devices or | ||
4978 | 28 | # subdirectories found in the device directory. This setting is applied | ||
4979 | 29 | # to udev-managed device directory only, other directories will be scanned | ||
4980 | 30 | # fully. LVM2 needs to be compiled with udev support for this setting to | ||
4981 | 31 | # take effect. N.B. Any device node or symlink not managed by udev in | ||
4982 | 32 | # udev directory will be ignored with this setting on. | ||
4983 | 33 | obtain_device_list_from_udev = 1 | ||
4984 | 34 | |||
4985 | 35 | # If several entries in the scanned directories correspond to the | ||
4986 | 36 | # same block device and the tools need to display a name for device, | ||
4987 | 37 | # all the pathnames are matched against each item in the following | ||
4988 | 38 | # list of regular expressions in turn and the first match is used. | ||
4989 | 39 | preferred_names = [ ] | ||
4990 | 40 | |||
4991 | 41 | # Try to avoid using undescriptive /dev/dm-N names, if present. | ||
4992 | 42 | # preferred_names = [ "^/dev/mpath/", "^/dev/mapper/mpath", "^/dev/[hs]d" ] | ||
4993 | 43 | |||
4994 | 44 | # A filter that tells LVM2 to only use a restricted set of devices. | ||
4995 | 45 | # The filter consists of an array of regular expressions. These | ||
4996 | 46 | # expressions can be delimited by a character of your choice, and | ||
4997 | 47 | # prefixed with either an 'a' (for accept) or 'r' (for reject). | ||
4998 | 48 | # The first expression found to match a device name determines if | ||
4999 | 49 | # the device will be accepted or rejected (ignored). Devices that | ||
5000 | 50 | # don't match any patterns are accepted. |
> - debian/ {clvmd. ra,clvm. init}:
> - create /var/run/lvm if it doesn't exist.
debian/rules now points at /run/lvm; this should be updated to match.
--- debian/ libdevmapper- dev.install 2010-12-07 08:08:45 +0000 libdevmapper- dev.install 2012-08-18 04:00:45 +0000 libdevmapper. h libdevmapper- event.h libdevmapper. so pkgconfig/ devmapper. pc pkgconfig/ devmapper- event.pc libdevmapper* */pkgconfig/ devmapper*
+++ debian/
@@ -1,5 +1,2 @@
-usr/include/
-usr/include/
-usr/lib/
-usr/lib/
-usr/lib/
+usr/include/
+usr/lib/
Hmm, good catch. I think you should call this out as a separate change in the changelog, since this isn't just a "remaining change" but a fix to multiarch support for the runtime lib package.
--- debian/ lvm2.postinst 2009-10-08 18:17:43 +0000 lvm2.postinst 2012-08-15 17:05:32 +0000
vgcfgbackup >/dev/null 2>&1 || : update- initramfs ]; then
update- initramfs -u
+++ debian/
@@ -5,7 +5,9 @@
case "$1" in
configure)
- invoke-rc.d lvm2 start || :
+ if [ -x /etc/init.d/lvm2 ]; then
+ invoke-rc.d lvm2 start || :
+ fi
if [ -x /usr/sbin/
fi
Since the lvm2.init is being dropped, this probably shouldn't be conditional - it should probably be removed entirely. In fact, when this regression was introduced during the lucid merge, the previous postinst was doing this:
if test -f /etc/init.d/lvm2; then
update-rc.d -f lvm2 remove >/dev/null 2>&1 || true
rm -f /etc/init.d/lvm2
fi
We probably want to be doing that again, possibly with better handling of modified conffiles.
BTW, perhaps it's worth checking with Kees to see if there was a reason he thought this init script should be restored when merging.
--- debian/ libdevmapper- event1. 02.1.symbols 2012-04-14 03:19:00 +0000 libdevmapper- event1. 02.1.symbols 2012-08-18 04:00:45 +0000 event.so. 1.02.1 libdevmapper- event1. 02.1 #MINVER# daemon_ fini_fifos@ Base 2:1.02.74 daemon_ init_fifos@ Base 2:1.02.74 daemon_ talk@Base 2:1.02.74
+++ debian/
@@ -1,11 +1,13 @@
libdevmapper-
Base@Base 2:1.02.20
- daemon_talk@Base 2:1.02.67
+ dm_event_
+ dm_event_
+ dm_event_
This is unfortunate, but it happens... In this case, it appears that dmeventd used the old symbol, so we want to have a Breaks against the old version of dmeventd. No other packages in Ubuntu that depend on libdevmapper- event1. 02.1 appear to use that symbol, so this Breaks is the only fix needed.
- dm_event_ get_version@ Base 2:1.02.67 get_version@ Base 2:1.02.74 handler_ create@ Base 2:1.02.20 handler_ destroy@ Base 2:1.02.20 handler_ get_dev_ name@Base 2:1.02.67 handler_ get_dev_ name@Base 2:1.02.74
+ dm_event_
dm_event_
dm_event_
- dm_event_
+ dm_event_
Those version bumps are unnecessary in Ubuntu, but mostly harmless.
@@ -22,5 +24,3 @@ handler_ set_uuid@ Base 2:1.02.20 register_ handler@ Base 2:1.02.20 unregister_ handler@ Base 2:1.02.20
dm_event_
dm_event_
dm_event_
- fini_fifos@Base 2:1.02.67
- init_fifos@Base 2:1.02.67
These symbols are also only used by dmeventd. (This makes sense, as all three symbols appear to be due to a Debian-specific patch for dmeventd.)
The rest looks good to me.