Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107164580
D34068.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D34068.diff
View Options
diff --git a/sys/kern/kern_shutdown.c b/sys/kern/kern_shutdown.c
--- a/sys/kern/kern_shutdown.c
+++ b/sys/kern/kern_shutdown.c
@@ -1212,45 +1212,39 @@
}
/*
- * Must not be present on global list.
+ * Free a dumper. Must not be present on global list.
*/
-static void
-free_single_dumper(struct dumperinfo *di)
+void
+dumper_destroy(struct dumperinfo *di)
{
if (di == NULL)
return;
zfree(di->blockbuf, M_DUMPER);
-
kerneldumpcomp_destroy(di);
-
#ifdef EKCD
zfree(di->kdcrypto, M_EKCD);
#endif
zfree(di, M_DUMPER);
}
-/* Registration of dumpers */
+/*
+ * Allocate and set up a new dumper from the provided template.
+ */
int
-dumper_insert(const struct dumperinfo *di_template, const char *devname,
- const struct diocskerneldump_arg *kda)
+dumper_create(const struct dumperinfo *di_template, const char *devname,
+ const struct diocskerneldump_arg *kda, struct dumperinfo **dip)
{
- struct dumperinfo *newdi, *listdi;
- bool inserted;
- uint8_t index;
- int error;
+ struct dumperinfo *newdi;
+ int error = 0;
- index = kda->kda_index;
- MPASS(index != KDA_REMOVE && index != KDA_REMOVE_DEV &&
- index != KDA_REMOVE_ALL);
-
- error = priv_check(curthread, PRIV_SETDUMPER);
- if (error != 0)
- return (error);
+ if (dip == NULL)
+ return (EINVAL);
- newdi = malloc(sizeof(*newdi) + strlen(devname) + 1, M_DUMPER, M_WAITOK
- | M_ZERO);
+ /* Allocate a new dumper */
+ newdi = malloc(sizeof(*newdi) + strlen(devname) + 1, M_DUMPER,
+ M_WAITOK | M_ZERO);
memcpy(newdi, di_template, sizeof(*newdi));
newdi->blockbuf = NULL;
newdi->kdcrypto = NULL;
@@ -1259,7 +1253,7 @@
if (kda->kda_encryption != KERNELDUMP_ENC_NONE) {
#ifdef EKCD
- newdi->kdcrypto = kerneldumpcrypto_create(di_template->blocksize,
+ newdi->kdcrypto = kerneldumpcrypto_create(newdi->blocksize,
kda->kda_encryption, kda->kda_key,
kda->kda_encryptedkeysize, kda->kda_encryptedkey);
if (newdi->kdcrypto == NULL) {
@@ -1291,9 +1285,39 @@
goto cleanup;
}
}
-
newdi->blockbuf = malloc(newdi->blocksize, M_DUMPER, M_WAITOK | M_ZERO);
+ *dip = newdi;
+ return (0);
+cleanup:
+ dumper_destroy(newdi);
+ return (error);
+}
+
+/*
+ * Create a new dumper and register it in the global list.
+ */
+int
+dumper_insert(const struct dumperinfo *di_template, const char *devname,
+ const struct diocskerneldump_arg *kda)
+{
+ struct dumperinfo *newdi, *listdi;
+ bool inserted;
+ uint8_t index;
+ int error;
+
+ index = kda->kda_index;
+ MPASS(index != KDA_REMOVE && index != KDA_REMOVE_DEV &&
+ index != KDA_REMOVE_ALL);
+
+ error = priv_check(curthread, PRIV_SETDUMPER);
+ if (error != 0)
+ return (error);
+
+ error = dumper_create(di_template, devname, kda, &newdi);
+ if (error != 0)
+ return (error);
+
/* Add the new configuration to the queue */
mtx_lock(&dumpconf_list_lk);
inserted = false;
@@ -1310,10 +1334,6 @@
mtx_unlock(&dumpconf_list_lk);
return (0);
-
-cleanup:
- free_single_dumper(newdi);
- return (error);
}
#ifdef DDB
@@ -1368,6 +1388,9 @@
return (true);
}
+/*
+ * Remove and free the requested dumper(s) from the global list.
+ */
int
dumper_remove(const char *devname, const struct diocskerneldump_arg *kda)
{
@@ -1391,7 +1414,7 @@
if (dumper_config_match(di, devname, kda)) {
found = true;
TAILQ_REMOVE(&dumper_configs, di, di_next);
- free_single_dumper(di);
+ dumper_destroy(di);
}
}
mtx_unlock(&dumpconf_list_lk);
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
--- a/sys/sys/conf.h
+++ b/sys/sys/conf.h
@@ -364,6 +364,9 @@
int doadump(boolean_t);
struct diocskerneldump_arg;
+int dumper_create(const struct dumperinfo *di_template, const char *devname,
+ const struct diocskerneldump_arg *kda, struct dumperinfo **dip);
+void dumper_destroy(struct dumperinfo *di);
int dumper_insert(const struct dumperinfo *di_template, const char *devname,
const struct diocskerneldump_arg *kda);
int dumper_remove(const char *devname, const struct diocskerneldump_arg *kda);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 12, 2:55 AM (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15760356
Default Alt Text
D34068.diff (3 KB)
Attached To
Mode
D34068: Split out dumper allocation from list insertion
Attached
Detach File
Event Timeline
Log In to Comment