mount.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/gfs2_ondisk.h>
  15. #include <linux/lm_interface.h>
  16. #include "gfs2.h"
  17. #include "incore.h"
  18. #include "mount.h"
  19. #include "sys.h"
  20. #include "util.h"
  21. /**
  22. * gfs2_mount_args - Parse mount options
  23. * @sdp:
  24. * @data:
  25. *
  26. * Return: errno
  27. */
  28. int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
  29. {
  30. struct gfs2_args *args = &sdp->sd_args;
  31. char *data = data_arg;
  32. char *options, *o, *v;
  33. int error = 0;
  34. if (!remount) {
  35. /* If someone preloaded options, use those instead */
  36. spin_lock(&gfs2_sys_margs_lock);
  37. if (gfs2_sys_margs) {
  38. data = gfs2_sys_margs;
  39. gfs2_sys_margs = NULL;
  40. }
  41. spin_unlock(&gfs2_sys_margs_lock);
  42. /* Set some defaults */
  43. args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
  44. args->ar_quota = GFS2_QUOTA_DEFAULT;
  45. args->ar_data = GFS2_DATA_DEFAULT;
  46. }
  47. /* Split the options into tokens with the "," character and
  48. process them */
  49. for (options = data; (o = strsep(&options, ",")); ) {
  50. if (!*o)
  51. continue;
  52. v = strchr(o, '=');
  53. if (v)
  54. *v++ = 0;
  55. if (!strcmp(o, "lockproto")) {
  56. if (!v)
  57. goto need_value;
  58. if (remount && strcmp(v, args->ar_lockproto))
  59. goto cant_remount;
  60. strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
  61. args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
  62. }
  63. else if (!strcmp(o, "locktable")) {
  64. if (!v)
  65. goto need_value;
  66. if (remount && strcmp(v, args->ar_locktable))
  67. goto cant_remount;
  68. strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
  69. args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
  70. }
  71. else if (!strcmp(o, "hostdata")) {
  72. if (!v)
  73. goto need_value;
  74. if (remount && strcmp(v, args->ar_hostdata))
  75. goto cant_remount;
  76. strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
  77. args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
  78. }
  79. else if (!strcmp(o, "spectator")) {
  80. if (remount && !args->ar_spectator)
  81. goto cant_remount;
  82. args->ar_spectator = 1;
  83. sdp->sd_vfs->s_flags |= MS_RDONLY;
  84. }
  85. else if (!strcmp(o, "ignore_local_fs")) {
  86. if (remount && !args->ar_ignore_local_fs)
  87. goto cant_remount;
  88. args->ar_ignore_local_fs = 1;
  89. }
  90. else if (!strcmp(o, "localflocks")) {
  91. if (remount && !args->ar_localflocks)
  92. goto cant_remount;
  93. args->ar_localflocks = 1;
  94. }
  95. else if (!strcmp(o, "localcaching")) {
  96. if (remount && !args->ar_localcaching)
  97. goto cant_remount;
  98. args->ar_localcaching = 1;
  99. }
  100. else if (!strcmp(o, "debug"))
  101. args->ar_debug = 1;
  102. else if (!strcmp(o, "nodebug"))
  103. args->ar_debug = 0;
  104. else if (!strcmp(o, "upgrade")) {
  105. if (remount && !args->ar_upgrade)
  106. goto cant_remount;
  107. args->ar_upgrade = 1;
  108. }
  109. else if (!strcmp(o, "num_glockd")) {
  110. unsigned int x;
  111. if (!v)
  112. goto need_value;
  113. sscanf(v, "%u", &x);
  114. if (remount && x != args->ar_num_glockd)
  115. goto cant_remount;
  116. if (!x || x > GFS2_GLOCKD_MAX) {
  117. fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
  118. GFS2_GLOCKD_MAX, x);
  119. error = -EINVAL;
  120. break;
  121. }
  122. args->ar_num_glockd = x;
  123. }
  124. else if (!strcmp(o, "acl")) {
  125. args->ar_posix_acl = 1;
  126. sdp->sd_vfs->s_flags |= MS_POSIXACL;
  127. }
  128. else if (!strcmp(o, "noacl")) {
  129. args->ar_posix_acl = 0;
  130. sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
  131. }
  132. else if (!strcmp(o, "quota")) {
  133. if (!v)
  134. goto need_value;
  135. if (!strcmp(v, "off"))
  136. args->ar_quota = GFS2_QUOTA_OFF;
  137. else if (!strcmp(v, "account"))
  138. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  139. else if (!strcmp(v, "on"))
  140. args->ar_quota = GFS2_QUOTA_ON;
  141. else {
  142. fs_info(sdp, "invalid value for quota\n");
  143. error = -EINVAL;
  144. break;
  145. }
  146. }
  147. else if (!strcmp(o, "suiddir"))
  148. args->ar_suiddir = 1;
  149. else if (!strcmp(o, "nosuiddir"))
  150. args->ar_suiddir = 0;
  151. else if (!strcmp(o, "data")) {
  152. if (!v)
  153. goto need_value;
  154. if (!strcmp(v, "writeback"))
  155. args->ar_data = GFS2_DATA_WRITEBACK;
  156. else if (!strcmp(v, "ordered"))
  157. args->ar_data = GFS2_DATA_ORDERED;
  158. else {
  159. fs_info(sdp, "invalid value for data\n");
  160. error = -EINVAL;
  161. break;
  162. }
  163. }
  164. else {
  165. fs_info(sdp, "unknown option: %s\n", o);
  166. error = -EINVAL;
  167. break;
  168. }
  169. }
  170. if (error)
  171. fs_info(sdp, "invalid mount option(s)\n");
  172. if (data != data_arg)
  173. kfree(data);
  174. return error;
  175. need_value:
  176. fs_info(sdp, "need value for option %s\n", o);
  177. return -EINVAL;
  178. cant_remount:
  179. fs_info(sdp, "can't remount with option %s\n", o);
  180. return -EINVAL;
  181. }