mount.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/gfs2_ondisk.h>
  14. #include <linux/lm_interface.h>
  15. #include <linux/parser.h>
  16. #include "gfs2.h"
  17. #include "incore.h"
  18. #include "mount.h"
  19. #include "sys.h"
  20. #include "util.h"
  21. enum {
  22. Opt_lockproto,
  23. Opt_locktable,
  24. Opt_hostdata,
  25. Opt_spectator,
  26. Opt_ignore_local_fs,
  27. Opt_localflocks,
  28. Opt_localcaching,
  29. Opt_debug,
  30. Opt_nodebug,
  31. Opt_upgrade,
  32. Opt_acl,
  33. Opt_noacl,
  34. Opt_quota_off,
  35. Opt_quota_account,
  36. Opt_quota_on,
  37. Opt_suiddir,
  38. Opt_nosuiddir,
  39. Opt_data_writeback,
  40. Opt_data_ordered,
  41. Opt_meta,
  42. Opt_err,
  43. };
  44. static const match_table_t tokens = {
  45. {Opt_lockproto, "lockproto=%s"},
  46. {Opt_locktable, "locktable=%s"},
  47. {Opt_hostdata, "hostdata=%s"},
  48. {Opt_spectator, "spectator"},
  49. {Opt_ignore_local_fs, "ignore_local_fs"},
  50. {Opt_localflocks, "localflocks"},
  51. {Opt_localcaching, "localcaching"},
  52. {Opt_debug, "debug"},
  53. {Opt_nodebug, "nodebug"},
  54. {Opt_upgrade, "upgrade"},
  55. {Opt_acl, "acl"},
  56. {Opt_noacl, "noacl"},
  57. {Opt_quota_off, "quota=off"},
  58. {Opt_quota_account, "quota=account"},
  59. {Opt_quota_on, "quota=on"},
  60. {Opt_suiddir, "suiddir"},
  61. {Opt_nosuiddir, "nosuiddir"},
  62. {Opt_data_writeback, "data=writeback"},
  63. {Opt_data_ordered, "data=ordered"},
  64. {Opt_meta, "meta"},
  65. {Opt_err, NULL}
  66. };
  67. /**
  68. * gfs2_mount_args - Parse mount options
  69. * @sdp:
  70. * @data:
  71. *
  72. * Return: errno
  73. */
  74. int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
  75. {
  76. struct gfs2_args *args = &sdp->sd_args;
  77. char *data = data_arg;
  78. char *options, *o, *v;
  79. int error = 0;
  80. if (!remount) {
  81. /* Set some defaults */
  82. args->ar_quota = GFS2_QUOTA_DEFAULT;
  83. args->ar_data = GFS2_DATA_DEFAULT;
  84. }
  85. /* Split the options into tokens with the "," character and
  86. process them */
  87. for (options = data; (o = strsep(&options, ",")); ) {
  88. int token;
  89. substring_t tmp[MAX_OPT_ARGS];
  90. if (!*o)
  91. continue;
  92. token = match_token(o, tokens, tmp);
  93. switch (token) {
  94. case Opt_lockproto:
  95. v = match_strdup(&tmp[0]);
  96. if (!v) {
  97. fs_info(sdp, "no memory for lockproto\n");
  98. error = -ENOMEM;
  99. goto out_error;
  100. }
  101. if (remount && strcmp(v, args->ar_lockproto)) {
  102. kfree(v);
  103. goto cant_remount;
  104. }
  105. strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
  106. args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
  107. kfree(v);
  108. break;
  109. case Opt_locktable:
  110. v = match_strdup(&tmp[0]);
  111. if (!v) {
  112. fs_info(sdp, "no memory for locktable\n");
  113. error = -ENOMEM;
  114. goto out_error;
  115. }
  116. if (remount && strcmp(v, args->ar_locktable)) {
  117. kfree(v);
  118. goto cant_remount;
  119. }
  120. strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
  121. args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
  122. kfree(v);
  123. break;
  124. case Opt_hostdata:
  125. v = match_strdup(&tmp[0]);
  126. if (!v) {
  127. fs_info(sdp, "no memory for hostdata\n");
  128. error = -ENOMEM;
  129. goto out_error;
  130. }
  131. if (remount && strcmp(v, args->ar_hostdata)) {
  132. kfree(v);
  133. goto cant_remount;
  134. }
  135. strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
  136. args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
  137. kfree(v);
  138. break;
  139. case Opt_spectator:
  140. if (remount && !args->ar_spectator)
  141. goto cant_remount;
  142. args->ar_spectator = 1;
  143. sdp->sd_vfs->s_flags |= MS_RDONLY;
  144. break;
  145. case Opt_ignore_local_fs:
  146. if (remount && !args->ar_ignore_local_fs)
  147. goto cant_remount;
  148. args->ar_ignore_local_fs = 1;
  149. break;
  150. case Opt_localflocks:
  151. if (remount && !args->ar_localflocks)
  152. goto cant_remount;
  153. args->ar_localflocks = 1;
  154. break;
  155. case Opt_localcaching:
  156. if (remount && !args->ar_localcaching)
  157. goto cant_remount;
  158. args->ar_localcaching = 1;
  159. break;
  160. case Opt_debug:
  161. args->ar_debug = 1;
  162. break;
  163. case Opt_nodebug:
  164. args->ar_debug = 0;
  165. break;
  166. case Opt_upgrade:
  167. if (remount && !args->ar_upgrade)
  168. goto cant_remount;
  169. args->ar_upgrade = 1;
  170. break;
  171. case Opt_acl:
  172. args->ar_posix_acl = 1;
  173. sdp->sd_vfs->s_flags |= MS_POSIXACL;
  174. break;
  175. case Opt_noacl:
  176. args->ar_posix_acl = 0;
  177. sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
  178. break;
  179. case Opt_quota_off:
  180. args->ar_quota = GFS2_QUOTA_OFF;
  181. break;
  182. case Opt_quota_account:
  183. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  184. break;
  185. case Opt_quota_on:
  186. args->ar_quota = GFS2_QUOTA_ON;
  187. break;
  188. case Opt_suiddir:
  189. args->ar_suiddir = 1;
  190. break;
  191. case Opt_nosuiddir:
  192. args->ar_suiddir = 0;
  193. break;
  194. case Opt_data_writeback:
  195. args->ar_data = GFS2_DATA_WRITEBACK;
  196. break;
  197. case Opt_data_ordered:
  198. args->ar_data = GFS2_DATA_ORDERED;
  199. break;
  200. case Opt_meta:
  201. if (remount && args->ar_meta != 1)
  202. goto cant_remount;
  203. args->ar_meta = 1;
  204. break;
  205. case Opt_err:
  206. default:
  207. fs_info(sdp, "unknown option: %s\n", o);
  208. error = -EINVAL;
  209. goto out_error;
  210. }
  211. }
  212. out_error:
  213. if (error)
  214. fs_info(sdp, "invalid mount option(s)\n");
  215. if (data != data_arg)
  216. kfree(data);
  217. return error;
  218. cant_remount:
  219. fs_info(sdp, "can't remount with option %s\n", o);
  220. return -EINVAL;
  221. }