1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* uevent.c - trigger upon netlink uevents from the kernel
*
* Only kernels from version 2.6.10* on provide the uevent netlink socket.
* Until the libc-kernel-headers are updated, you need to compile with:
*
* gcc -I /lib/modules/`uname -r`/build/include -o uevent_listen uevent_listen.c
*
* Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*/
#include <unistd.h>
#include <stdio.h>
#include <stdbool.h>
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/user.h>
#include <sys/un.h>
#include <poll.h>
#include <linux/types.h>
#include <linux/netlink.h>
#include <pthread.h>
#include <sys/mman.h>
#include <sys/time.h>
#include "mt-udev-wrap.h"
#include "autoconfig.h"
#include "debug.h"
#include "list.h"
#include "uevent.h"
#include "vector.h"
#include "structs.h"
#include "util.h"
#include "config.h"
#include "blacklist.h"
#include "devmapper.h"
#include "strbuf.h"
typedef int (uev_trigger)(struct uevent *, void * trigger_data);
static LIST_HEAD(uevq);
static pthread_mutex_t uevq_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t *uevq_lockp = &uevq_lock;
static pthread_cond_t uev_cond = PTHREAD_COND_INITIALIZER;
static pthread_cond_t *uev_condp = &uev_cond;
static uev_trigger *my_uev_trigger;
static void *my_trigger_data;
static int servicing_uev;
static int adding_uev; /* uatomic access only */
struct uevent_filter_state {
struct list_head uevq;
struct list_head *old_tail;
struct config *conf;
unsigned long added;
unsigned long discarded;
unsigned long filtered;
unsigned long merged;
};
static void reset_filter_state(struct uevent_filter_state *st)
{
st->added = st->discarded = st->filtered = st->merged = 0;
}
int is_uevent_busy(void)
{
int empty, servicing, adding;
pthread_mutex_lock(uevq_lockp);
empty = list_empty(&uevq);
servicing = servicing_uev;
adding = uatomic_read(&adding_uev);
pthread_mutex_unlock(uevq_lockp);
return (!empty || servicing || adding);
}
struct uevent * alloc_uevent (void)
{
struct uevent *uev = calloc(1, sizeof(struct uevent));
if (uev) {
INIT_LIST_HEAD(&uev->node);
INIT_LIST_HEAD(&uev->merge_node);
}
return uev;
}
static void uevq_cleanup(struct list_head *tmpq);
static void cleanup_uev(void *arg)
{
struct uevent *uev = arg;
uevq_cleanup(&uev->merge_node);
if (uev->udev)
udev_device_unref(uev->udev);
free(uev);
}
static void uevq_cleanup(struct list_head *tmpq)
{
struct uevent *uev, *tmp;
list_for_each_entry_safe(uev, tmp, tmpq, node) {
list_del_init(&uev->node);
cleanup_uev(uev);
}
}
static const char* uevent_get_env_var(const struct uevent *uev,
const char *attr)
{
int i;
size_t len;
const char *p = NULL;
if (attr == NULL)
goto invalid;
len = strlen(attr);
if (len == 0)
goto invalid;
for (i = 0; uev->envp[i] != NULL; i++) {
const char *var = uev->envp[i];
if (strlen(var) > len &&
!memcmp(var, attr, len) && var[len] == '=') {
p = var + len + 1;
break;
}
}
condlog(4, "%s: %s -> '%s'", __func__, attr, p ?: "(null)");
return p;
invalid:
condlog(2, "%s: empty variable name", __func__);
return NULL;
}
int uevent_get_env_positive_int(const struct uevent *uev,
const char *attr)
{
const char *p = uevent_get_env_var(uev, attr);
char *q;
int ret;
if (p == NULL || *p == '\0')
return -1;
ret = strtoul(p, &q, 10);
if (*q != '\0' || ret < 0) {
condlog(2, "%s: invalid %s: '%s'", __func__, attr, p);
return -1;
}
return ret;
}
void
uevent_get_wwid(struct uevent *uev, const struct config *conf)
{
const char *uid_attribute;
const char *val;
uid_attribute = get_uid_attribute_by_attrs(conf, uev->kernel);
val = uevent_get_env_var(uev, uid_attribute);
if (val)
uev->wwid = val;
}
static bool uevent_need_merge(const struct config *conf)
{
return VECTOR_SIZE(&conf->uid_attrs) > 0;
}
static bool uevent_can_discard(struct uevent *uev, const struct config *conf)
{
/*
* do not filter dm devices by devnode
*/
if (!strncmp(uev->kernel, "dm-", 3))
return false;
/*
* filter paths devices by devnode
*/
if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
uev->kernel) > 0)
return true;
return false;
}
static bool
uevent_can_filter(struct uevent *earlier, struct uevent *later)
{
if (!strncmp(later->kernel, "dm-", 3) ||
strcmp(earlier->kernel, later->kernel))
return false;
/*
* filter earlier uvents if path has removed later. Eg:
* "add path1 |chang path1 |add path2 |remove path1"
* can filter as:
* "add path2 |remove path1"
* uevents "add path1" and "chang path1" are filtered out
*/
if (!strcmp(later->action, "remove"))
return true;
/*
* filter change uvents if add uevents exist. Eg:
* "change path1| add path1 |add path2"
* can filter as:
* "add path1 |add path2"
* uevent "chang path1" is filtered out
*/
if (!strcmp(earlier->action, "change") &&
!strcmp(later->action, "add"))
return true;
return false;
}
static bool
merge_need_stop(struct uevent *earlier, struct uevent *later)
{
/*
* dm uevent do not try to merge with left uevents
*/
if (!strncmp(later->kernel, "dm-", 3))
return true;
/*
* we cannot make a jugement without wwid,
* so it is sensible to stop merging
*/
if (!earlier->wwid || !later->wwid)
return true;
/*
* uevents merging stopped
* when we meet an opposite action uevent from the same LUN to AVOID
* "add path1 |remove path1 |add path2 |remove path2 |add path3"
* to merge as "remove path1, path2" and "add path1, path2, path3"
* OR
* "remove path1 |add path1 |remove path2 |add path2 |remove path3"
* to merge as "add path1, path2" and "remove path1, path2, path3"
* SO
* when we meet a non-change uevent from the same LUN
* with the same wwid and different action
* it would be better to stop merging.
*/
if (strcmp(earlier->action, later->action) &&
strcmp(earlier->action, "change") &&
strcmp(later->action, "change") &&
!strcmp(earlier->wwid, later->wwid))
return true;
return false;
}
static bool
uevent_can_merge(struct uevent *earlier, struct uevent *later)
{
/* merge paths uevents
* whose wwids exist and are same
* and actions are same,
* and actions are addition or deletion
*/
if (earlier->wwid && later->wwid &&
strncmp(earlier->kernel, "dm-", 3) &&
!strcmp(earlier->action, later->action) &&
(!strcmp(earlier->action, "add") ||
!strcmp(earlier->action, "remove")) &&
!strcmp(earlier->wwid, later->wwid))
return true;
return false;
}
static void uevent_delete_from_list(struct uevent *to_delete,
struct uevent **previous,
struct list_head **old_tail)
{
/*
* "old_tail" is the list_head before the last list element to which
* the caller iterates (the list anchor if the caller iterates over
* the entire list). If this element is removed (which can't happen
* for the anchor), "old_tail" must be moved. It can happen that
* "old_tail" ends up pointing at the anchor.
*/
if (*old_tail == &to_delete->node)
*old_tail = to_delete->node.prev;
list_del_init(&to_delete->node);
/*
* The "to_delete" uevent has been merged with other uevents
* previously. Re-insert them into the list, at the point we're
* currently at. This must be done after the list_del_init() above,
* otherwise previous->next would still point to to_delete.
*/
if (!list_empty(&to_delete->merge_node)) {
struct uevent *last = list_entry(to_delete->merge_node.prev,
typeof(*last), node);
condlog(3, "%s: deleted uevent \"%s %s\" with merged uevents",
__func__, to_delete->action, to_delete->kernel);
list_splice(&to_delete->merge_node, &(*previous)->node);
*previous = last;
}
if (to_delete->udev)
udev_device_unref(to_delete->udev);
free(to_delete);
}
/*
* Use this function to delete events that are known not to
* be equal to old_tail, and have an empty merge_node list.
* For others, use uevent_delete_from_list().
*/
static void uevent_delete_simple(struct uevent *to_delete)
{
list_del_init(&to_delete->node);
if (to_delete->udev)
udev_device_unref(to_delete->udev);
free(to_delete);
}
static void uevent_prepare(struct uevent_filter_state *st)
{
struct uevent *uev, *tmp;
list_for_some_entry_reverse_safe(uev, tmp, &st->uevq, st->old_tail, node) {
st->added++;
if (uevent_can_discard(uev, st->conf)) {
uevent_delete_simple(uev);
st->discarded++;
continue;
}
if (strncmp(uev->kernel, "dm-", 3) &&
uevent_need_merge(st->conf))
uevent_get_wwid(uev, st->conf);
}
}
static void
uevent_filter(struct uevent *later, struct uevent_filter_state *st)
{
struct uevent *earlier, *tmp;
list_for_some_entry_reverse_safe(earlier, tmp, &later->node, &st->uevq, node) {
/*
* filter unnecessary earlier uevents
* by the later uevent
*/
if (!list_empty(&earlier->merge_node)) {
struct uevent *mn, *t;
list_for_each_entry_reverse_safe(mn, t, &earlier->merge_node, node) {
if (uevent_can_filter(mn, later)) {
condlog(4, "uevent: \"%s %s\" (merged into \"%s %s\") filtered by \"%s %s\"",
mn->action, mn->kernel,
earlier->action, earlier->kernel,
later->action, later->kernel);
uevent_delete_simple(mn);
st->filtered++;
}
}
}
if (uevent_can_filter(earlier, later)) {
condlog(4, "uevent: \"%s %s\" filtered by \"%s %s\"",
earlier->action, earlier->kernel,
later->action, later->kernel);
uevent_delete_from_list(earlier, &tmp, &st->old_tail);
st->filtered++;
}
}
}
static void uevent_merge(struct uevent *later, struct uevent_filter_state *st)
{
struct uevent *earlier, *tmp;
list_for_some_entry_reverse_safe(earlier, tmp, &later->node, &st->uevq, node) {
if (merge_need_stop(earlier, later))
break;
/*
* merge earlier uevents to the later uevent
*/
if (uevent_can_merge(earlier, later)) {
condlog(4, "uevent: \"%s %s\" merged with \"%s %s\" for WWID %s",
earlier->action, earlier->kernel,
later->action, later->kernel, later->wwid);
/* See comment in uevent_delete_from_list() */
if (&earlier->node == st->old_tail)
st->old_tail = earlier->node.prev;
list_move(&earlier->node, &later->merge_node);
list_splice_init(&earlier->merge_node,
&later->merge_node);
st->merged++;
}
}
}
static void merge_uevq(struct uevent_filter_state *st)
{
struct uevent *later;
uevent_prepare(st);
list_for_some_entry_reverse(later, &st->uevq, st->old_tail, node)
uevent_filter(later, st);
if(uevent_need_merge(st->conf))
list_for_some_entry_reverse(later, &st->uevq, st->old_tail, node)
uevent_merge(later, st);
}
static void print_uev(struct strbuf *buf, struct uevent *uev)
{
print_strbuf(buf, "\"%s %s\"", uev->action, uev->kernel);
if (!list_empty(&uev->merge_node)) {
struct uevent *u;
append_strbuf_str(buf, "[");
list_for_each_entry(u, &uev->merge_node, node)
print_strbuf(buf, "\"%s %s \"", u->action, u->kernel);
append_strbuf_str(buf, "]");
}
append_strbuf_str(buf, " ");
}
static void print_uevq(const char *msg, struct list_head *uevq)
{
struct uevent *uev;
int i = 0;
STRBUF_ON_STACK(buf);
if (4 > MAX_VERBOSITY || 4 > libmp_verbosity)
return;
if (list_empty(uevq))
append_strbuf_str(&buf, "*empty*");
else
list_for_each_entry(uev, uevq, node) {
print_strbuf(&buf, "%d:", i++);
print_uev(&buf, uev);
}
condlog(4, "uevent queue (%s): %s", msg, steal_strbuf_str(&buf));
}
static void
service_uevq(struct list_head *tmpq)
{
struct uevent *uev = list_pop_entry(tmpq, typeof(*uev), node);
if (uev == NULL)
return;
condlog(4, "servicing uevent '%s %s'", uev->action, uev->kernel);
pthread_cleanup_push(cleanup_uev, uev);
if (my_uev_trigger && my_uev_trigger(uev, my_trigger_data))
condlog(0, "uevent trigger error");
pthread_cleanup_pop(1);
}
static void uevent_cleanup(void *arg)
{
struct udev *udev = arg;
condlog(3, "Releasing uevent_listen() resources");
udev_unref(udev);
}
static void monitor_cleanup(void *arg)
{
struct udev_monitor *monitor = arg;
condlog(3, "Releasing uevent_monitor() resources");
udev_monitor_unref(monitor);
}
static void cleanup_uevq(void *arg)
{
uevq_cleanup(arg);
}
static void cleanup_global_uevq(void *arg __attribute__((unused)))
{
pthread_mutex_lock(uevq_lockp);
uevq_cleanup(&uevq);
pthread_mutex_unlock(uevq_lockp);
}
static void log_filter_state(const struct uevent_filter_state *st)
{
if (st->added == 0 && st->filtered == 0 && st->merged == 0)
return;
condlog(3, "uevents: %lu added, %lu discarded, %lu filtered, %lu merged",
st->added, st->discarded, st->filtered, st->merged);
}
/*
* Service the uevent queue.
*/
int uevent_dispatch(int (*uev_trigger)(struct uevent *, void * trigger_data),
void * trigger_data)
{
struct uevent_filter_state filter_state;
INIT_LIST_HEAD(&filter_state.uevq);
my_uev_trigger = uev_trigger;
my_trigger_data = trigger_data;
mlockall(MCL_CURRENT | MCL_FUTURE);
pthread_cleanup_push(cleanup_uevq, &filter_state.uevq);
while (1) {
pthread_cleanup_push(cleanup_mutex, uevq_lockp);
pthread_mutex_lock(uevq_lockp);
servicing_uev = !list_empty(&filter_state.uevq);
while (list_empty(&filter_state.uevq) && list_empty(&uevq)) {
condlog(4, "%s: waiting for events", __func__);
pthread_cond_wait(uev_condp, uevq_lockp);
condlog(4, "%s: waking up", __func__);
}
servicing_uev = 1;
/*
* "old_tail" is the list element towards which merge_uevq()
* will iterate: the last element of uevq before
* appending new uevents. If uveq empty, uevq.prev
* equals &uevq, which is what we need.
*/
filter_state.old_tail = filter_state.uevq.prev;
list_splice_tail_init(&uevq, &filter_state.uevq);
pthread_cleanup_pop(1);
if (!my_uev_trigger)
break;
reset_filter_state(&filter_state);
pthread_cleanup_push(put_multipath_config, filter_state.conf);
print_uevq("append", &filter_state.uevq);
filter_state.conf = get_multipath_config();
merge_uevq(&filter_state);
pthread_cleanup_pop(1);
log_filter_state(&filter_state);
print_uevq("merge", &filter_state.uevq);
service_uevq(&filter_state.uevq);
}
pthread_cleanup_pop(1);
condlog(3, "Terminating uev service queue");
return 0;
}
static struct uevent *uevent_from_udev_device(struct udev_device *dev)
{
struct uevent *uev;
int i = 0;
char *pos, *end;
struct udev_list_entry *list_entry;
uev = alloc_uevent();
if (!uev) {
udev_device_unref(dev);
condlog(1, "lost uevent, oom");
return NULL;
}
pos = uev->buffer;
end = pos + HOTPLUG_BUFFER_SIZE + OBJECT_SIZE - 1;
udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(dev)) {
const char *name, *value;
int bytes;
name = udev_list_entry_get_name(list_entry);
if (!name)
name = "(null)";
value = udev_list_entry_get_value(list_entry);
if (!value)
value = "(null)";
bytes = snprintf(pos, end - pos, "%s=%s", name, value);
if (pos + bytes >= end) {
condlog(2, "buffer overflow for uevent");
break;
}
uev->envp[i] = pos;
pos += bytes;
*pos = '\0';
pos++;
if (strcmp(name, "DEVPATH") == 0)
uev->devpath = uev->envp[i] + 8;
if (strcmp(name, "ACTION") == 0)
uev->action = uev->envp[i] + 7;
i++;
if (i == HOTPLUG_NUM_ENVP - 1)
break;
}
if (!uev->devpath || ! uev->action) {
udev_device_unref(dev);
condlog(1, "uevent missing necessary fields");
free(uev);
return NULL;
}
uev->udev = dev;
uev->envp[i] = NULL;
condlog(3, "uevent '%s' from '%s'", uev->action, uev->devpath);
uev->kernel = strrchr(uev->devpath, '/');
if (uev->kernel)
uev->kernel++;
/* print payload environment */
for (i = 0; uev->envp[i] != NULL; i++)
condlog(5, "%s", uev->envp[i]);
return uev;
}
#define MAX_UEVENTS 1000
static int uevent_receive_events(int fd, struct list_head *tmpq,
struct udev_monitor *monitor)
{
struct pollfd ev_poll;
int n = 0;
do {
struct uevent *uev;
struct udev_device *dev;
dev = udev_monitor_receive_device(monitor);
if (!dev) {
condlog(0, "failed getting udev device");
break;
}
uev = uevent_from_udev_device(dev);
if (!uev)
break;
list_add_tail(&uev->node, tmpq);
n++;
condlog(4, "received uevent \"%s %s\"", uev->action, uev->kernel);
ev_poll.fd = fd;
ev_poll.events = POLLIN;
} while (n < MAX_UEVENTS && poll(&ev_poll, 1, 0) > 0);
return n;
}
int uevent_listen(struct udev *udev)
{
int err = 2;
struct udev_monitor *monitor = NULL;
int fd, socket_flags;
LIST_HEAD(uevlisten_tmp);
/*
* Queue uevents for service by dedicated thread so that the uevent
* listening thread does not block on multipathd locks (vecs->lock)
* thereby not getting to empty the socket's receive buffer queue
* often enough.
*/
if (!udev) {
condlog(1, "no udev context");
return 1;
}
udev_ref(udev);
pthread_cleanup_push(uevent_cleanup, udev);
monitor = udev_monitor_new_from_netlink(udev, "udev");
if (!monitor) {
condlog(2, "failed to create udev monitor");
goto out_udev;
}
pthread_cleanup_push(monitor_cleanup, monitor);
#ifdef LIBUDEV_API_RECVBUF
if (udev_monitor_set_receive_buffer_size(monitor, 128 * 1024 * 1024) < 0)
condlog(2, "failed to increase buffer size");
#endif
fd = udev_monitor_get_fd(monitor);
if (fd < 0) {
condlog(2, "failed to get monitor fd");
goto out;
}
socket_flags = fcntl(fd, F_GETFL);
if (socket_flags < 0) {
condlog(2, "failed to get monitor socket flags : %s",
strerror(errno));
goto out;
}
if (fcntl(fd, F_SETFL, socket_flags & ~O_NONBLOCK) < 0) {
condlog(2, "failed to set monitor socket flags : %s",
strerror(errno));
goto out;
}
err = udev_monitor_filter_add_match_subsystem_devtype(monitor, "block",
"disk");
if (err)
condlog(2, "failed to create filter : %s", strerror(-err));
err = udev_monitor_enable_receiving(monitor);
if (err) {
condlog(2, "failed to enable receiving : %s", strerror(-err));
goto out;
}
pthread_cleanup_push(cleanup_global_uevq, NULL);
pthread_cleanup_push(cleanup_uevq, &uevlisten_tmp);
while (1) {
int fdcount, events;
struct pollfd ev_poll = { .fd = fd, .events = POLLIN, };
uatomic_set(&adding_uev, 0);
fdcount = poll(&ev_poll, 1, -1);
if (fdcount < 0) {
if (errno == EINTR)
continue;
condlog(0, "error receiving uevent message: %m");
err = -errno;
break;
}
uatomic_set(&adding_uev, 1);
events = uevent_receive_events(fd, &uevlisten_tmp, monitor);
if (events <= 0)
continue;
condlog(4, "Forwarding %d uevents", events);
pthread_mutex_lock(uevq_lockp);
list_splice_tail_init(&uevlisten_tmp, &uevq);
pthread_cond_signal(uev_condp);
pthread_mutex_unlock(uevq_lockp);
}
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
out:
pthread_cleanup_pop(1);
out_udev:
pthread_cleanup_pop(1);
return err;
}
char *uevent_get_dm_str(const struct uevent *uev, char *attr)
{
const char *tmp = uevent_get_env_var(uev, attr);
if (tmp == NULL)
return NULL;
return strdup(tmp);
}
bool uevent_is_mpath(const struct uevent *uev)
{
const char *uuid = uevent_get_env_var(uev, "DM_UUID");
if (uuid == NULL)
return false;
if (strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN))
return false;
return uuid[UUID_PREFIX_LEN] != '\0';
}
|