mount.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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_num_glockd,
  33. Opt_acl,
  34. Opt_noacl,
  35. Opt_quota_off,
  36. Opt_quota_account,
  37. Opt_quota_on,
  38. Opt_suiddir,
  39. Opt_nosuiddir,
  40. Opt_data_writeback,
  41. Opt_data_ordered,
  42. Opt_meta,
  43. Opt_err,
  44. };
  45. static const match_table_t tokens = {
  46. {Opt_lockproto, "lockproto=%s"},
  47. {Opt_locktable, "locktable=%s"},
  48. {Opt_hostdata, "hostdata=%s"},
  49. {Opt_spectator, "spectator"},
  50. {Opt_ignore_local_fs, "ignore_local_fs"},
  51. {Opt_localflocks, "localflocks"},
  52. {Opt_localcaching, "localcaching"},
  53. {Opt_debug, "debug"},
  54. {Opt_nodebug, "nodebug"},
  55. {Opt_upgrade, "upgrade"},
  56. {Opt_num_glockd, "num_glockd=%d"},
  57. {Opt_acl, "acl"},
  58. {Opt_noacl, "noacl"},
  59. {Opt_quota_off, "quota=off"},
  60. {Opt_quota_account, "quota=account"},
  61. {Opt_quota_on, "quota=on"},
  62. {Opt_suiddir, "suiddir"},
  63. {Opt_nosuiddir, "nosuiddir"},
  64. {Opt_data_writeback, "data=writeback"},
  65. {Opt_data_ordered, "data=ordered"},
  66. {Opt_meta, "meta"},
  67. {Opt_err, NULL}
  68. };
  69. /**
  70. * gfs2_mount_args - Parse mount options
  71. * @sdp:
  72. * @data:
  73. *
  74. * Return: errno
  75. */
  76. int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
  77. {
  78. struct gfs2_args *args = &sdp->sd_args;
  79. char *data = data_arg;
  80. char *options, *o, *v;
  81. int error = 0;
  82. if (!remount) {
  83. /* If someone preloaded options, use those instead */
  84. spin_lock(&gfs2_sys_margs_lock);
  85. if (gfs2_sys_margs) {
  86. data = gfs2_sys_margs;
  87. gfs2_sys_margs = NULL;
  88. }
  89. spin_unlock(&gfs2_sys_margs_lock);
  90. /* Set some defaults */
  91. args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
  92. args->ar_quota = GFS2_QUOTA_DEFAULT;
  93. args->ar_data = GFS2_DATA_DEFAULT;
  94. }
  95. /* Split the options into tokens with the "," character and
  96. process them */
  97. for (options = data; (o = strsep(&options, ",")); ) {
  98. int token, option;
  99. substring_t tmp[MAX_OPT_ARGS];
  100. if (!*o)
  101. continue;
  102. token = match_token(o, tokens, tmp);
  103. switch (token) {
  104. case Opt_lockproto:
  105. v = match_strdup(&tmp[0]);
  106. if (!v) {
  107. fs_info(sdp, "no memory for lockproto\n");
  108. error = -ENOMEM;
  109. goto out_error;
  110. }
  111. if (remount && strcmp(v, args->ar_lockproto)) {
  112. kfree(v);
  113. goto cant_remount;
  114. }
  115. strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
  116. args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
  117. kfree(v);
  118. break;
  119. case Opt_locktable:
  120. v = match_strdup(&tmp[0]);
  121. if (!v) {
  122. fs_info(sdp, "no memory for locktable\n");
  123. error = -ENOMEM;
  124. goto out_error;
  125. }
  126. if (remount && strcmp(v, args->ar_locktable)) {
  127. kfree(v);
  128. goto cant_remount;
  129. }
  130. strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
  131. args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
  132. kfree(v);
  133. break;
  134. case Opt_hostdata:
  135. v = match_strdup(&tmp[0]);
  136. if (!v) {
  137. fs_info(sdp, "no memory for hostdata\n");
  138. error = -ENOMEM;
  139. goto out_error;
  140. }
  141. if (remount && strcmp(v, args->ar_hostdata)) {
  142. kfree(v);
  143. goto cant_remount;
  144. }
  145. strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
  146. args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
  147. kfree(v);
  148. break;
  149. case Opt_spectator:
  150. if (remount && !args->ar_spectator)
  151. goto cant_remount;
  152. args->ar_spectator = 1;
  153. sdp->sd_vfs->s_flags |= MS_RDONLY;
  154. break;
  155. case Opt_ignore_local_fs:
  156. if (remount && !args->ar_ignore_local_fs)
  157. goto cant_remount;
  158. args->ar_ignore_local_fs = 1;
  159. break;
  160. case Opt_localflocks:
  161. if (remount && !args->ar_localflocks)
  162. goto cant_remount;
  163. args->ar_localflocks = 1;
  164. break;
  165. case Opt_localcaching:
  166. if (remount && !args->ar_localcaching)
  167. goto cant_remount;
  168. args->ar_localcaching = 1;
  169. break;
  170. case Opt_debug:
  171. args->ar_debug = 1;
  172. break;
  173. case Opt_nodebug:
  174. args->ar_debug = 0;
  175. break;
  176. case Opt_upgrade:
  177. if (remount && !args->ar_upgrade)
  178. goto cant_remount;
  179. args->ar_upgrade = 1;
  180. break;
  181. case Opt_num_glockd:
  182. if ((error = match_int(&tmp[0], &option))) {
  183. fs_info(sdp, "problem getting num_glockd\n");
  184. goto out_error;
  185. }
  186. if (remount && option != args->ar_num_glockd)
  187. goto cant_remount;
  188. if (!option || option > GFS2_GLOCKD_MAX) {
  189. fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
  190. GFS2_GLOCKD_MAX, option);
  191. error = -EINVAL;
  192. goto out_error;
  193. }
  194. args->ar_num_glockd = option;
  195. break;
  196. case Opt_acl:
  197. args->ar_posix_acl = 1;
  198. sdp->sd_vfs->s_flags |= MS_POSIXACL;
  199. break;
  200. case Opt_noacl:
  201. args->ar_posix_acl = 0;
  202. sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
  203. break;
  204. case Opt_quota_off:
  205. args->ar_quota = GFS2_QUOTA_OFF;
  206. break;
  207. case Opt_quota_account:
  208. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  209. break;
  210. case Opt_quota_on:
  211. args->ar_quota = GFS2_QUOTA_ON;
  212. break;
  213. case Opt_suiddir:
  214. args->ar_suiddir = 1;
  215. break;
  216. case Opt_nosuiddir:
  217. args->ar_suiddir = 0;
  218. break;
  219. case Opt_data_writeback:
  220. args->ar_data = GFS2_DATA_WRITEBACK;
  221. break;
  222. case Opt_data_ordered:
  223. args->ar_data = GFS2_DATA_ORDERED;
  224. break;
  225. case Opt_meta:
  226. if (remount && args->ar_meta != 1)
  227. goto cant_remount;
  228. args->ar_meta = 1;
  229. break;
  230. case Opt_err:
  231. default:
  232. fs_info(sdp, "unknown option: %s\n", o);
  233. error = -EINVAL;
  234. goto out_error;
  235. }
  236. }
  237. out_error:
  238. if (error)
  239. fs_info(sdp, "invalid mount option(s)\n");
  240. if (data != data_arg)
  241. kfree(data);
  242. return error;
  243. cant_remount:
  244. fs_info(sdp, "can't remount with option %s\n", o);
  245. return -EINVAL;
  246. }