mount.c 5.8 KB

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