From 4abfd3816948fb7b30d211fbdfe3391e9d96c73f Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Tue, 26 Jun 2012 12:55:14 +0200 Subject: [PATCH] Remove open device debugging feature (no longer needed). --- ChangeLog | 1 + lib/Makefile.am | 1 - lib/internal.h | 1 - lib/libdevmapper.c | 2 - lib/utils_debug.c | 146 ----------------------------------------------------- 5 files changed, 1 insertion(+), 150 deletions(-) delete mode 100644 lib/utils_debug.c diff --git a/ChangeLog b/ChangeLog index 579dfc9..eb85f13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2012-06-25 Milan Broz * Add --device-size option for reencryption tool. * Switch to use unit suffix for --reduce-device-size option. + * Remove open device debugging feature (no longer needed). 2012-06-20 Milan Broz * Version 1.5.0-rc2. diff --git a/lib/Makefile.am b/lib/Makefile.am index 01c35f0..5da6a0e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -53,7 +53,6 @@ libcryptsetup_la_SOURCES = \ utils.c \ utils_crypt.c \ utils_crypt.h \ - utils_debug.c \ utils_loop.c \ utils_loop.h \ utils_devpath.c \ diff --git a/lib/internal.h b/lib/internal.h index dcf78e3..c39c7ce 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -94,7 +94,6 @@ void logger(struct crypt_device *cd, int class, const char *file, int line, cons #define log_err(c, x...) logger(c, CRYPT_LOG_ERROR, __FILE__, __LINE__, x) int crypt_get_debug_level(void); -void debug_processes_using_device(const char *name); int crypt_memlock_inc(struct crypt_device *ctx); int crypt_memlock_dec(struct crypt_device *ctx); diff --git a/lib/libdevmapper.c b/lib/libdevmapper.c index 7eaac7d..86bca48 100644 --- a/lib/libdevmapper.c +++ b/lib/libdevmapper.c @@ -437,8 +437,6 @@ int dm_remove_device(const char *name, int force, uint64_t size) if (--retries && r) { log_dbg("WARNING: other process locked internal device %s, %s.", name, retries ? "retrying remove" : "giving up"); - if (force && (crypt_get_debug_level() == CRYPT_LOG_DEBUG)) - debug_processes_using_device(name); sleep(1); if (force && !error_target) { /* If force flag is set, replace device with error, read-only target. diff --git a/lib/utils_debug.c b/lib/utils_debug.c deleted file mode 100644 index 83e1dc5..0000000 --- a/lib/utils_debug.c +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Temporary debug code to find processes locking internal cryptsetup devices. - * This code is intended to run only in debug mode. - * - * inspired by psmisc/fuser proc scanning code - * - * Copyright (C) 2009-2012, Red Hat, Inc. All rights reserved. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libcryptsetup.h" -#include "internal.h" - -#define MAX_PATHNAME 1024 -#define MAX_SHORTNAME 64 - -static int numeric_name(const char *name) -{ - return (name[0] < '0' || name[0] > '9') ? 0 : 1; -} - -static int check_pid(const pid_t pid, const char *dev_name, const char *short_dev_name) -{ - char dirpath[MAX_SHORTNAME], fdpath[MAX_SHORTNAME], linkpath[MAX_PATHNAME]; - DIR *dirp; - struct dirent *direntry; - ssize_t len; - int r = 0; - - snprintf(dirpath, sizeof(dirpath), "/proc/%d/fd", pid); - - if (!(dirp = opendir(dirpath))) - return r; - - while ((direntry = readdir(dirp))) { - if (!numeric_name(direntry->d_name)) - continue; - - snprintf(fdpath, sizeof(fdpath), "/proc/%d/fd/%s", pid, direntry->d_name); - - if ((len = readlink(fdpath, linkpath, MAX_PATHNAME-1)) < 0) - break; - linkpath[len] = '\0'; - - if (!strcmp(dev_name, linkpath)) { - r = 1; - break; - } - - if (!strcmp(short_dev_name, linkpath)) { - r = 2; - break; - } - } - closedir(dirp); - return r; -} - -static int read_proc_info(const pid_t pid, pid_t *ppid, char *name, int max_size) -{ - char path[MAX_SHORTNAME], info[max_size], c; - int fd, xpid, r = 0; - - snprintf(path, sizeof(path), "/proc/%u/stat", pid); - if ((fd = open(path, O_RDONLY)) < 0) - return 0; - - if (read(fd, info, max_size) > 0 && - sscanf(info, "%d %s %c %d", &xpid, name, &c, ppid) == 4) - r = 1; - - if (!r) { - *ppid = 0; - name[0] = '\0'; - } - close(fd); - return r; -} - -static void report_proc(const pid_t pid, const char *dev_name) -{ - char name[MAX_PATHNAME], name2[MAX_PATHNAME]; - pid_t ppid, ppid2; - - if (read_proc_info(pid, &ppid, name, MAX_PATHNAME) && - read_proc_info(ppid, &ppid2, name2, MAX_PATHNAME)) - log_dbg("WARNING: Process PID %u %s [PPID %u %s] spying on internal device %s.", - pid, name, ppid, name2, dev_name); -} - -void debug_processes_using_device(const char *dm_name) -{ - char short_dev_name[MAX_SHORTNAME], dev_name[MAX_PATHNAME]; - DIR *proc_dir; - struct dirent *proc_dentry; - struct stat st; - pid_t pid; - - if (crypt_get_debug_level() != CRYPT_LOG_DEBUG) - return; - - snprintf(dev_name, sizeof(dev_name), "/dev/mapper/%s", dm_name); - if (stat(dev_name, &st) || !S_ISBLK(st.st_mode)) - return; - snprintf(short_dev_name, sizeof(short_dev_name), "/dev/dm-%u", minor(st.st_rdev)); - - if (!(proc_dir = opendir("/proc"))) - return; - - while ((proc_dentry = readdir(proc_dir))) { - if (!numeric_name(proc_dentry->d_name)) - continue; - - pid = atoi(proc_dentry->d_name); - switch(check_pid(pid, dev_name, short_dev_name)) { - case 1: report_proc(pid, dev_name); - break; - case 2: report_proc(pid, short_dev_name); - default: - break; - } - } - closedir(proc_dir); -} -- 2.7.4