-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ubuntu-host is a module for providing data to containers via proc. Initially it is populated with a single file, esm-token, for supplying ESM access tokens. Signed-off-by: Seth Forshee <seth.forshee@canonical.com>
- Loading branch information
Seth Forshee
authored and
Andrea Righi
committed
Dec 15, 2020
1 parent
1887e71
commit cab29ff
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,10 @@ source "ubuntu/hio/Kconfig" | |
## | ||
## | ||
## | ||
source "ubuntu/ubuntu-host/Kconfig" | ||
## | ||
## | ||
## | ||
## | ||
## | ||
## | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
config UBUNTU_HOST | ||
tristate "proc dir for exporting host data to containers" | ||
help | ||
Creates an ubuntu-host directory in proc for providing data from | ||
Ubuntu hosts to containers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
obj-$(CONFIG_UBUNTU_HOST) += ubuntu-host.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <linux/uaccess.h> | ||
#include <linux/module.h> | ||
#include <linux/kernel.h> | ||
#include <linux/proc_fs.h> | ||
#include <asm/uaccess.h> | ||
|
||
#define PROC_DIR "ubuntu-host" | ||
|
||
#define ESM_TOKEN_FILE "esm-token" | ||
#define ESM_TOKEN_MAX_SIZE 64 | ||
|
||
static struct proc_dir_entry *proc_dir; | ||
static char esm_token_buffer[ESM_TOKEN_MAX_SIZE]; | ||
|
||
static ssize_t esm_token_read(struct file *f, char __user *buf, size_t len, | ||
loff_t *off) | ||
{ | ||
return simple_read_from_buffer(buf, len, off, esm_token_buffer, | ||
strlen(esm_token_buffer)); | ||
} | ||
|
||
static ssize_t esm_token_write(struct file *f, const char __user *buf, | ||
size_t len, loff_t *off) | ||
{ | ||
ssize_t ret; | ||
|
||
if (len >= ESM_TOKEN_MAX_SIZE - 1) | ||
return -EINVAL; | ||
|
||
ret = simple_write_to_buffer(esm_token_buffer, ESM_TOKEN_MAX_SIZE - 1, | ||
off, buf, len); | ||
if (ret >= 0) | ||
esm_token_buffer[ret] = '\0'; | ||
|
||
return ret; | ||
} | ||
|
||
static const struct proc_ops esm_token_fops = { | ||
.proc_read = esm_token_read, | ||
.proc_write = esm_token_write, | ||
}; | ||
|
||
static void ubuntu_host_cleanup(void) | ||
{ | ||
remove_proc_entry(ESM_TOKEN_FILE, proc_dir); | ||
proc_remove(proc_dir); | ||
} | ||
|
||
static int __init ubuntu_host_init(void) | ||
{ | ||
proc_dir = proc_mkdir(PROC_DIR, NULL); | ||
if (!proc_dir) { | ||
pr_err("Failed to create ubuntu-host dir\n"); | ||
return -ENOMEM; | ||
} | ||
|
||
if (!proc_create_data(ESM_TOKEN_FILE, 0644, proc_dir, &esm_token_fops, NULL)) { | ||
pr_err("Failed to create esm-tokan file\n"); | ||
ubuntu_host_cleanup(); | ||
return -ENOMEM; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
module_init(ubuntu_host_init); | ||
module_exit(ubuntu_host_cleanup); | ||
MODULE_LICENSE("GPL"); |