5 #include <lustre_disk.h>
6 #include <lustre_ver.h>
8 #include <sys/utsname.h>
10 extern char *progname;
13 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
14 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
19 fprintf(stderr, "\n%s FATAL: ", progname);
22 int run_command(char *cmd, int cmdsz)
24 char log[] = "/tmp/run_command_logXXXXXX";
27 if ((cmdsz - strlen(cmd)) < 6) {
29 fprintf(stderr, "Command buffer overflow: %.*s...\n",
35 printf("cmd: %s\n", cmd);
37 if ((fd = mkstemp(log)) >= 0) {
45 /* Can't use popen because we need the rv of the command */
47 if (rc && (fd >= 0)) {
52 while (fgets(buf, sizeof(buf), fp) != NULL) {
63 int get_mountdata(char *dev, struct lustre_disk_data *mo_ldd)
66 char tmpdir[] = "/tmp/lustre_tmp.XXXXXX";
72 int cmdsz = sizeof(cmd);
74 /* Make a temporary directory to hold Lustre data files. */
75 if (!mkdtemp(tmpdir)) {
76 verrprint("%s: Can't create temporary directory %s: %s\n",
77 progname, tmpdir, strerror(errno));
81 snprintf(cmd, cmdsz, "/sbin/debugfs -c -R 'dump /%s %s/mountdata' %s",
82 MOUNT_DATA_FILE, tmpdir, dev);
84 ret = run_command(cmd, cmdsz);
86 verrprint("%s: Unable to dump %s dir (%d)\n",
87 progname, MOUNT_CONFIGS_DIR, ret);
91 sprintf(filepnm, "%s/mountdata", tmpdir);
92 filep = fopen(filepnm, "r");
94 vprint("Reading %s\n", MOUNT_DATA_FILE);
95 fread(mo_ldd, sizeof(*mo_ldd), 1, filep);
97 verrprint("%s: Unable to read %d.%d config %s.\n",
98 progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
106 snprintf(cmd, cmdsz, "rm -rf %s", tmpdir);
107 ret2 = run_command(cmd, cmdsz);
109 verrprint("Failed to remove temp dir %s (%d)\n", tmpdir, ret2);
110 /* failure return from run_command() is more important
111 * than the failure to remove a dir */
119 #define PARENT_URN "urn:uuid:2bb5bdbf-6c4b-11dc-9b8e-080020a9ed93"
120 #define PARENT_PRODUCT "Lustre"
122 static int stclient(char *type, char *arch)
131 if (strcmp(type, "Client") == 0)
133 else if (strcmp(type, "MDS") == 0)
135 else if (strcmp(type, "MGS") == 0)
137 else if (strcmp(type, "OSS") == 0)
140 snprintf(product, 64, "Lustre %s %d.%d.%d", type, LUSTRE_MAJOR,
141 LUSTRE_MINOR, LUSTRE_PATCH);
143 /* need to see if the entry exists first */
145 "/opt/sun/servicetag/bin/stclient -f -t '%s' ", urn);
146 fp = popen(cmd, "r");
149 fprintf(stderr, "%s: trying to run stclient -f: %s\n",
150 progname, strerror(errno));
154 i = fread(cmd, 1, sizeof(cmd), fp);
157 if (strcmp(cmd, "Record not found\n") != 0) {
158 /* exists, just return */
165 snprintf(cmd, 1024, "/opt/sun/servicetag/bin/stclient -a -p '%s' "
166 "-e %d.%d.%d -t '%s' -S mount -F '%s' -P '%s' -m SUN "
167 "-A %s -z global", product, LUSTRE_MAJOR, LUSTRE_MINOR,
168 LUSTRE_PATCH, urn, PARENT_URN, PARENT_PRODUCT, arch);
170 return(run_command(cmd, sizeof(cmd)));
173 void register_service_tags(char *usource, char *source, char *target)
175 struct lustre_disk_data mo_ldd;
176 struct utsname utsname_buf;
177 struct stat stat_buf;
178 char stclient_loc[] = "/opt/sun/servicetag/bin/stclient";
181 rc = stat(stclient_loc, &stat_buf);
184 /* call the service tags stclient to show that we use Lustre on
187 rc = uname(&utsname_buf);
191 "%s: trying to get uname failed: %s, "
192 "inventory tags will not be created\n",
193 progname, strerror(errno));
196 /* client or server? */
197 if (strchr(usource, ':')) {
198 stclient("Client", utsname_buf.machine);
200 /* first figure what type of device it is */
201 rc = get_mountdata(source, &mo_ldd);
205 "%s: trying to read mountdata from %s "
206 "failed: %s, inventory tags will not "
208 progname, target, strerror(errno));
212 stclient("MDS", utsname_buf.machine);
215 stclient("MGS", utsname_buf.machine);
218 stclient("OSS", utsname_buf.machine);
223 if (errno != ENOENT && verbose) {
225 "%s: trying to stat stclient failed: %s\n",
226 progname, strerror(errno));