1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Manage without dm_udev_cleanup?

This commit is contained in:
Alasdair Kergon 2009-08-03 18:01:45 +00:00
parent 5e82475490
commit a74be32bf6
8 changed files with 40 additions and 68 deletions

View File

@ -1114,6 +1114,7 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
struct dm_tree_node *child; struct dm_tree_node *child;
char *vgname, *lvname, *layer; char *vgname, *lvname, *layer;
const char *name, *uuid; const char *name, *uuid;
int r;
while ((child = dm_tree_next_child(&handle, root, 0))) { while ((child = dm_tree_next_child(&handle, root, 0))) {
if (!(name = dm_tree_node_get_name(child))) if (!(name = dm_tree_node_get_name(child)))
@ -1132,12 +1133,12 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
continue; continue;
dm_tree_set_cookie(root, 0); dm_tree_set_cookie(root, 0);
if (!dm_tree_deactivate_children(root, uuid, strlen(uuid))) { r = dm_tree_deactivate_children(root, uuid, strlen(uuid));
(void) dm_udev_cleanup(dm_tree_get_cookie(root));
return_0;
}
if (!dm_udev_wait(dm_tree_get_cookie(root))) if (!dm_udev_wait(dm_tree_get_cookie(root)))
stack; stack;
if (!r)
return_0;
} }
return 1; return 1;
@ -1171,12 +1172,11 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
case DEACTIVATE: case DEACTIVATE:
/* Deactivate LV and all devices it references that nothing else has open. */ /* Deactivate LV and all devices it references that nothing else has open. */
dm_tree_set_cookie(root, 0); dm_tree_set_cookie(root, 0);
if (!dm_tree_deactivate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1)) { r = dm_tree_deactivate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
(void) dm_udev_cleanup(dm_tree_get_cookie(root));
goto_out;
}
if (!dm_udev_wait(dm_tree_get_cookie(root))) if (!dm_udev_wait(dm_tree_get_cookie(root)))
stack; stack;
if (!r)
goto_out;
if (!_remove_lv_symlinks(dm, root)) if (!_remove_lv_symlinks(dm, root))
log_error("Failed to remove all device symlinks associated with %s.", lv->name); log_error("Failed to remove all device symlinks associated with %s.", lv->name);
break; break;
@ -1196,24 +1196,22 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
/* Preload any devices required before any suspensions */ /* Preload any devices required before any suspensions */
dm_tree_set_cookie(root, 0); dm_tree_set_cookie(root, 0);
if (!dm_tree_preload_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1)) { r = dm_tree_preload_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
(void) dm_udev_cleanup(dm_tree_get_cookie(root));
goto_out;
}
if (!dm_udev_wait(dm_tree_get_cookie(root))) if (!dm_udev_wait(dm_tree_get_cookie(root)))
stack; stack;
if (!r)
goto_out;
if (dm_tree_node_size_changed(root)) if (dm_tree_node_size_changed(root))
dm->flush_required = 1; dm->flush_required = 1;
if (action == ACTIVATE) { if (action == ACTIVATE) {
dm_tree_set_cookie(root, 0); dm_tree_set_cookie(root, 0);
if (!dm_tree_activate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1)) { r = dm_tree_activate_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1);
(void) dm_udev_cleanup(dm_tree_get_cookie(root));
goto_out;
}
if (!dm_udev_wait(dm_tree_get_cookie(root))) if (!dm_udev_wait(dm_tree_get_cookie(root)))
stack; stack;
if (!r)
goto_out;
} }
if (!_create_lv_symlinks(dm, root)) { if (!_create_lv_symlinks(dm, root)) {

View File

@ -161,4 +161,3 @@ dm_udev_set_sync_support
dm_udev_get_sync_support dm_udev_get_sync_support
dm_udev_complete dm_udev_complete
dm_udev_wait dm_udev_wait
dm_udev_cleanup

View File

@ -1742,9 +1742,18 @@ int dm_task_run(struct dm_task *dmt)
if (!_open_control()) if (!_open_control())
return 0; return 0;
/* FIXME Detect and warn if cookie set but should not be. */
repeat_ioctl: repeat_ioctl:
if (!(dmi = _do_dm_ioctl(dmt, command, _ioctl_buffer_double_factor))) if (!(dmi = _do_dm_ioctl(dmt, command, _ioctl_buffer_double_factor))) {
/*
* If an operation that uses a cookie fails, decrement the
* semaphore instead of udev.
* FIXME Review error paths: found one where uevent fired too.
*/
if (dmt->cookie_set)
dm_udev_complete(dmt->event_nr);
return 0; return 0;
}
if (dmi->flags & DM_BUFFER_FULL_FLAG) { if (dmi->flags & DM_BUFFER_FULL_FLAG) {
switch (dmt->type) { switch (dmt->type) {

View File

@ -60,6 +60,7 @@ struct dm_task {
int skip_lockfs; int skip_lockfs;
int suppress_identical_reload; int suppress_identical_reload;
uint64_t existing_table_size; uint64_t existing_table_size;
int cookie_set;
char *uuid; char *uuid;
}; };

View File

@ -1023,6 +1023,5 @@ void dm_udev_set_sync_support(int sync_with_udev);
int dm_udev_get_sync_support(void); int dm_udev_get_sync_support(void);
int dm_udev_complete(uint32_t cookie); int dm_udev_complete(uint32_t cookie);
int dm_udev_wait(uint32_t cookie); int dm_udev_wait(uint32_t cookie);
int dm_udev_cleanup(uint32_t cookie);
#endif /* LIB_DEVICE_MAPPER_H */ #endif /* LIB_DEVICE_MAPPER_H */

View File

@ -174,6 +174,7 @@ struct dm_task *dm_task_create(int type)
dmt->no_open_count = 0; dmt->no_open_count = 0;
dmt->read_ahead = DM_READ_AHEAD_AUTO; dmt->read_ahead = DM_READ_AHEAD_AUTO;
dmt->read_ahead_flags = 0; dmt->read_ahead_flags = 0;
dmt->cookie_set = 0;
return dmt; return dmt;
} }
@ -799,11 +800,6 @@ int dm_udev_wait(uint32_t cookie)
return 1; return 1;
} }
int dm_udev_cleanup(uint32_t cookie)
{
return 1;
}
#else /* UDEV_SYNC_SUPPORT */ #else /* UDEV_SYNC_SUPPORT */
void dm_udev_set_sync_support(int sync_with_udev) void dm_udev_set_sync_support(int sync_with_udev)
@ -821,7 +817,8 @@ static int _get_cookie_sem(uint32_t cookie, int *semid)
if (!(cookie >> 16 & COOKIE_MAGIC)) { if (!(cookie >> 16 & COOKIE_MAGIC)) {
log_error("Could not continue to access notification " log_error("Could not continue to access notification "
"semaphore identified by cookie value %" "semaphore identified by cookie value %"
PRIu32 " (0x%x). Incorrect cookie prefix."); PRIu32 " (0x%x). Incorrect cookie prefix.",
cookie, cookie);
return 0; return 0;
} }
@ -952,7 +949,7 @@ static int _udev_notify_sem_create(uint32_t *cookie, int *semid)
log_error("semid %d: semctl failed: %s", gen_semid, strerror(errno)); log_error("semid %d: semctl failed: %s", gen_semid, strerror(errno));
/* We have to destroy just created semaphore /* We have to destroy just created semaphore
* so it won't stay in the system. */ * so it won't stay in the system. */
_udev_notify_sem_destroy(gen_semid, gen_cookie); (void) _udev_notify_sem_destroy(gen_semid, gen_cookie);
goto bad; goto bad;
} }
@ -996,6 +993,7 @@ int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie)
} }
dmt->event_nr = *cookie; dmt->event_nr = *cookie;
dmt->cookie_set = 1;
return 1; return 1;
bad: bad:
@ -1039,7 +1037,7 @@ int dm_udev_wait(uint32_t cookie)
"semaphore identified by cookie value %" PRIu32 " (0x%x) " "semaphore identified by cookie value %" PRIu32 " (0x%x) "
"to initialize waiting for incoming notifications.", "to initialize waiting for incoming notifications.",
cookie, cookie); cookie, cookie);
_udev_notify_sem_destroy(semid, cookie); (void) _udev_notify_sem_destroy(semid, cookie);
return 0; return 0;
} }
@ -1050,23 +1048,11 @@ repeat_wait:
log_error("Could not set wait state for notification semaphore " log_error("Could not set wait state for notification semaphore "
"identified by cookie value %" PRIu32 " (0x%x): %s", "identified by cookie value %" PRIu32 " (0x%x): %s",
cookie, cookie, strerror(errno)); cookie, cookie, strerror(errno));
_udev_notify_sem_destroy(semid, cookie); (void) _udev_notify_sem_destroy(semid, cookie);
return 0; return 0;
} }
return _udev_notify_sem_destroy(semid, cookie); return _udev_notify_sem_destroy(semid, cookie);
} }
int dm_udev_cleanup(uint32_t cookie)
{
int semid;
if (!cookie || !dm_udev_get_sync_support() || !dm_cookie_supported())
return 1;
if (!_get_cookie_sem(cookie, &semid))
return_0;
return _udev_notify_sem_destroy(semid, cookie);
}
#endif /* UDEV_SYNC_SUPPORT */ #endif /* UDEV_SYNC_SUPPORT */

View File

@ -845,9 +845,6 @@ static int _deactivate_node(const char *name, uint32_t major, uint32_t minor, ui
r = dm_task_run(dmt); r = dm_task_run(dmt);
if (!r)
(void) dm_udev_complete(*cookie);
/* FIXME Until kernel returns actual name so dm-ioctl.c can handle it */ /* FIXME Until kernel returns actual name so dm-ioctl.c can handle it */
rm_dev_node(name); rm_dev_node(name);
@ -888,9 +885,6 @@ static int _rename_node(const char *old_name, const char *new_name, uint32_t maj
r = dm_task_run(dmt); r = dm_task_run(dmt);
if (!r)
(void) dm_udev_complete(*cookie);
out: out:
dm_task_destroy(dmt); dm_task_destroy(dmt);
@ -934,8 +928,6 @@ static int _resume_node(const char *name, uint32_t major, uint32_t minor,
if ((r = dm_task_run(dmt))) if ((r = dm_task_run(dmt)))
r = dm_task_get_info(dmt, newinfo); r = dm_task_get_info(dmt, newinfo);
else
(void) dm_udev_complete(*cookie);
out: out:
dm_task_destroy(dmt); dm_task_destroy(dmt);

View File

@ -588,12 +588,8 @@ static int _create(int argc, char **argv, void *data __attribute((unused)))
dm_udev_set_sync_support(0); dm_udev_set_sync_support(0);
if (!dm_task_set_cookie(dmt, &cookie) || if (!dm_task_set_cookie(dmt, &cookie) ||
!dm_task_run(dmt)) { !dm_task_run(dmt))
(void) dm_udev_cleanup(cookie);
goto out; goto out;
}
(void) dm_udev_wait(cookie);
r = 1; r = 1;
@ -601,6 +597,7 @@ static int _create(int argc, char **argv, void *data __attribute((unused)))
r = _display_info(dmt); r = _display_info(dmt);
out: out:
(void) dm_udev_wait(cookie);
dm_task_destroy(dmt); dm_task_destroy(dmt);
return r; return r;
@ -626,16 +623,13 @@ static int _rename(int argc, char **argv, void *data __attribute((unused)))
goto out; goto out;
if (!dm_task_set_cookie(dmt, &cookie) || if (!dm_task_set_cookie(dmt, &cookie) ||
!dm_task_run(dmt)) { !dm_task_run(dmt))
(void) dm_udev_cleanup(cookie);
goto out; goto out;
}
(void) dm_udev_wait(cookie);
r = 1; r = 1;
out: out:
(void) dm_udev_wait(cookie);
dm_task_destroy(dmt); dm_task_destroy(dmt);
return r; return r;
@ -816,24 +810,18 @@ static int _simple(int task, const char *name, uint32_t event_nr, int display)
_read_ahead_flags)) _read_ahead_flags))
goto out; goto out;
if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie)) { if (udev_wait_flag && !dm_task_set_cookie(dmt, &cookie))
(void) dm_udev_cleanup(cookie);
goto out; goto out;
}
r = dm_task_run(dmt); r = dm_task_run(dmt);
if (udev_wait_flag) {
if (r)
(void) dm_udev_wait(cookie);
else
(void) dm_udev_cleanup(cookie);
}
if (r && display && _switches[VERBOSE_ARG]) if (r && display && _switches[VERBOSE_ARG])
r = _display_info(dmt); r = _display_info(dmt);
out: out:
if (udev_wait_flag)
(void) dm_udev_wait(cookie);
dm_task_destroy(dmt); dm_task_destroy(dmt);
return r; return r;
} }