mount.c 5.8 KB

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