Created
April 30, 2013 17:49
-
-
Save zachwalton/5490478 to your computer and use it in GitHub Desktop.
theoretically a way to interact with the asmlib ABI. written with a lot of help from this awesome article: http://www.scaleabilities.co.uk/2013/02/07/diagnosing-asmlib/ i'm uploading this as a gist because it is a proof of concept and not syntactically correct. i need a testing environment, which i don't have right now. usage: ./asm_release ASMX…
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
// | |
// asm_release.c | |
// | |
// Releases disks from ASM after removing them from a disk group by utilizing the | |
// oracleasm ABI. | |
// | |
// Usage: ./asm_release ASMXXXXXX | |
// - where ASMXXXXXX is the ASM disk name. | |
// | |
// Constructed with help from the following article: | |
// http://www.scaleabilities.co.uk/2013/02/07/diagnosing-asmlib/ | |
// | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <fcntl.h> | |
struct oracleasm_abi_info | |
{ | |
/*00*/ __u32 ai_magic; /* ASM_ABI_MAGIC */ | |
__u16 ai_version; /* ABI version */ | |
__u16 ai_type; /* Type of operation */ | |
__u32 ai_size; /* Size of passed struct */ | |
__u32 ai_status; /* Did it succeed */ | |
/*10*/ | |
}; | |
struct oracleasm_close_disk_v2 | |
{ | |
/*00*/ struct oracleasm_abi_info cd_abi; | |
/*10*/ __u64 cd_handle; | |
/*18*/ | |
}; | |
int main(int argc, char * argv[]) { | |
if (argc < 2) { | |
fprintf(stderr, "Usage: %s [asm device name].\n\n e.g. %s ASMXXXXXX\n", | |
argv[0], | |
argv[0]); | |
return 1; | |
} | |
int res, fd; | |
const char * path = "/dev/oracleasm/disks/" + argv[1]; | |
struct stat *buf = malloc(sizeof(struct stat)); | |
// Fetch the inode number for the device that we want to free. This is the | |
// handle that we end up passing to the oracleasm ABI. | |
res = stat(path, buf); | |
if (res == -1) { | |
fprintf(stderr, "Error opening file: %s", strerror(errno)); | |
return 1; | |
} | |
ino_t inode = buf.st_ino; | |
free(buf); | |
struct oracleasm_abi_info oabi = { | |
.ai_magic = strtoul("MSA\0"), | |
.ai_version = "\2\0", | |
.ai_type = "\06\0", // ASMOP_CLOSE_DISK | |
.ai_size = 18, // sizeof(oracleasm_close_disk_v2) | |
.ai_status = 0 | |
}; | |
struct oracleasm_close_disk_v2 cdv2 = { | |
.cd_abi = oabi, | |
.cd_handle = (__u64)inode | |
}; | |
// this needs to be replaced with code that determines the correct IID | |
fd = open("/dev/oracleasm/iid/0000000000000009") | |
if (fd == -1) { | |
fprintf(stderr, "Error opening file: %s", strerror(errno)); | |
return 1; | |
} | |
// This is the way that asmlib accepts operations from user space. | |
res = read(fd, (void *)cdv2, 80); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment