5 #include <lustre_disk.h>
6 #include <lustre_ver.h>
8 #include <sys/utsname.h>
10 extern char *progname;
13 #define vprint if (verbose > 0) printf
14 #define verrprint if (verbose >= 0) printf
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(stderr, "%s: Can't create temporary "
78 progname, tmpdir, strerror(errno));
82 snprintf(cmd, cmdsz, "/sbin/debugfs -c -R 'dump /%s %s/mountdata' %s",
83 MOUNT_DATA_FILE, tmpdir, dev);
85 ret = run_command(cmd, cmdsz);
87 verrprint("%s: Unable to dump %s dir (%d)\n",
88 progname, MOUNT_CONFIGS_DIR, ret);
92 sprintf(filepnm, "%s/mountdata", tmpdir);
93 filep = fopen(filepnm, "r");
95 vprint("Reading %s\n", MOUNT_DATA_FILE);
96 fread(mo_ldd, sizeof(*mo_ldd), 1, filep);
98 verrprint("%s: Unable to read %d.%d config %s.\n",
99 progname, LUSTRE_MAJOR, LUSTRE_MINOR, filepnm);
107 snprintf(cmd, cmdsz, "rm -rf %s", tmpdir);
108 ret2 = run_command(cmd, cmdsz);
110 verrprint("Failed to remove temp dir %s (%d)\n", tmpdir, ret2);
111 /* failure return from run_command() is more important
112 * than the failure to remove a dir */
120 #define PARENT_URN "urn:uuid:2bb5bdbf-6c4b-11dc-9b8e-080020a9ed93"
121 #define PARENT_PRODUCT "Lustre"
123 static int stclient(char *type, char *arch)
132 if (strcmp(type, "Client") == 0)
134 else if (strcmp(type, "MDS") == 0)
136 else if (strcmp(type, "MGS") == 0)
138 else if (strcmp(type, "OSS") == 0)
141 snprintf(product, 64, "Lustre %s %d.%d.%d", type, LUSTRE_MAJOR,
142 LUSTRE_MINOR, LUSTRE_PATCH);
144 /* need to see if the entry exists first */
146 "/opt/sun/servicetag/bin/stclient -f -t '%s' ", urn);
147 fp = popen(cmd, "r");
150 fprintf(stderr, "%s: trying to run stclient -f: %s\n",
151 progname, strerror(errno));
155 i = fread(cmd, 1, sizeof(cmd), fp);
158 if (strcmp(cmd, "Record not found\n") != 0) {
159 /* exists, just return */
166 snprintf(cmd, 1024, "/opt/sun/servicetag/bin/stclient -a -p '%s' "
167 "-e %d.%d.%d -t '%s' -S mount -F '%s' -P '%s' -m SUN "
168 "-A %s -z global", product, LUSTRE_MAJOR, LUSTRE_MINOR,
169 LUSTRE_PATCH, urn, PARENT_URN, PARENT_PRODUCT, arch);
171 return(run_command(cmd, sizeof(cmd)));
174 void register_service_tags(char *usource, char *source, char *target)
176 struct lustre_disk_data mo_ldd;
177 struct utsname utsname_buf;
178 struct stat stat_buf;
179 char stclient_loc[] = "/opt/sun/servicetag/bin/stclient";
182 rc = stat(stclient_loc, &stat_buf);
185 /* call the service tags stclient to show that we use Lustre on
188 rc = uname(&utsname_buf);
192 "%s: trying to get uname failed: %s, "
193 "inventory tags will not be created\n",
194 progname, strerror(errno));
197 /* client or server? */
198 if (strchr(usource, ':')) {
199 stclient("Client", utsname_buf.machine);
201 /* first figure what type of device it is */
202 rc = get_mountdata(source, &mo_ldd);
206 "%s: trying to read mountdata from %s "
207 "failed: %s, inventory tags will not "
209 progname, target, strerror(errno));
213 stclient("MDS", utsname_buf.machine);
216 stclient("MGS", utsname_buf.machine);
219 stclient("OSS", utsname_buf.machine);
224 if (errno != ENOENT && verbose) {
226 "%s: trying to stat stclient failed: %s\n",
227 progname, strerror(errno));