Whamcloud - gitweb
LU-4724 hsm: Safe copytool event logging
[fs/lustre-release.git] / lustre / utils / mount_utils.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  * Copyright (c) 2012, 2013, Intel Corporation.
30  */
31 /*
32  * This file is part of Lustre, http://www.lustre.org/
33  * Lustre is a trademark of Sun Microsystems, Inc.
34  */
35
36 #if HAVE_CONFIG_H
37 #  include "config.h"
38 #endif /* HAVE_CONFIG_H */
39
40 #include "mount_utils.h"
41 #include <stdio.h>
42 #include <errno.h>
43 #include <string.h>
44 #include <config.h>
45 #include <lustre_disk.h>
46 #include <lustre_ver.h>
47 #include <sys/stat.h>
48 #include <sys/utsname.h>
49 #include <linux/loop.h>
50
51 extern char *progname;
52 extern int verbose;
53
54 #define vprint(fmt, arg...) if (verbose > 0) printf(fmt, ##arg)
55 #define verrprint(fmt, arg...) if (verbose >= 0) fprintf(stderr, fmt, ##arg)
56
57 void fatal(void)
58 {
59         verbose = 0;
60         fprintf(stderr, "\n%s FATAL: ", progname);
61 }
62
63 int run_command(char *cmd, int cmdsz)
64 {
65         char log[] = "/tmp/run_command_logXXXXXX";
66         int fd = -1, rc;
67
68         if ((cmdsz - strlen(cmd)) < 6) {
69                 fatal();
70                 fprintf(stderr, "Command buffer overflow: %.*s...\n",
71                         cmdsz, cmd);
72                 return ENOMEM;
73         }
74
75         if (verbose > 1) {
76                 printf("cmd: %s\n", cmd);
77         } else {
78                 if ((fd = mkstemp(log)) >= 0) {
79                         close(fd);
80                         strcat(cmd, " >");
81                         strcat(cmd, log);
82                 }
83         }
84         strcat(cmd, " 2>&1");
85
86         /* Can't use popen because we need the rv of the command */
87         rc = system(cmd);
88         if (rc && (fd >= 0)) {
89                 char buf[128];
90                 FILE *fp;
91                 fp = fopen(log, "r");
92                 if (fp) {
93                         while (fgets(buf, sizeof(buf), fp) != NULL) {
94                                 printf("   %s", buf);
95                         }
96                         fclose(fp);
97                 }
98         }
99         if (fd >= 0)
100                 remove(log);
101         return rc;
102 }
103
104 int add_param(char *buf, char *key, char *val)
105 {
106         int end = sizeof(((struct lustre_disk_data *)0)->ldd_params);
107         int start = strlen(buf);
108         int keylen = 0;
109
110         if (key)
111                 keylen = strlen(key);
112         if (start + 1 + keylen + strlen(val) >= end) {
113                 fprintf(stderr, "%s: params are too long-\n%s %s%s\n",
114                         progname, buf, key ? key : "", val);
115                 return 1;
116         }
117
118         sprintf(buf + start, " %s%s", key ? key : "", val);
119         return 0;
120 }
121
122 int get_param(char *buf, char *key, char **val)
123 {
124         int i, key_len = strlen(key);
125         char *ptr;
126
127         ptr = strstr(buf, key);
128         if (ptr) {
129                 *val = strdup(ptr + key_len);
130                 if (*val == NULL)
131                         return ENOMEM;
132
133                 for (i = 0; i < strlen(*val); i++)
134                         if (((*val)[i] == ' ') || ((*val)[i] == '\0'))
135                                 break;
136
137                 (*val)[i] = '\0';
138                 return 0;
139         }
140
141         return ENOENT;
142 }
143
144 char *strscat(char *dst, char *src, int buflen)
145 {
146         dst[buflen - 1] = 0;
147         if (strlen(dst) + strlen(src) >= buflen) {
148                 fprintf(stderr, "string buffer overflow (max %d): '%s' + '%s'"
149                         "\n", buflen, dst, src);
150                 exit(EOVERFLOW);
151         }
152         return strcat(dst, src);
153 }
154
155 char *strscpy(char *dst, char *src, int buflen)
156 {
157         dst[0] = 0;
158         return strscat(dst, src, buflen);
159 }
160
161 int check_mtab_entry(char *spec1, char *spec2, char *mtpt, char *type)
162 {
163         FILE *fp;
164         struct mntent *mnt;
165
166         fp = setmntent(MOUNTED, "r");
167         if (fp == NULL)
168                 return 0;
169
170         while ((mnt = getmntent(fp)) != NULL) {
171                 if ((strcmp(mnt->mnt_fsname, spec1) == 0 ||
172                      strcmp(mnt->mnt_fsname, spec2) == 0) &&
173                     (mtpt == NULL || strcmp(mnt->mnt_dir, mtpt) == 0) &&
174                     (type == NULL || strcmp(mnt->mnt_type, type) == 0)) {
175                         endmntent(fp);
176                         return(EEXIST);
177                 }
178         }
179         endmntent(fp);
180
181         return 0;
182 }
183
184 #define PROC_DIR        "/proc/"
185 static int mtab_is_proc(const char *mtab)
186 {
187         char path[16];
188
189         if (readlink(mtab, path, sizeof(path)) < 0)
190                 return 0;
191
192         if (strncmp(path, PROC_DIR, strlen(PROC_DIR)))
193                 return 0;
194
195         return 1;
196 }
197
198 int update_mtab_entry(char *spec, char *mtpt, char *type, char *opts,
199                 int flags, int freq, int pass)
200 {
201         FILE *fp;
202         struct mntent mnt;
203         int rc = 0;
204
205         /* Don't update mtab if it is linked to any file in /proc direcotry.*/
206         if (mtab_is_proc(MOUNTED))
207                 return 0;
208
209         mnt.mnt_fsname = spec;
210         mnt.mnt_dir = mtpt;
211         mnt.mnt_type = type;
212         mnt.mnt_opts = opts ? opts : "";
213         mnt.mnt_freq = freq;
214         mnt.mnt_passno = pass;
215
216         fp = setmntent(MOUNTED, "a+");
217         if (fp == NULL) {
218                 fprintf(stderr, "%s: setmntent(%s): %s:",
219                         progname, MOUNTED, strerror (errno));
220                 rc = 16;
221         } else {
222                 if ((addmntent(fp, &mnt)) == 1) {
223                         fprintf(stderr, "%s: addmntent: %s:",
224                                 progname, strerror (errno));
225                         rc = 16;
226                 }
227                 endmntent(fp);
228         }
229
230         return rc;
231 }
232
233 /* Search for opt in mntlist, returning true if found.
234  */
235 static int in_mntlist(char *opt, char *mntlist)
236 {
237         char *ml, *mlp, *item, *ctx = NULL;
238
239         if (!(ml = strdup(mntlist))) {
240                 fprintf(stderr, "%s: out of memory\n", progname);
241                 exit(1);
242         }
243         mlp = ml;
244         while ((item = strtok_r(mlp, ",", &ctx))) {
245                 if (!strcmp(opt, item))
246                         break;
247                 mlp = NULL;
248         }
249         free(ml);
250         return (item != NULL);
251 }
252
253 /* Issue a message on stderr for every item in wanted_mountopts that is not
254  * present in mountopts.  The justwarn boolean toggles between error and
255  * warning message.  Return an error count.
256  */
257 int check_mountfsoptions(char *mountopts, char *wanted_mountopts,
258                          int justwarn)
259 {
260         char *ml, *mlp, *item, *ctx = NULL;
261         int errors = 0;
262
263         if (!(ml = strdup(wanted_mountopts))) {
264                 fprintf(stderr, "%s: out of memory\n", progname);
265                 exit(1);
266         }
267         mlp = ml;
268         while ((item = strtok_r(mlp, ",", &ctx))) {
269                 if (!in_mntlist(item, mountopts)) {
270                         fprintf(stderr, "%s: %s mount option `%s' is missing\n",
271                                 progname, justwarn ? "Warning: default"
272                                 : "Error: mandatory", item);
273                         errors++;
274                 }
275                 mlp = NULL;
276         }
277         free(ml);
278         return errors;
279 }
280
281 /* Trim embedded white space, leading and trailing commas from string s.
282  */
283 void trim_mountfsoptions(char *s)
284 {
285         char *p;
286
287         for (p = s; *p; ) {
288                 if (isspace(*p)) {
289                         memmove(p, p + 1, strlen(p + 1) + 1);
290                         continue;
291                 }
292                 p++;
293         }
294
295         while (s[0] == ',')
296                 memmove(&s[0], &s[1], strlen(&s[1]) + 1);
297
298         p = s + strlen(s) - 1;
299         while (p >= s && *p == ',')
300                 *p-- = '\0';
301 }
302
303 /* Setup a file in the first unused loop_device */
304 int loop_setup(struct mkfs_opts *mop)
305 {
306         char loop_base[20];
307         char l_device[64];
308         int i, ret = 0;
309
310         /* Figure out the loop device names */
311         if (!access("/dev/loop0", F_OK | R_OK) ||
312             !access("/dev/loop-control", F_OK | R_OK)) {
313                 strcpy(loop_base, "/dev/loop\0");
314         } else if (!access("/dev/loop/0", F_OK | R_OK)) {
315                 strcpy(loop_base, "/dev/loop/\0");
316         } else {
317                 fprintf(stderr, "%s: can't access loop devices\n", progname);
318                 return EACCES;
319         }
320
321         /* Find unused loop device */
322         for (i = 0; i < MAX_LOOP_DEVICES; i++) {
323                 char cmd[PATH_MAX];
324                 int cmdsz = sizeof(cmd);
325
326 #ifdef LOOP_CTL_GET_FREE
327                 ret = open("/dev/loop-control", O_RDWR);
328                 if (ret < 0) {
329                         fprintf(stderr, "%s: can't access loop control\n", progname);
330                         return EACCES;
331                 }
332                 /* find or allocate a free loop device to use */
333                 i = ioctl(ret, LOOP_CTL_GET_FREE);
334                 if (i < 0) {
335                         fprintf(stderr, "%s: access loop control error\n", progname);
336                         return EACCES;
337                 }
338                 sprintf(l_device, "%s%d", loop_base, i);
339 #else
340                 sprintf(l_device, "%s%d", loop_base, i);
341                 if (access(l_device, F_OK | R_OK))
342                         break;
343 #endif
344                 snprintf(cmd, cmdsz, "losetup %s > /dev/null 2>&1", l_device);
345                 ret = system(cmd);
346
347                 /* losetup gets 1 (ret=256) for non-set-up device */
348                 if (ret) {
349                         /* Set up a loopback device to our file */
350                         snprintf(cmd, cmdsz, "losetup %s %s", l_device,
351                                  mop->mo_device);
352                         ret = run_command(cmd, cmdsz);
353                         if (ret == 256)
354                                 /* someone else picked up this loop device
355                                  * behind our back */
356                                 continue;
357                         if (ret) {
358                                 fprintf(stderr, "%s: error %d on losetup: %s\n",
359                                         progname, ret,
360                                         ret >= 0 ? strerror(ret) : "");
361                                 return ret;
362                         }
363                         strscpy(mop->mo_loopdev, l_device,
364                                 sizeof(mop->mo_loopdev));
365                         return ret;
366                 }
367         }
368
369         fprintf(stderr, "%s: out of loop devices!\n", progname);
370         return EMFILE;
371 }
372
373 int loop_cleanup(struct mkfs_opts *mop)
374 {
375         char cmd[150];
376         int ret = 0;
377
378         if ((mop->mo_flags & MO_IS_LOOP) && *mop->mo_loopdev) {
379                 int tries;
380
381                 sprintf(cmd, "losetup -d %s", mop->mo_loopdev);
382                 for (tries = 0; tries < 3; tries++) {
383                         ret = run_command(cmd, sizeof(cmd));
384                         if (ret == 0)
385                                 break;
386                         sleep(1);
387                 }
388         }
389
390         if (ret != 0)
391                 fprintf(stderr, "cannot cleanup %s: rc = %d\n",
392                         mop->mo_loopdev, ret);
393         return ret;
394 }
395
396 int loop_format(struct mkfs_opts *mop)
397 {
398         int fd;
399
400         if (mop->mo_device_kb == 0) {
401                 fatal();
402                 fprintf(stderr, "loop device requires a --device-size= "
403                         "param\n");
404                 return EINVAL;
405         }
406
407         fd = creat(mop->mo_device, S_IRUSR|S_IWUSR);
408         if (fd < 0) {
409                 fatal();
410                 fprintf(stderr, "%s: Unable to create backing store: %s\n",
411                         progname, strerror(errno));
412                 return errno;
413         }
414
415         if (ftruncate(fd, mop->mo_device_kb * 1024) != 0) {
416                 close(fd);
417                 fatal();
418                 fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
419                         progname, strerror(errno));
420                 return errno;
421         }
422
423         close(fd);
424         return 0;
425 }
426
427 /* Write the server config files */
428 int osd_write_ldd(struct mkfs_opts *mop)
429 {
430         struct lustre_disk_data *ldd = &mop->mo_ldd;
431         int ret;
432
433         switch (ldd->ldd_mount_type) {
434 #ifdef HAVE_LDISKFS_OSD
435         case LDD_MT_LDISKFS:
436         case LDD_MT_LDISKFS2:
437                 ret = ldiskfs_write_ldd(mop);
438                 break;
439 #endif /* HAVE_LDISKFS_OSD */
440 #ifdef HAVE_ZFS_OSD
441         case LDD_MT_ZFS:
442                 ret = zfs_write_ldd(mop);
443                 break;
444 #endif /* HAVE_ZFS_OSD */
445         default:
446                 fatal();
447                 fprintf(stderr, "unknown fs type %d '%s'\n",
448                         ldd->ldd_mount_type, MT_STR(ldd));
449                 ret = EINVAL;
450                 break;
451         }
452
453         return ret;
454 }
455
456 /* Read the server config files */
457 int osd_read_ldd(char *dev, struct lustre_disk_data *ldd)
458 {
459         int ret;
460
461         switch (ldd->ldd_mount_type) {
462 #ifdef HAVE_LDISKFS_OSD
463         case LDD_MT_LDISKFS:
464         case LDD_MT_LDISKFS2:
465                 ret = ldiskfs_read_ldd(dev, ldd);
466                 break;
467 #endif /* HAVE_LDISKFS_OSD */
468 #ifdef HAVE_ZFS_OSD
469         case LDD_MT_ZFS:
470                 ret = zfs_read_ldd(dev, ldd);
471                 break;
472 #endif /* HAVE_ZFS_OSD */
473         default:
474                 fatal();
475                 fprintf(stderr, "unknown fs type %d '%s'\n",
476                         ldd->ldd_mount_type, MT_STR(ldd));
477                 ret = EINVAL;
478                 break;
479         }
480
481         return ret;
482 }
483
484 /* Was this device formatted for Lustre */
485 int osd_is_lustre(char *dev, unsigned *mount_type)
486 {
487         vprint("checking for existing Lustre data: ");
488
489 #ifdef HAVE_LDISKFS_OSD
490         if (ldiskfs_is_lustre(dev, mount_type)) {
491                 vprint("found\n");
492                 return 1;
493         }
494 #endif /* HAVE_LDISKFS_OSD */
495 #ifdef HAVE_ZFS_OSD
496         if (zfs_is_lustre(dev, mount_type)) {
497                 vprint("found\n");
498                 return 1;
499         }
500 #endif /* HAVE_ZFS_OSD */
501
502         vprint("not found\n");
503         return 0;
504 }
505
506 /* Build fs according to type */
507 int osd_make_lustre(struct mkfs_opts *mop)
508 {
509         struct lustre_disk_data *ldd = &mop->mo_ldd;
510         int ret;
511
512         switch (ldd->ldd_mount_type) {
513 #ifdef HAVE_LDISKFS_OSD
514         case LDD_MT_LDISKFS:
515         case LDD_MT_LDISKFS2:
516                 ret = ldiskfs_make_lustre(mop);
517                 break;
518 #endif /* HAVE_LDISKFS_OSD */
519 #ifdef HAVE_ZFS_OSD
520         case LDD_MT_ZFS:
521                 ret = zfs_make_lustre(mop);
522                 break;
523 #endif /* HAVE_ZFS_OSD */
524         default:
525                 fatal();
526                 fprintf(stderr, "unknown fs type %d '%s'\n",
527                         ldd->ldd_mount_type, MT_STR(ldd));
528                 ret = EINVAL;
529                 break;
530         }
531
532         return ret;
533 }
534
535 int osd_prepare_lustre(struct mkfs_opts *mop,
536                 char *default_mountopts, int default_len,
537                 char *always_mountopts, int always_len)
538 {
539         struct lustre_disk_data *ldd = &mop->mo_ldd;
540         int ret;
541
542         switch (ldd->ldd_mount_type) {
543 #ifdef HAVE_LDISKFS_OSD
544         case LDD_MT_LDISKFS:
545         case LDD_MT_LDISKFS2:
546                 ret = ldiskfs_prepare_lustre(mop,
547                                              default_mountopts, default_len,
548                                              always_mountopts, always_len);
549                 break;
550 #endif /* HAVE_LDISKFS_OSD */
551 #ifdef HAVE_ZFS_OSD
552         case LDD_MT_ZFS:
553                 ret = zfs_prepare_lustre(mop,
554                                          default_mountopts, default_len,
555                                          always_mountopts, always_len);
556                 break;
557 #endif /* HAVE_ZFS_OSD */
558         default:
559                 fatal();
560                 fprintf(stderr, "unknown fs type %d '%s'\n",
561                         ldd->ldd_mount_type, MT_STR(ldd));
562                 ret = EINVAL;
563                 break;
564         }
565
566         return ret;
567 }
568
569 int osd_tune_lustre(char *dev, struct mount_opts *mop)
570 {
571         struct lustre_disk_data *ldd = &mop->mo_ldd;
572         int ret;
573
574         switch (ldd->ldd_mount_type) {
575 #ifdef HAVE_LDISKFS_OSD
576         case LDD_MT_LDISKFS:
577         case LDD_MT_LDISKFS2:
578                 ret = ldiskfs_tune_lustre(dev, mop);
579                 break;
580 #endif /* HAVE_LDISKFS_OSD */
581 #ifdef HAVE_ZFS_OSD
582         case LDD_MT_ZFS:
583                 ret = zfs_tune_lustre(dev, mop);
584                 break;
585 #endif /* HAVE_ZFS_OSD */
586         default:
587                 fatal();
588                 fprintf(stderr, "unknown fs type %d '%s'\n",
589                                 ldd->ldd_mount_type, MT_STR(ldd));
590                 ret = EINVAL;
591                 break;
592         }
593
594         return ret;
595 }
596
597 int osd_label_lustre(struct mount_opts *mop)
598 {
599         struct lustre_disk_data *ldd = &mop->mo_ldd;
600         int ret;
601
602         switch (ldd->ldd_mount_type) {
603 #ifdef HAVE_LDISKFS_OSD
604         case LDD_MT_LDISKFS:
605         case LDD_MT_LDISKFS2:
606                 ret = ldiskfs_label_lustre(mop);
607                 break;
608 #endif /* HAVE_LDISKFS_OSD */
609 #ifdef HAVE_ZFS_OSD
610         case LDD_MT_ZFS:
611                 ret = zfs_label_lustre(mop);
612                 break;
613 #endif /* HAVE_ZFS_OSD */
614         default:
615                 fatal();
616                 fprintf(stderr, "unknown fs type %d '%s'\n",
617                         ldd->ldd_mount_type, MT_STR(ldd));
618                 ret = EINVAL;
619                 break;
620         }
621
622         return ret;
623 }
624
625 /* Enable quota accounting */
626 int osd_enable_quota(struct mkfs_opts *mop)
627 {
628         struct lustre_disk_data *ldd = &mop->mo_ldd;
629         int ret;
630
631         switch (ldd->ldd_mount_type) {
632 #ifdef HAVE_LDISKFS_OSD
633         case LDD_MT_EXT3:
634         case LDD_MT_LDISKFS:
635         case LDD_MT_LDISKFS2:
636                 ret = ldiskfs_enable_quota(mop);
637                 break;
638 #endif /* HAVE_LDISKFS_OSD */
639 #ifdef HAVE_ZFS_OSD
640         case LDD_MT_ZFS:
641                 fprintf(stderr, "this option is only valid for ldiskfs\n");
642                 ret = EINVAL;
643                 break;
644 #endif /* HAVE_ZFS_OSD */
645         default:
646                 fatal();
647                 fprintf(stderr, "unknown fs type %d '%s'\n",
648                         ldd->ldd_mount_type, MT_STR(ldd));
649                 ret = EINVAL;
650                 break;
651         }
652
653         return ret;
654 }
655
656 int osd_init(void)
657 {
658         int ret = 0;
659
660 #ifdef HAVE_LDISKFS_OSD
661         ret = ldiskfs_init();
662         if (ret)
663                 return ret;
664 #endif /* HAVE_LDISKFS_OSD */
665 #ifdef HAVE_ZFS_OSD
666         ret = zfs_init();
667         /* we want to be able to set up a ldiskfs-based filesystem w/o
668          * the ZFS modules installed, see ORI-425 */
669         if (ret)
670                 ret = 0;
671 #endif /* HAVE_ZFS_OSD */
672
673         return ret;
674 }
675
676 void osd_fini(void)
677 {
678 #ifdef HAVE_LDISKFS_OSD
679         ldiskfs_fini();
680 #endif /* HAVE_LDISKFS_OSD */
681 #ifdef HAVE_ZFS_OSD
682         zfs_fini();
683 #endif /* HAVE_ZFS_OSD */
684 }
685
686 __u64 get_device_size(char* device)
687 {
688         int ret, fd;
689         __u64 size = 0;
690
691         fd = open(device, O_RDONLY);
692         if (fd < 0) {
693                 fprintf(stderr, "%s: cannot open %s: %s\n",
694                         progname, device, strerror(errno));
695                 return 0;
696         }
697
698 #ifdef BLKGETSIZE64
699         /* size in bytes. bz5831 */
700         ret = ioctl(fd, BLKGETSIZE64, (void*)&size);
701 #else
702         {
703                 __u32 lsize = 0;
704                 /* size in blocks */
705                 ret = ioctl(fd, BLKGETSIZE, (void*)&lsize);
706                 size = (__u64)lsize * 512;
707         }
708 #endif
709         close(fd);
710         if (ret < 0) {
711                 fprintf(stderr, "%s: size ioctl failed: %s\n",
712                         progname, strerror(errno));
713                 return 0;
714         }
715
716         vprint("device size = "LPU64"MB\n", size >> 20);
717         /* return value in KB */
718         return size >> 10;
719 }
720
721 int file_create(char *path, __u64 size)
722 {
723         __u64 size_max;
724         int ret;
725         int fd;
726
727         /*
728          * Since "size" is in KB, the file offset it represents could overflow
729          * off_t.
730          */
731         size_max = (off_t)1 << (_FILE_OFFSET_BITS - 1 - 10);
732         if (size >= size_max) {
733                 fprintf(stderr, "%s: "LPU64" KB: Backing store size must be "
734                         "smaller than "LPU64" KB\n", progname, size, size_max);
735                 return EFBIG;
736         }
737
738         ret = access(path, F_OK);
739         if (ret == 0) {
740                 ret = unlink(path);
741                 if (ret != 0)
742                         return errno;
743         }
744
745         fd = creat(path, S_IRUSR|S_IWUSR);
746         if (fd < 0) {
747                 fatal();
748                 fprintf(stderr, "%s: Unable to create backing store: %s\n",
749                         progname, strerror(errno));
750                 return errno;
751         }
752
753         ret = ftruncate(fd, size * 1024);
754         close(fd);
755         if (ret != 0) {
756                 fatal();
757                 fprintf(stderr, "%s: Unable to truncate backing store: %s\n",
758                         progname, strerror(errno));
759                 return errno;
760         }
761
762         return 0;
763 }