super.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175
  1. /*
  2. * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  3. *
  4. * Trivial changes by Alan Cox to add the LFS fixes
  5. *
  6. * Trivial Changes:
  7. * Rights granted to Hans Reiser to redistribute under other terms providing
  8. * he accepts all liability including but not limited to patent, fitness
  9. * for purpose, and direct or indirect claims arising from failure to perform.
  10. *
  11. * NO WARRANTY
  12. */
  13. #include <linux/module.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/time.h>
  16. #include <asm/uaccess.h>
  17. #include <linux/reiserfs_fs.h>
  18. #include <linux/reiserfs_acl.h>
  19. #include <linux/reiserfs_xattr.h>
  20. #include <linux/init.h>
  21. #include <linux/blkdev.h>
  22. #include <linux/buffer_head.h>
  23. #include <linux/vfs.h>
  24. #include <linux/mnt_namespace.h>
  25. #include <linux/mount.h>
  26. #include <linux/namei.h>
  27. #include <linux/quotaops.h>
  28. struct file_system_type reiserfs_fs_type;
  29. static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
  30. static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
  31. static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
  32. int is_reiserfs_3_5(struct reiserfs_super_block *rs)
  33. {
  34. return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
  35. strlen(reiserfs_3_5_magic_string));
  36. }
  37. int is_reiserfs_3_6(struct reiserfs_super_block *rs)
  38. {
  39. return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
  40. strlen(reiserfs_3_6_magic_string));
  41. }
  42. int is_reiserfs_jr(struct reiserfs_super_block *rs)
  43. {
  44. return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
  45. strlen(reiserfs_jr_magic_string));
  46. }
  47. static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
  48. {
  49. return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
  50. is_reiserfs_jr(rs));
  51. }
  52. static int reiserfs_remount(struct super_block *s, int *flags, char *data);
  53. static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
  54. static int reiserfs_sync_fs(struct super_block *s, int wait)
  55. {
  56. if (!(s->s_flags & MS_RDONLY)) {
  57. struct reiserfs_transaction_handle th;
  58. reiserfs_write_lock(s);
  59. if (!journal_begin(&th, s, 1))
  60. if (!journal_end_sync(&th, s, 1))
  61. reiserfs_flush_old_commits(s);
  62. s->s_dirt = 0; /* Even if it's not true.
  63. * We'll loop forever in sync_supers otherwise */
  64. reiserfs_write_unlock(s);
  65. } else {
  66. s->s_dirt = 0;
  67. }
  68. return 0;
  69. }
  70. static void reiserfs_write_super(struct super_block *s)
  71. {
  72. reiserfs_sync_fs(s, 1);
  73. }
  74. static void reiserfs_write_super_lockfs(struct super_block *s)
  75. {
  76. struct reiserfs_transaction_handle th;
  77. reiserfs_write_lock(s);
  78. if (!(s->s_flags & MS_RDONLY)) {
  79. int err = journal_begin(&th, s, 1);
  80. if (err) {
  81. reiserfs_block_writes(&th);
  82. } else {
  83. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
  84. 1);
  85. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  86. reiserfs_block_writes(&th);
  87. journal_end_sync(&th, s, 1);
  88. }
  89. }
  90. s->s_dirt = 0;
  91. reiserfs_write_unlock(s);
  92. }
  93. static void reiserfs_unlockfs(struct super_block *s)
  94. {
  95. reiserfs_allow_writes(s);
  96. }
  97. extern const struct in_core_key MAX_IN_CORE_KEY;
  98. /* this is used to delete "save link" when there are no items of a
  99. file it points to. It can either happen if unlink is completed but
  100. "save unlink" removal, or if file has both unlink and truncate
  101. pending and as unlink completes first (because key of "save link"
  102. protecting unlink is bigger that a key lf "save link" which
  103. protects truncate), so there left no items to make truncate
  104. completion on */
  105. static int remove_save_link_only(struct super_block *s,
  106. struct reiserfs_key *key, int oid_free)
  107. {
  108. struct reiserfs_transaction_handle th;
  109. int err;
  110. /* we are going to do one balancing */
  111. err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
  112. if (err)
  113. return err;
  114. reiserfs_delete_solid_item(&th, NULL, key);
  115. if (oid_free)
  116. /* removals are protected by direct items */
  117. reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
  118. return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
  119. }
  120. #ifdef CONFIG_QUOTA
  121. static int reiserfs_quota_on_mount(struct super_block *, int);
  122. #endif
  123. /* look for uncompleted unlinks and truncates and complete them */
  124. static int finish_unfinished(struct super_block *s)
  125. {
  126. INITIALIZE_PATH(path);
  127. struct cpu_key max_cpu_key, obj_key;
  128. struct reiserfs_key save_link_key;
  129. int retval = 0;
  130. struct item_head *ih;
  131. struct buffer_head *bh;
  132. int item_pos;
  133. char *item;
  134. int done;
  135. struct inode *inode;
  136. int truncate;
  137. #ifdef CONFIG_QUOTA
  138. int i;
  139. int ms_active_set;
  140. #endif
  141. /* compose key to look for "save" links */
  142. max_cpu_key.version = KEY_FORMAT_3_5;
  143. max_cpu_key.on_disk_key.k_dir_id = ~0U;
  144. max_cpu_key.on_disk_key.k_objectid = ~0U;
  145. set_cpu_key_k_offset(&max_cpu_key, ~0U);
  146. max_cpu_key.key_length = 3;
  147. #ifdef CONFIG_QUOTA
  148. /* Needed for iput() to work correctly and not trash data */
  149. if (s->s_flags & MS_ACTIVE) {
  150. ms_active_set = 0;
  151. } else {
  152. ms_active_set = 1;
  153. s->s_flags |= MS_ACTIVE;
  154. }
  155. /* Turn on quotas so that they are updated correctly */
  156. for (i = 0; i < MAXQUOTAS; i++) {
  157. if (REISERFS_SB(s)->s_qf_names[i]) {
  158. int ret = reiserfs_quota_on_mount(s, i);
  159. if (ret < 0)
  160. reiserfs_warning(s,
  161. "reiserfs: cannot turn on journalled quota: error %d",
  162. ret);
  163. }
  164. }
  165. #endif
  166. done = 0;
  167. REISERFS_SB(s)->s_is_unlinked_ok = 1;
  168. while (!retval) {
  169. retval = search_item(s, &max_cpu_key, &path);
  170. if (retval != ITEM_NOT_FOUND) {
  171. reiserfs_warning(s,
  172. "vs-2140: finish_unfinished: search_by_key returned %d",
  173. retval);
  174. break;
  175. }
  176. bh = get_last_bh(&path);
  177. item_pos = get_item_pos(&path);
  178. if (item_pos != B_NR_ITEMS(bh)) {
  179. reiserfs_warning(s,
  180. "vs-2060: finish_unfinished: wrong position found");
  181. break;
  182. }
  183. item_pos--;
  184. ih = B_N_PITEM_HEAD(bh, item_pos);
  185. if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
  186. /* there are no "save" links anymore */
  187. break;
  188. save_link_key = ih->ih_key;
  189. if (is_indirect_le_ih(ih))
  190. truncate = 1;
  191. else
  192. truncate = 0;
  193. /* reiserfs_iget needs k_dirid and k_objectid only */
  194. item = B_I_PITEM(bh, ih);
  195. obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
  196. obj_key.on_disk_key.k_objectid =
  197. le32_to_cpu(ih->ih_key.k_objectid);
  198. obj_key.on_disk_key.k_offset = 0;
  199. obj_key.on_disk_key.k_type = 0;
  200. pathrelse(&path);
  201. inode = reiserfs_iget(s, &obj_key);
  202. if (!inode) {
  203. /* the unlink almost completed, it just did not manage to remove
  204. "save" link and release objectid */
  205. reiserfs_warning(s,
  206. "vs-2180: finish_unfinished: iget failed for %K",
  207. &obj_key);
  208. retval = remove_save_link_only(s, &save_link_key, 1);
  209. continue;
  210. }
  211. if (!truncate && inode->i_nlink) {
  212. /* file is not unlinked */
  213. reiserfs_warning(s,
  214. "vs-2185: finish_unfinished: file %K is not unlinked",
  215. &obj_key);
  216. retval = remove_save_link_only(s, &save_link_key, 0);
  217. continue;
  218. }
  219. DQUOT_INIT(inode);
  220. if (truncate && S_ISDIR(inode->i_mode)) {
  221. /* We got a truncate request for a dir which is impossible.
  222. The only imaginable way is to execute unfinished truncate request
  223. then boot into old kernel, remove the file and create dir with
  224. the same key. */
  225. reiserfs_warning(s,
  226. "green-2101: impossible truncate on a directory %k. Please report",
  227. INODE_PKEY(inode));
  228. retval = remove_save_link_only(s, &save_link_key, 0);
  229. truncate = 0;
  230. iput(inode);
  231. continue;
  232. }
  233. if (truncate) {
  234. REISERFS_I(inode)->i_flags |=
  235. i_link_saved_truncate_mask;
  236. /* not completed truncate found. New size was committed together
  237. with "save" link */
  238. reiserfs_info(s, "Truncating %k to %Ld ..",
  239. INODE_PKEY(inode), inode->i_size);
  240. reiserfs_truncate_file(inode,
  241. 0
  242. /*don't update modification time */
  243. );
  244. retval = remove_save_link(inode, truncate);
  245. } else {
  246. REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
  247. /* not completed unlink (rmdir) found */
  248. reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
  249. /* removal gets completed in iput */
  250. retval = 0;
  251. }
  252. iput(inode);
  253. printk("done\n");
  254. done++;
  255. }
  256. REISERFS_SB(s)->s_is_unlinked_ok = 0;
  257. #ifdef CONFIG_QUOTA
  258. /* Turn quotas off */
  259. for (i = 0; i < MAXQUOTAS; i++) {
  260. if (sb_dqopt(s)->files[i])
  261. vfs_quota_off_mount(s, i);
  262. }
  263. if (ms_active_set)
  264. /* Restore the flag back */
  265. s->s_flags &= ~MS_ACTIVE;
  266. #endif
  267. pathrelse(&path);
  268. if (done)
  269. reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
  270. "Completed\n", done);
  271. return retval;
  272. }
  273. /* to protect file being unlinked from getting lost we "safe" link files
  274. being unlinked. This link will be deleted in the same transaction with last
  275. item of file. mounting the filesytem we scan all these links and remove
  276. files which almost got lost */
  277. void add_save_link(struct reiserfs_transaction_handle *th,
  278. struct inode *inode, int truncate)
  279. {
  280. INITIALIZE_PATH(path);
  281. int retval;
  282. struct cpu_key key;
  283. struct item_head ih;
  284. __le32 link;
  285. BUG_ON(!th->t_trans_id);
  286. /* file can only get one "save link" of each kind */
  287. RFALSE(truncate &&
  288. (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
  289. "saved link already exists for truncated inode %lx",
  290. (long)inode->i_ino);
  291. RFALSE(!truncate &&
  292. (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
  293. "saved link already exists for unlinked inode %lx",
  294. (long)inode->i_ino);
  295. /* setup key of "save" link */
  296. key.version = KEY_FORMAT_3_5;
  297. key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
  298. key.on_disk_key.k_objectid = inode->i_ino;
  299. if (!truncate) {
  300. /* unlink, rmdir, rename */
  301. set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
  302. set_cpu_key_k_type(&key, TYPE_DIRECT);
  303. /* item head of "safe" link */
  304. make_le_item_head(&ih, &key, key.version,
  305. 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
  306. 4 /*length */ , 0xffff /*free space */ );
  307. } else {
  308. /* truncate */
  309. if (S_ISDIR(inode->i_mode))
  310. reiserfs_warning(inode->i_sb,
  311. "green-2102: Adding a truncate savelink for a directory %k! Please report",
  312. INODE_PKEY(inode));
  313. set_cpu_key_k_offset(&key, 1);
  314. set_cpu_key_k_type(&key, TYPE_INDIRECT);
  315. /* item head of "safe" link */
  316. make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
  317. 4 /*length */ , 0 /*free space */ );
  318. }
  319. key.key_length = 3;
  320. /* look for its place in the tree */
  321. retval = search_item(inode->i_sb, &key, &path);
  322. if (retval != ITEM_NOT_FOUND) {
  323. if (retval != -ENOSPC)
  324. reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
  325. "search_by_key (%K) returned %d", &key,
  326. retval);
  327. pathrelse(&path);
  328. return;
  329. }
  330. /* body of "save" link */
  331. link = INODE_PKEY(inode)->k_dir_id;
  332. /* put "save" link inot tree, don't charge quota to anyone */
  333. retval =
  334. reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
  335. if (retval) {
  336. if (retval != -ENOSPC)
  337. reiserfs_warning(inode->i_sb,
  338. "vs-2120: add_save_link: insert_item returned %d",
  339. retval);
  340. } else {
  341. if (truncate)
  342. REISERFS_I(inode)->i_flags |=
  343. i_link_saved_truncate_mask;
  344. else
  345. REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
  346. }
  347. }
  348. /* this opens transaction unlike add_save_link */
  349. int remove_save_link(struct inode *inode, int truncate)
  350. {
  351. struct reiserfs_transaction_handle th;
  352. struct reiserfs_key key;
  353. int err;
  354. /* we are going to do one balancing only */
  355. err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
  356. if (err)
  357. return err;
  358. /* setup key of "save" link */
  359. key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
  360. key.k_objectid = INODE_PKEY(inode)->k_objectid;
  361. if (!truncate) {
  362. /* unlink, rmdir, rename */
  363. set_le_key_k_offset(KEY_FORMAT_3_5, &key,
  364. 1 + inode->i_sb->s_blocksize);
  365. set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
  366. } else {
  367. /* truncate */
  368. set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
  369. set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
  370. }
  371. if ((truncate &&
  372. (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
  373. (!truncate &&
  374. (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
  375. /* don't take quota bytes from anywhere */
  376. reiserfs_delete_solid_item(&th, NULL, &key);
  377. if (!truncate) {
  378. reiserfs_release_objectid(&th, inode->i_ino);
  379. REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
  380. } else
  381. REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
  382. return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
  383. }
  384. static void reiserfs_kill_sb(struct super_block *s)
  385. {
  386. if (REISERFS_SB(s)) {
  387. #ifdef CONFIG_REISERFS_FS_XATTR
  388. if (REISERFS_SB(s)->xattr_root) {
  389. d_invalidate(REISERFS_SB(s)->xattr_root);
  390. dput(REISERFS_SB(s)->xattr_root);
  391. REISERFS_SB(s)->xattr_root = NULL;
  392. }
  393. #endif
  394. if (REISERFS_SB(s)->priv_root) {
  395. d_invalidate(REISERFS_SB(s)->priv_root);
  396. dput(REISERFS_SB(s)->priv_root);
  397. REISERFS_SB(s)->priv_root = NULL;
  398. }
  399. }
  400. kill_block_super(s);
  401. }
  402. static void reiserfs_put_super(struct super_block *s)
  403. {
  404. struct reiserfs_transaction_handle th;
  405. th.t_trans_id = 0;
  406. /* change file system state to current state if it was mounted with read-write permissions */
  407. if (!(s->s_flags & MS_RDONLY)) {
  408. if (!journal_begin(&th, s, 10)) {
  409. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
  410. 1);
  411. set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
  412. REISERFS_SB(s)->s_mount_state);
  413. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  414. }
  415. }
  416. /* note, journal_release checks for readonly mount, and can decide not
  417. ** to do a journal_end
  418. */
  419. journal_release(&th, s);
  420. reiserfs_free_bitmap_cache(s);
  421. brelse(SB_BUFFER_WITH_SB(s));
  422. print_statistics(s);
  423. if (REISERFS_SB(s)->reserved_blocks != 0) {
  424. reiserfs_warning(s,
  425. "green-2005: reiserfs_put_super: reserved blocks left %d",
  426. REISERFS_SB(s)->reserved_blocks);
  427. }
  428. reiserfs_proc_info_done(s);
  429. kfree(s->s_fs_info);
  430. s->s_fs_info = NULL;
  431. return;
  432. }
  433. static struct kmem_cache *reiserfs_inode_cachep;
  434. static struct inode *reiserfs_alloc_inode(struct super_block *sb)
  435. {
  436. struct reiserfs_inode_info *ei;
  437. ei = (struct reiserfs_inode_info *)
  438. kmem_cache_alloc(reiserfs_inode_cachep, GFP_KERNEL);
  439. if (!ei)
  440. return NULL;
  441. return &ei->vfs_inode;
  442. }
  443. static void reiserfs_destroy_inode(struct inode *inode)
  444. {
  445. kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
  446. }
  447. static void init_once(void *foo, struct kmem_cache * cachep, unsigned long flags)
  448. {
  449. struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
  450. INIT_LIST_HEAD(&ei->i_prealloc_list);
  451. inode_init_once(&ei->vfs_inode);
  452. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  453. ei->i_acl_access = NULL;
  454. ei->i_acl_default = NULL;
  455. #endif
  456. }
  457. static int init_inodecache(void)
  458. {
  459. reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
  460. sizeof(struct
  461. reiserfs_inode_info),
  462. 0, (SLAB_RECLAIM_ACCOUNT|
  463. SLAB_MEM_SPREAD),
  464. init_once, NULL);
  465. if (reiserfs_inode_cachep == NULL)
  466. return -ENOMEM;
  467. return 0;
  468. }
  469. static void destroy_inodecache(void)
  470. {
  471. kmem_cache_destroy(reiserfs_inode_cachep);
  472. }
  473. /* we don't mark inodes dirty, we just log them */
  474. static void reiserfs_dirty_inode(struct inode *inode)
  475. {
  476. struct reiserfs_transaction_handle th;
  477. int err = 0;
  478. if (inode->i_sb->s_flags & MS_RDONLY) {
  479. reiserfs_warning(inode->i_sb,
  480. "clm-6006: writing inode %lu on readonly FS",
  481. inode->i_ino);
  482. return;
  483. }
  484. reiserfs_write_lock(inode->i_sb);
  485. /* this is really only used for atime updates, so they don't have
  486. ** to be included in O_SYNC or fsync
  487. */
  488. err = journal_begin(&th, inode->i_sb, 1);
  489. if (err) {
  490. reiserfs_write_unlock(inode->i_sb);
  491. return;
  492. }
  493. reiserfs_update_sd(&th, inode);
  494. journal_end(&th, inode->i_sb, 1);
  495. reiserfs_write_unlock(inode->i_sb);
  496. }
  497. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  498. static void reiserfs_clear_inode(struct inode *inode)
  499. {
  500. struct posix_acl *acl;
  501. acl = REISERFS_I(inode)->i_acl_access;
  502. if (acl && !IS_ERR(acl))
  503. posix_acl_release(acl);
  504. REISERFS_I(inode)->i_acl_access = NULL;
  505. acl = REISERFS_I(inode)->i_acl_default;
  506. if (acl && !IS_ERR(acl))
  507. posix_acl_release(acl);
  508. REISERFS_I(inode)->i_acl_default = NULL;
  509. }
  510. #else
  511. #define reiserfs_clear_inode NULL
  512. #endif
  513. #ifdef CONFIG_QUOTA
  514. static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
  515. size_t, loff_t);
  516. static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
  517. loff_t);
  518. #endif
  519. static const struct super_operations reiserfs_sops = {
  520. .alloc_inode = reiserfs_alloc_inode,
  521. .destroy_inode = reiserfs_destroy_inode,
  522. .write_inode = reiserfs_write_inode,
  523. .dirty_inode = reiserfs_dirty_inode,
  524. .delete_inode = reiserfs_delete_inode,
  525. .clear_inode = reiserfs_clear_inode,
  526. .put_super = reiserfs_put_super,
  527. .write_super = reiserfs_write_super,
  528. .sync_fs = reiserfs_sync_fs,
  529. .write_super_lockfs = reiserfs_write_super_lockfs,
  530. .unlockfs = reiserfs_unlockfs,
  531. .statfs = reiserfs_statfs,
  532. .remount_fs = reiserfs_remount,
  533. #ifdef CONFIG_QUOTA
  534. .quota_read = reiserfs_quota_read,
  535. .quota_write = reiserfs_quota_write,
  536. #endif
  537. };
  538. #ifdef CONFIG_QUOTA
  539. #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
  540. static int reiserfs_dquot_initialize(struct inode *, int);
  541. static int reiserfs_dquot_drop(struct inode *);
  542. static int reiserfs_write_dquot(struct dquot *);
  543. static int reiserfs_acquire_dquot(struct dquot *);
  544. static int reiserfs_release_dquot(struct dquot *);
  545. static int reiserfs_mark_dquot_dirty(struct dquot *);
  546. static int reiserfs_write_info(struct super_block *, int);
  547. static int reiserfs_quota_on(struct super_block *, int, int, char *);
  548. static struct dquot_operations reiserfs_quota_operations = {
  549. .initialize = reiserfs_dquot_initialize,
  550. .drop = reiserfs_dquot_drop,
  551. .alloc_space = dquot_alloc_space,
  552. .alloc_inode = dquot_alloc_inode,
  553. .free_space = dquot_free_space,
  554. .free_inode = dquot_free_inode,
  555. .transfer = dquot_transfer,
  556. .write_dquot = reiserfs_write_dquot,
  557. .acquire_dquot = reiserfs_acquire_dquot,
  558. .release_dquot = reiserfs_release_dquot,
  559. .mark_dirty = reiserfs_mark_dquot_dirty,
  560. .write_info = reiserfs_write_info,
  561. };
  562. static struct quotactl_ops reiserfs_qctl_operations = {
  563. .quota_on = reiserfs_quota_on,
  564. .quota_off = vfs_quota_off,
  565. .quota_sync = vfs_quota_sync,
  566. .get_info = vfs_get_dqinfo,
  567. .set_info = vfs_set_dqinfo,
  568. .get_dqblk = vfs_get_dqblk,
  569. .set_dqblk = vfs_set_dqblk,
  570. };
  571. #endif
  572. static struct export_operations reiserfs_export_ops = {
  573. .encode_fh = reiserfs_encode_fh,
  574. .decode_fh = reiserfs_decode_fh,
  575. .get_parent = reiserfs_get_parent,
  576. .get_dentry = reiserfs_get_dentry,
  577. };
  578. /* this struct is used in reiserfs_getopt () for containing the value for those
  579. mount options that have values rather than being toggles. */
  580. typedef struct {
  581. char *value;
  582. int setmask; /* bitmask which is to set on mount_options bitmask when this
  583. value is found, 0 is no bits are to be changed. */
  584. int clrmask; /* bitmask which is to clear on mount_options bitmask when this
  585. value is found, 0 is no bits are to be changed. This is
  586. applied BEFORE setmask */
  587. } arg_desc_t;
  588. /* Set this bit in arg_required to allow empty arguments */
  589. #define REISERFS_OPT_ALLOWEMPTY 31
  590. /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
  591. mount options */
  592. typedef struct {
  593. char *option_name;
  594. int arg_required; /* 0 if argument is not required, not 0 otherwise */
  595. const arg_desc_t *values; /* list of values accepted by an option */
  596. int setmask; /* bitmask which is to set on mount_options bitmask when this
  597. value is found, 0 is no bits are to be changed. */
  598. int clrmask; /* bitmask which is to clear on mount_options bitmask when this
  599. value is found, 0 is no bits are to be changed. This is
  600. applied BEFORE setmask */
  601. } opt_desc_t;
  602. /* possible values for -o data= */
  603. static const arg_desc_t logging_mode[] = {
  604. {"ordered", 1 << REISERFS_DATA_ORDERED,
  605. (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
  606. {"journal", 1 << REISERFS_DATA_LOG,
  607. (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
  608. {"writeback", 1 << REISERFS_DATA_WRITEBACK,
  609. (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
  610. {.value = NULL}
  611. };
  612. /* possible values for -o barrier= */
  613. static const arg_desc_t barrier_mode[] = {
  614. {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
  615. {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
  616. {.value = NULL}
  617. };
  618. /* possible values for "-o block-allocator=" and bits which are to be set in
  619. s_mount_opt of reiserfs specific part of in-core super block */
  620. static const arg_desc_t balloc[] = {
  621. {"noborder", 1 << REISERFS_NO_BORDER, 0},
  622. {"border", 0, 1 << REISERFS_NO_BORDER},
  623. {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
  624. {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
  625. {"test4", 1 << REISERFS_TEST4, 0},
  626. {"notest4", 0, 1 << REISERFS_TEST4},
  627. {NULL, 0, 0}
  628. };
  629. static const arg_desc_t tails[] = {
  630. {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
  631. {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
  632. {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
  633. {NULL, 0, 0}
  634. };
  635. static const arg_desc_t error_actions[] = {
  636. {"panic", 1 << REISERFS_ERROR_PANIC,
  637. (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
  638. {"ro-remount", 1 << REISERFS_ERROR_RO,
  639. (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
  640. #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
  641. {"continue", 1 << REISERFS_ERROR_CONTINUE,
  642. (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
  643. #endif
  644. {NULL, 0, 0},
  645. };
  646. /* proceed only one option from a list *cur - string containing of mount options
  647. opts - array of options which are accepted
  648. opt_arg - if option is found and requires an argument and if it is specifed
  649. in the input - pointer to the argument is stored here
  650. bit_flags - if option requires to set a certain bit - it is set here
  651. return -1 if unknown option is found, opt->arg_required otherwise */
  652. static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
  653. char **opt_arg, unsigned long *bit_flags)
  654. {
  655. char *p;
  656. /* foo=bar,
  657. ^ ^ ^
  658. | | +-- option_end
  659. | +-- arg_start
  660. +-- option_start
  661. */
  662. const opt_desc_t *opt;
  663. const arg_desc_t *arg;
  664. p = *cur;
  665. /* assume argument cannot contain commas */
  666. *cur = strchr(p, ',');
  667. if (*cur) {
  668. *(*cur) = '\0';
  669. (*cur)++;
  670. }
  671. if (!strncmp(p, "alloc=", 6)) {
  672. /* Ugly special case, probably we should redo options parser so that
  673. it can understand several arguments for some options, also so that
  674. it can fill several bitfields with option values. */
  675. if (reiserfs_parse_alloc_options(s, p + 6)) {
  676. return -1;
  677. } else {
  678. return 0;
  679. }
  680. }
  681. /* for every option in the list */
  682. for (opt = opts; opt->option_name; opt++) {
  683. if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
  684. if (bit_flags) {
  685. if (opt->clrmask ==
  686. (1 << REISERFS_UNSUPPORTED_OPT))
  687. reiserfs_warning(s, "%s not supported.",
  688. p);
  689. else
  690. *bit_flags &= ~opt->clrmask;
  691. if (opt->setmask ==
  692. (1 << REISERFS_UNSUPPORTED_OPT))
  693. reiserfs_warning(s, "%s not supported.",
  694. p);
  695. else
  696. *bit_flags |= opt->setmask;
  697. }
  698. break;
  699. }
  700. }
  701. if (!opt->option_name) {
  702. reiserfs_warning(s, "unknown mount option \"%s\"", p);
  703. return -1;
  704. }
  705. p += strlen(opt->option_name);
  706. switch (*p) {
  707. case '=':
  708. if (!opt->arg_required) {
  709. reiserfs_warning(s,
  710. "the option \"%s\" does not require an argument",
  711. opt->option_name);
  712. return -1;
  713. }
  714. break;
  715. case 0:
  716. if (opt->arg_required) {
  717. reiserfs_warning(s,
  718. "the option \"%s\" requires an argument",
  719. opt->option_name);
  720. return -1;
  721. }
  722. break;
  723. default:
  724. reiserfs_warning(s, "head of option \"%s\" is only correct",
  725. opt->option_name);
  726. return -1;
  727. }
  728. /* move to the argument, or to next option if argument is not required */
  729. p++;
  730. if (opt->arg_required
  731. && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
  732. && !strlen(p)) {
  733. /* this catches "option=," if not allowed */
  734. reiserfs_warning(s, "empty argument for \"%s\"",
  735. opt->option_name);
  736. return -1;
  737. }
  738. if (!opt->values) {
  739. /* *=NULLopt_arg contains pointer to argument */
  740. *opt_arg = p;
  741. return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
  742. }
  743. /* values possible for this option are listed in opt->values */
  744. for (arg = opt->values; arg->value; arg++) {
  745. if (!strcmp(p, arg->value)) {
  746. if (bit_flags) {
  747. *bit_flags &= ~arg->clrmask;
  748. *bit_flags |= arg->setmask;
  749. }
  750. return opt->arg_required;
  751. }
  752. }
  753. reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
  754. opt->option_name);
  755. return -1;
  756. }
  757. /* returns 0 if something is wrong in option string, 1 - otherwise */
  758. static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
  759. unsigned long *mount_options,
  760. /* after the parsing phase, contains the
  761. collection of bitflags defining what
  762. mount options were selected. */
  763. unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
  764. char **jdev_name,
  765. unsigned int *commit_max_age)
  766. {
  767. int c;
  768. char *arg = NULL;
  769. char *pos;
  770. opt_desc_t opts[] = {
  771. /* Compatibility stuff, so that -o notail for old setups still work */
  772. {"tails",.arg_required = 't',.values = tails},
  773. {"notail",.clrmask =
  774. (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
  775. {"conv",.setmask = 1 << REISERFS_CONVERT},
  776. {"attrs",.setmask = 1 << REISERFS_ATTRS},
  777. {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
  778. #ifdef CONFIG_REISERFS_FS_XATTR
  779. {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
  780. {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
  781. #else
  782. {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
  783. {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
  784. #endif
  785. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  786. {"acl",.setmask = 1 << REISERFS_POSIXACL},
  787. {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
  788. #else
  789. {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
  790. {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
  791. #endif
  792. {.option_name = "nolog"},
  793. {"replayonly",.setmask = 1 << REPLAYONLY},
  794. {"block-allocator",.arg_required = 'a',.values = balloc},
  795. {"data",.arg_required = 'd',.values = logging_mode},
  796. {"barrier",.arg_required = 'b',.values = barrier_mode},
  797. {"resize",.arg_required = 'r',.values = NULL},
  798. {"jdev",.arg_required = 'j',.values = NULL},
  799. {"nolargeio",.arg_required = 'w',.values = NULL},
  800. {"commit",.arg_required = 'c',.values = NULL},
  801. {"usrquota",.setmask = 1 << REISERFS_QUOTA},
  802. {"grpquota",.setmask = 1 << REISERFS_QUOTA},
  803. {"noquota",.clrmask = 1 << REISERFS_QUOTA},
  804. {"errors",.arg_required = 'e',.values = error_actions},
  805. {"usrjquota",.arg_required =
  806. 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
  807. {"grpjquota",.arg_required =
  808. 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
  809. {"jqfmt",.arg_required = 'f',.values = NULL},
  810. {.option_name = NULL}
  811. };
  812. *blocks = 0;
  813. if (!options || !*options)
  814. /* use default configuration: create tails, journaling on, no
  815. conversion to newest format */
  816. return 1;
  817. for (pos = options; pos;) {
  818. c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
  819. if (c == -1)
  820. /* wrong option is given */
  821. return 0;
  822. if (c == 'r') {
  823. char *p;
  824. p = NULL;
  825. /* "resize=NNN" or "resize=auto" */
  826. if (!strcmp(arg, "auto")) {
  827. /* From JFS code, to auto-get the size. */
  828. *blocks =
  829. s->s_bdev->bd_inode->i_size >> s->
  830. s_blocksize_bits;
  831. } else {
  832. *blocks = simple_strtoul(arg, &p, 0);
  833. if (*p != '\0') {
  834. /* NNN does not look like a number */
  835. reiserfs_warning(s,
  836. "reiserfs_parse_options: bad value %s",
  837. arg);
  838. return 0;
  839. }
  840. }
  841. }
  842. if (c == 'c') {
  843. char *p = NULL;
  844. unsigned long val = simple_strtoul(arg, &p, 0);
  845. /* commit=NNN (time in seconds) */
  846. if (*p != '\0' || val >= (unsigned int)-1) {
  847. reiserfs_warning(s,
  848. "reiserfs_parse_options: bad value %s",
  849. arg);
  850. return 0;
  851. }
  852. *commit_max_age = (unsigned int)val;
  853. }
  854. if (c == 'w') {
  855. reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported");
  856. return 0;
  857. }
  858. if (c == 'j') {
  859. if (arg && *arg && jdev_name) {
  860. if (*jdev_name) { //Hm, already assigned?
  861. reiserfs_warning(s,
  862. "reiserfs_parse_options: journal device was already specified to be %s",
  863. *jdev_name);
  864. return 0;
  865. }
  866. *jdev_name = arg;
  867. }
  868. }
  869. #ifdef CONFIG_QUOTA
  870. if (c == 'u' || c == 'g') {
  871. int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
  872. if (sb_any_quota_enabled(s)) {
  873. reiserfs_warning(s,
  874. "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
  875. return 0;
  876. }
  877. if (*arg) { /* Some filename specified? */
  878. if (REISERFS_SB(s)->s_qf_names[qtype]
  879. && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
  880. arg)) {
  881. reiserfs_warning(s,
  882. "reiserfs_parse_options: %s quota file already specified.",
  883. QTYPE2NAME(qtype));
  884. return 0;
  885. }
  886. if (strchr(arg, '/')) {
  887. reiserfs_warning(s,
  888. "reiserfs_parse_options: quotafile must be on filesystem root.");
  889. return 0;
  890. }
  891. REISERFS_SB(s)->s_qf_names[qtype] =
  892. kmalloc(strlen(arg) + 1, GFP_KERNEL);
  893. if (!REISERFS_SB(s)->s_qf_names[qtype]) {
  894. reiserfs_warning(s,
  895. "reiserfs_parse_options: not enough memory for storing quotafile name.");
  896. return 0;
  897. }
  898. strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
  899. *mount_options |= 1 << REISERFS_QUOTA;
  900. } else {
  901. kfree(REISERFS_SB(s)->s_qf_names[qtype]);
  902. REISERFS_SB(s)->s_qf_names[qtype] = NULL;
  903. }
  904. }
  905. if (c == 'f') {
  906. if (!strcmp(arg, "vfsold"))
  907. REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
  908. else if (!strcmp(arg, "vfsv0"))
  909. REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
  910. else {
  911. reiserfs_warning(s,
  912. "reiserfs_parse_options: unknown quota format specified.");
  913. return 0;
  914. }
  915. }
  916. #else
  917. if (c == 'u' || c == 'g' || c == 'f') {
  918. reiserfs_warning(s,
  919. "reiserfs_parse_options: journalled quota options not supported.");
  920. return 0;
  921. }
  922. #endif
  923. }
  924. #ifdef CONFIG_QUOTA
  925. if (!REISERFS_SB(s)->s_jquota_fmt
  926. && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
  927. || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
  928. reiserfs_warning(s,
  929. "reiserfs_parse_options: journalled quota format not specified.");
  930. return 0;
  931. }
  932. /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
  933. if (!(*mount_options & (1 << REISERFS_QUOTA))
  934. && sb_any_quota_enabled(s)) {
  935. reiserfs_warning(s,
  936. "reiserfs_parse_options: quota options must be present when quota is turned on.");
  937. return 0;
  938. }
  939. #endif
  940. return 1;
  941. }
  942. static void switch_data_mode(struct super_block *s, unsigned long mode)
  943. {
  944. REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
  945. (1 << REISERFS_DATA_ORDERED) |
  946. (1 << REISERFS_DATA_WRITEBACK));
  947. REISERFS_SB(s)->s_mount_opt |= (1 << mode);
  948. }
  949. static void handle_data_mode(struct super_block *s, unsigned long mount_options)
  950. {
  951. if (mount_options & (1 << REISERFS_DATA_LOG)) {
  952. if (!reiserfs_data_log(s)) {
  953. switch_data_mode(s, REISERFS_DATA_LOG);
  954. reiserfs_info(s, "switching to journaled data mode\n");
  955. }
  956. } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
  957. if (!reiserfs_data_ordered(s)) {
  958. switch_data_mode(s, REISERFS_DATA_ORDERED);
  959. reiserfs_info(s, "switching to ordered data mode\n");
  960. }
  961. } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
  962. if (!reiserfs_data_writeback(s)) {
  963. switch_data_mode(s, REISERFS_DATA_WRITEBACK);
  964. reiserfs_info(s, "switching to writeback data mode\n");
  965. }
  966. }
  967. }
  968. static void handle_barrier_mode(struct super_block *s, unsigned long bits)
  969. {
  970. int flush = (1 << REISERFS_BARRIER_FLUSH);
  971. int none = (1 << REISERFS_BARRIER_NONE);
  972. int all_barrier = flush | none;
  973. if (bits & all_barrier) {
  974. REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
  975. if (bits & flush) {
  976. REISERFS_SB(s)->s_mount_opt |= flush;
  977. printk("reiserfs: enabling write barrier flush mode\n");
  978. } else if (bits & none) {
  979. REISERFS_SB(s)->s_mount_opt |= none;
  980. printk("reiserfs: write barriers turned off\n");
  981. }
  982. }
  983. }
  984. static void handle_attrs(struct super_block *s)
  985. {
  986. struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
  987. if (reiserfs_attrs(s)) {
  988. if (old_format_only(s)) {
  989. reiserfs_warning(s,
  990. "reiserfs: cannot support attributes on 3.5.x disk format");
  991. REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
  992. return;
  993. }
  994. if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
  995. reiserfs_warning(s,
  996. "reiserfs: cannot support attributes until flag is set in super-block");
  997. REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
  998. }
  999. }
  1000. }
  1001. static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
  1002. {
  1003. struct reiserfs_super_block *rs;
  1004. struct reiserfs_transaction_handle th;
  1005. unsigned long blocks;
  1006. unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
  1007. unsigned long safe_mask = 0;
  1008. unsigned int commit_max_age = (unsigned int)-1;
  1009. struct reiserfs_journal *journal = SB_JOURNAL(s);
  1010. int err;
  1011. #ifdef CONFIG_QUOTA
  1012. int i;
  1013. #endif
  1014. rs = SB_DISK_SUPER_BLOCK(s);
  1015. if (!reiserfs_parse_options
  1016. (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
  1017. #ifdef CONFIG_QUOTA
  1018. for (i = 0; i < MAXQUOTAS; i++) {
  1019. kfree(REISERFS_SB(s)->s_qf_names[i]);
  1020. REISERFS_SB(s)->s_qf_names[i] = NULL;
  1021. }
  1022. #endif
  1023. return -EINVAL;
  1024. }
  1025. handle_attrs(s);
  1026. /* Add options that are safe here */
  1027. safe_mask |= 1 << REISERFS_SMALLTAIL;
  1028. safe_mask |= 1 << REISERFS_LARGETAIL;
  1029. safe_mask |= 1 << REISERFS_NO_BORDER;
  1030. safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
  1031. safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
  1032. safe_mask |= 1 << REISERFS_TEST4;
  1033. safe_mask |= 1 << REISERFS_ATTRS;
  1034. safe_mask |= 1 << REISERFS_XATTRS_USER;
  1035. safe_mask |= 1 << REISERFS_POSIXACL;
  1036. safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
  1037. safe_mask |= 1 << REISERFS_BARRIER_NONE;
  1038. safe_mask |= 1 << REISERFS_ERROR_RO;
  1039. safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
  1040. safe_mask |= 1 << REISERFS_ERROR_PANIC;
  1041. safe_mask |= 1 << REISERFS_QUOTA;
  1042. /* Update the bitmask, taking care to keep
  1043. * the bits we're not allowed to change here */
  1044. REISERFS_SB(s)->s_mount_opt =
  1045. (REISERFS_SB(s)->
  1046. s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
  1047. if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
  1048. journal->j_max_commit_age = commit_max_age;
  1049. journal->j_max_trans_age = commit_max_age;
  1050. } else if (commit_max_age == 0) {
  1051. /* 0 means restore defaults. */
  1052. journal->j_max_commit_age = journal->j_default_max_commit_age;
  1053. journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
  1054. }
  1055. if (blocks) {
  1056. int rc = reiserfs_resize(s, blocks);
  1057. if (rc != 0)
  1058. return rc;
  1059. }
  1060. if (*mount_flags & MS_RDONLY) {
  1061. reiserfs_xattr_init(s, *mount_flags);
  1062. /* remount read-only */
  1063. if (s->s_flags & MS_RDONLY)
  1064. /* it is read-only already */
  1065. return 0;
  1066. /* try to remount file system with read-only permissions */
  1067. if (sb_umount_state(rs) == REISERFS_VALID_FS
  1068. || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
  1069. return 0;
  1070. }
  1071. err = journal_begin(&th, s, 10);
  1072. if (err)
  1073. return err;
  1074. /* Mounting a rw partition read-only. */
  1075. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1076. set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
  1077. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1078. } else {
  1079. /* remount read-write */
  1080. if (!(s->s_flags & MS_RDONLY)) {
  1081. reiserfs_xattr_init(s, *mount_flags);
  1082. return 0; /* We are read-write already */
  1083. }
  1084. if (reiserfs_is_journal_aborted(journal))
  1085. return journal->j_errno;
  1086. handle_data_mode(s, mount_options);
  1087. handle_barrier_mode(s, mount_options);
  1088. REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
  1089. s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
  1090. err = journal_begin(&th, s, 10);
  1091. if (err)
  1092. return err;
  1093. /* Mount a partition which is read-only, read-write */
  1094. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1095. REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
  1096. s->s_flags &= ~MS_RDONLY;
  1097. set_sb_umount_state(rs, REISERFS_ERROR_FS);
  1098. /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
  1099. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1100. REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
  1101. }
  1102. /* this will force a full flush of all journal lists */
  1103. SB_JOURNAL(s)->j_must_wait = 1;
  1104. err = journal_end(&th, s, 10);
  1105. if (err)
  1106. return err;
  1107. s->s_dirt = 0;
  1108. if (!(*mount_flags & MS_RDONLY)) {
  1109. finish_unfinished(s);
  1110. reiserfs_xattr_init(s, *mount_flags);
  1111. }
  1112. return 0;
  1113. }
  1114. static int read_super_block(struct super_block *s, int offset)
  1115. {
  1116. struct buffer_head *bh;
  1117. struct reiserfs_super_block *rs;
  1118. int fs_blocksize;
  1119. bh = sb_bread(s, offset / s->s_blocksize);
  1120. if (!bh) {
  1121. reiserfs_warning(s, "sh-2006: read_super_block: "
  1122. "bread failed (dev %s, block %lu, size %lu)",
  1123. reiserfs_bdevname(s), offset / s->s_blocksize,
  1124. s->s_blocksize);
  1125. return 1;
  1126. }
  1127. rs = (struct reiserfs_super_block *)bh->b_data;
  1128. if (!is_any_reiserfs_magic_string(rs)) {
  1129. brelse(bh);
  1130. return 1;
  1131. }
  1132. //
  1133. // ok, reiserfs signature (old or new) found in at the given offset
  1134. //
  1135. fs_blocksize = sb_blocksize(rs);
  1136. brelse(bh);
  1137. sb_set_blocksize(s, fs_blocksize);
  1138. bh = sb_bread(s, offset / s->s_blocksize);
  1139. if (!bh) {
  1140. reiserfs_warning(s, "sh-2007: read_super_block: "
  1141. "bread failed (dev %s, block %lu, size %lu)\n",
  1142. reiserfs_bdevname(s), offset / s->s_blocksize,
  1143. s->s_blocksize);
  1144. return 1;
  1145. }
  1146. rs = (struct reiserfs_super_block *)bh->b_data;
  1147. if (sb_blocksize(rs) != s->s_blocksize) {
  1148. reiserfs_warning(s, "sh-2011: read_super_block: "
  1149. "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
  1150. reiserfs_bdevname(s),
  1151. (unsigned long long)bh->b_blocknr,
  1152. s->s_blocksize);
  1153. brelse(bh);
  1154. return 1;
  1155. }
  1156. if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
  1157. brelse(bh);
  1158. reiserfs_warning(s,
  1159. "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
  1160. "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
  1161. "get newer reiserfsprogs package");
  1162. return 1;
  1163. }
  1164. SB_BUFFER_WITH_SB(s) = bh;
  1165. SB_DISK_SUPER_BLOCK(s) = rs;
  1166. if (is_reiserfs_jr(rs)) {
  1167. /* magic is of non-standard journal filesystem, look at s_version to
  1168. find which format is in use */
  1169. if (sb_version(rs) == REISERFS_VERSION_2)
  1170. reiserfs_warning(s,
  1171. "read_super_block: found reiserfs format \"3.6\""
  1172. " with non-standard journal");
  1173. else if (sb_version(rs) == REISERFS_VERSION_1)
  1174. reiserfs_warning(s,
  1175. "read_super_block: found reiserfs format \"3.5\""
  1176. " with non-standard journal");
  1177. else {
  1178. reiserfs_warning(s,
  1179. "sh-2012: read_super_block: found unknown "
  1180. "format \"%u\" of reiserfs with non-standard magic",
  1181. sb_version(rs));
  1182. return 1;
  1183. }
  1184. } else
  1185. /* s_version of standard format may contain incorrect information,
  1186. so we just look at the magic string */
  1187. reiserfs_info(s,
  1188. "found reiserfs format \"%s\" with standard journal\n",
  1189. is_reiserfs_3_5(rs) ? "3.5" : "3.6");
  1190. s->s_op = &reiserfs_sops;
  1191. s->s_export_op = &reiserfs_export_ops;
  1192. #ifdef CONFIG_QUOTA
  1193. s->s_qcop = &reiserfs_qctl_operations;
  1194. s->dq_op = &reiserfs_quota_operations;
  1195. #endif
  1196. /* new format is limited by the 32 bit wide i_blocks field, want to
  1197. ** be one full block below that.
  1198. */
  1199. s->s_maxbytes = (512LL << 32) - s->s_blocksize;
  1200. return 0;
  1201. }
  1202. /* after journal replay, reread all bitmap and super blocks */
  1203. static int reread_meta_blocks(struct super_block *s)
  1204. {
  1205. ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
  1206. wait_on_buffer(SB_BUFFER_WITH_SB(s));
  1207. if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
  1208. reiserfs_warning(s,
  1209. "reread_meta_blocks, error reading the super");
  1210. return 1;
  1211. }
  1212. return 0;
  1213. }
  1214. /////////////////////////////////////////////////////
  1215. // hash detection stuff
  1216. // if root directory is empty - we set default - Yura's - hash and
  1217. // warn about it
  1218. // FIXME: we look for only one name in a directory. If tea and yura
  1219. // bith have the same value - we ask user to send report to the
  1220. // mailing list
  1221. static __u32 find_hash_out(struct super_block *s)
  1222. {
  1223. int retval;
  1224. struct inode *inode;
  1225. struct cpu_key key;
  1226. INITIALIZE_PATH(path);
  1227. struct reiserfs_dir_entry de;
  1228. __u32 hash = DEFAULT_HASH;
  1229. inode = s->s_root->d_inode;
  1230. do { // Some serious "goto"-hater was there ;)
  1231. u32 teahash, r5hash, yurahash;
  1232. make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
  1233. retval = search_by_entry_key(s, &key, &path, &de);
  1234. if (retval == IO_ERROR) {
  1235. pathrelse(&path);
  1236. return UNSET_HASH;
  1237. }
  1238. if (retval == NAME_NOT_FOUND)
  1239. de.de_entry_num--;
  1240. set_de_name_and_namelen(&de);
  1241. if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
  1242. /* allow override in this case */
  1243. if (reiserfs_rupasov_hash(s)) {
  1244. hash = YURA_HASH;
  1245. }
  1246. reiserfs_warning(s, "FS seems to be empty, autodetect "
  1247. "is using the default hash");
  1248. break;
  1249. }
  1250. r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
  1251. teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
  1252. yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
  1253. if (((teahash == r5hash)
  1254. &&
  1255. (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
  1256. == r5hash)) || ((teahash == yurahash)
  1257. && (yurahash ==
  1258. GET_HASH_VALUE(deh_offset
  1259. (&
  1260. (de.
  1261. de_deh[de.
  1262. de_entry_num])))))
  1263. || ((r5hash == yurahash)
  1264. && (yurahash ==
  1265. GET_HASH_VALUE(deh_offset
  1266. (&(de.de_deh[de.de_entry_num])))))) {
  1267. reiserfs_warning(s,
  1268. "Unable to automatically detect hash function. "
  1269. "Please mount with -o hash={tea,rupasov,r5}",
  1270. reiserfs_bdevname(s));
  1271. hash = UNSET_HASH;
  1272. break;
  1273. }
  1274. if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
  1275. yurahash)
  1276. hash = YURA_HASH;
  1277. else if (GET_HASH_VALUE
  1278. (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
  1279. hash = TEA_HASH;
  1280. else if (GET_HASH_VALUE
  1281. (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
  1282. hash = R5_HASH;
  1283. else {
  1284. reiserfs_warning(s, "Unrecognised hash function");
  1285. hash = UNSET_HASH;
  1286. }
  1287. } while (0);
  1288. pathrelse(&path);
  1289. return hash;
  1290. }
  1291. // finds out which hash names are sorted with
  1292. static int what_hash(struct super_block *s)
  1293. {
  1294. __u32 code;
  1295. code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
  1296. /* reiserfs_hash_detect() == true if any of the hash mount options
  1297. ** were used. We must check them to make sure the user isn't
  1298. ** using a bad hash value
  1299. */
  1300. if (code == UNSET_HASH || reiserfs_hash_detect(s))
  1301. code = find_hash_out(s);
  1302. if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
  1303. /* detection has found the hash, and we must check against the
  1304. ** mount options
  1305. */
  1306. if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
  1307. reiserfs_warning(s, "Error, %s hash detected, "
  1308. "unable to force rupasov hash",
  1309. reiserfs_hashname(code));
  1310. code = UNSET_HASH;
  1311. } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
  1312. reiserfs_warning(s, "Error, %s hash detected, "
  1313. "unable to force tea hash",
  1314. reiserfs_hashname(code));
  1315. code = UNSET_HASH;
  1316. } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
  1317. reiserfs_warning(s, "Error, %s hash detected, "
  1318. "unable to force r5 hash",
  1319. reiserfs_hashname(code));
  1320. code = UNSET_HASH;
  1321. }
  1322. } else {
  1323. /* find_hash_out was not called or could not determine the hash */
  1324. if (reiserfs_rupasov_hash(s)) {
  1325. code = YURA_HASH;
  1326. } else if (reiserfs_tea_hash(s)) {
  1327. code = TEA_HASH;
  1328. } else if (reiserfs_r5_hash(s)) {
  1329. code = R5_HASH;
  1330. }
  1331. }
  1332. /* if we are mounted RW, and we have a new valid hash code, update
  1333. ** the super
  1334. */
  1335. if (code != UNSET_HASH &&
  1336. !(s->s_flags & MS_RDONLY) &&
  1337. code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
  1338. set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
  1339. }
  1340. return code;
  1341. }
  1342. // return pointer to appropriate function
  1343. static hashf_t hash_function(struct super_block *s)
  1344. {
  1345. switch (what_hash(s)) {
  1346. case TEA_HASH:
  1347. reiserfs_info(s, "Using tea hash to sort names\n");
  1348. return keyed_hash;
  1349. case YURA_HASH:
  1350. reiserfs_info(s, "Using rupasov hash to sort names\n");
  1351. return yura_hash;
  1352. case R5_HASH:
  1353. reiserfs_info(s, "Using r5 hash to sort names\n");
  1354. return r5_hash;
  1355. }
  1356. return NULL;
  1357. }
  1358. // this is used to set up correct value for old partitions
  1359. static int function2code(hashf_t func)
  1360. {
  1361. if (func == keyed_hash)
  1362. return TEA_HASH;
  1363. if (func == yura_hash)
  1364. return YURA_HASH;
  1365. if (func == r5_hash)
  1366. return R5_HASH;
  1367. BUG(); // should never happen
  1368. return 0;
  1369. }
  1370. #define SWARN(silent, s, ...) \
  1371. if (!(silent)) \
  1372. reiserfs_warning (s, __VA_ARGS__)
  1373. static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
  1374. {
  1375. struct inode *root_inode;
  1376. struct reiserfs_transaction_handle th;
  1377. int old_format = 0;
  1378. unsigned long blocks;
  1379. unsigned int commit_max_age = 0;
  1380. int jinit_done = 0;
  1381. struct reiserfs_iget_args args;
  1382. struct reiserfs_super_block *rs;
  1383. char *jdev_name;
  1384. struct reiserfs_sb_info *sbi;
  1385. int errval = -EINVAL;
  1386. sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
  1387. if (!sbi) {
  1388. errval = -ENOMEM;
  1389. goto error;
  1390. }
  1391. s->s_fs_info = sbi;
  1392. /* Set default values for options: non-aggressive tails, RO on errors */
  1393. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
  1394. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
  1395. /* no preallocation minimum, be smart in
  1396. reiserfs_file_write instead */
  1397. REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
  1398. /* Preallocate by 16 blocks (17-1) at once */
  1399. REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
  1400. #ifdef CONFIG_REISERFS_FS_XATTR
  1401. /* Initialize the rwsem for xattr dir */
  1402. init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
  1403. #endif
  1404. /* setup default block allocator options */
  1405. reiserfs_init_alloc_options(s);
  1406. jdev_name = NULL;
  1407. if (reiserfs_parse_options
  1408. (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
  1409. &commit_max_age) == 0) {
  1410. goto error;
  1411. }
  1412. if (blocks) {
  1413. SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
  1414. "for remount only");
  1415. goto error;
  1416. }
  1417. /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
  1418. if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
  1419. old_format = 1;
  1420. /* try new format (64-th 1k block), which can contain reiserfs super block */
  1421. else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
  1422. SWARN(silent, s,
  1423. "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
  1424. reiserfs_bdevname(s));
  1425. goto error;
  1426. }
  1427. rs = SB_DISK_SUPER_BLOCK(s);
  1428. /* Let's do basic sanity check to verify that underlying device is not
  1429. smaller than the filesystem. If the check fails then abort and scream,
  1430. because bad stuff will happen otherwise. */
  1431. if (s->s_bdev && s->s_bdev->bd_inode
  1432. && i_size_read(s->s_bdev->bd_inode) <
  1433. sb_block_count(rs) * sb_blocksize(rs)) {
  1434. SWARN(silent, s,
  1435. "Filesystem on %s cannot be mounted because it is bigger than the device",
  1436. reiserfs_bdevname(s));
  1437. SWARN(silent, s,
  1438. "You may need to run fsck or increase size of your LVM partition");
  1439. SWARN(silent, s,
  1440. "Or may be you forgot to reboot after fdisk when it told you to");
  1441. goto error;
  1442. }
  1443. sbi->s_mount_state = SB_REISERFS_STATE(s);
  1444. sbi->s_mount_state = REISERFS_VALID_FS;
  1445. if ((errval = reiserfs_init_bitmap_cache(s))) {
  1446. SWARN(silent, s,
  1447. "jmacd-8: reiserfs_fill_super: unable to read bitmap");
  1448. goto error;
  1449. }
  1450. errval = -EINVAL;
  1451. #ifdef CONFIG_REISERFS_CHECK
  1452. SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
  1453. SWARN(silent, s, "- it is slow mode for debugging.");
  1454. #endif
  1455. /* make data=ordered the default */
  1456. if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
  1457. !reiserfs_data_writeback(s)) {
  1458. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
  1459. }
  1460. if (reiserfs_data_log(s)) {
  1461. reiserfs_info(s, "using journaled data mode\n");
  1462. } else if (reiserfs_data_ordered(s)) {
  1463. reiserfs_info(s, "using ordered data mode\n");
  1464. } else {
  1465. reiserfs_info(s, "using writeback data mode\n");
  1466. }
  1467. if (reiserfs_barrier_flush(s)) {
  1468. printk("reiserfs: using flush barriers\n");
  1469. }
  1470. // set_device_ro(s->s_dev, 1) ;
  1471. if (journal_init(s, jdev_name, old_format, commit_max_age)) {
  1472. SWARN(silent, s,
  1473. "sh-2022: reiserfs_fill_super: unable to initialize journal space");
  1474. goto error;
  1475. } else {
  1476. jinit_done = 1; /* once this is set, journal_release must be called
  1477. ** if we error out of the mount
  1478. */
  1479. }
  1480. if (reread_meta_blocks(s)) {
  1481. SWARN(silent, s,
  1482. "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
  1483. goto error;
  1484. }
  1485. if (replay_only(s))
  1486. goto error;
  1487. if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
  1488. SWARN(silent, s,
  1489. "clm-7000: Detected readonly device, marking FS readonly");
  1490. s->s_flags |= MS_RDONLY;
  1491. }
  1492. args.objectid = REISERFS_ROOT_OBJECTID;
  1493. args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
  1494. root_inode =
  1495. iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
  1496. reiserfs_init_locked_inode, (void *)(&args));
  1497. if (!root_inode) {
  1498. SWARN(silent, s,
  1499. "jmacd-10: reiserfs_fill_super: get root inode failed");
  1500. goto error;
  1501. }
  1502. if (root_inode->i_state & I_NEW) {
  1503. reiserfs_read_locked_inode(root_inode, &args);
  1504. unlock_new_inode(root_inode);
  1505. }
  1506. s->s_root = d_alloc_root(root_inode);
  1507. if (!s->s_root) {
  1508. iput(root_inode);
  1509. goto error;
  1510. }
  1511. // define and initialize hash function
  1512. sbi->s_hash_function = hash_function(s);
  1513. if (sbi->s_hash_function == NULL) {
  1514. dput(s->s_root);
  1515. s->s_root = NULL;
  1516. goto error;
  1517. }
  1518. if (is_reiserfs_3_5(rs)
  1519. || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
  1520. set_bit(REISERFS_3_5, &(sbi->s_properties));
  1521. else if (old_format)
  1522. set_bit(REISERFS_OLD_FORMAT, &(sbi->s_properties));
  1523. else
  1524. set_bit(REISERFS_3_6, &(sbi->s_properties));
  1525. if (!(s->s_flags & MS_RDONLY)) {
  1526. errval = journal_begin(&th, s, 1);
  1527. if (errval) {
  1528. dput(s->s_root);
  1529. s->s_root = NULL;
  1530. goto error;
  1531. }
  1532. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1533. set_sb_umount_state(rs, REISERFS_ERROR_FS);
  1534. set_sb_fs_state(rs, 0);
  1535. if (old_format_only(s)) {
  1536. /* filesystem of format 3.5 either with standard or non-standard
  1537. journal */
  1538. if (convert_reiserfs(s)) {
  1539. /* and -o conv is given */
  1540. if (!silent)
  1541. reiserfs_info(s,
  1542. "converting 3.5 filesystem to the 3.6 format");
  1543. if (is_reiserfs_3_5(rs))
  1544. /* put magic string of 3.6 format. 2.2 will not be able to
  1545. mount this filesystem anymore */
  1546. memcpy(rs->s_v1.s_magic,
  1547. reiserfs_3_6_magic_string,
  1548. sizeof
  1549. (reiserfs_3_6_magic_string));
  1550. set_sb_version(rs, REISERFS_VERSION_2);
  1551. reiserfs_convert_objectid_map_v1(s);
  1552. set_bit(REISERFS_3_6, &(sbi->s_properties));
  1553. clear_bit(REISERFS_3_5, &(sbi->s_properties));
  1554. } else if (!silent) {
  1555. reiserfs_info(s, "using 3.5.x disk format\n");
  1556. }
  1557. }
  1558. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1559. errval = journal_end(&th, s, 1);
  1560. if (errval) {
  1561. dput(s->s_root);
  1562. s->s_root = NULL;
  1563. goto error;
  1564. }
  1565. if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
  1566. dput(s->s_root);
  1567. s->s_root = NULL;
  1568. goto error;
  1569. }
  1570. /* look for files which were to be removed in previous session */
  1571. finish_unfinished(s);
  1572. } else {
  1573. if (old_format_only(s) && !silent) {
  1574. reiserfs_info(s, "using 3.5.x disk format\n");
  1575. }
  1576. if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
  1577. dput(s->s_root);
  1578. s->s_root = NULL;
  1579. goto error;
  1580. }
  1581. }
  1582. // mark hash in super block: it could be unset. overwrite should be ok
  1583. set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
  1584. handle_attrs(s);
  1585. reiserfs_proc_info_init(s);
  1586. init_waitqueue_head(&(sbi->s_wait));
  1587. spin_lock_init(&sbi->bitmap_lock);
  1588. return (0);
  1589. error:
  1590. if (jinit_done) { /* kill the commit thread, free journal ram */
  1591. journal_release_error(NULL, s);
  1592. }
  1593. reiserfs_free_bitmap_cache(s);
  1594. if (SB_BUFFER_WITH_SB(s))
  1595. brelse(SB_BUFFER_WITH_SB(s));
  1596. #ifdef CONFIG_QUOTA
  1597. {
  1598. int j;
  1599. for (j = 0; j < MAXQUOTAS; j++) {
  1600. kfree(sbi->s_qf_names[j]);
  1601. sbi->s_qf_names[j] = NULL;
  1602. }
  1603. }
  1604. #endif
  1605. kfree(sbi);
  1606. s->s_fs_info = NULL;
  1607. return errval;
  1608. }
  1609. static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  1610. {
  1611. struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
  1612. buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
  1613. buf->f_bfree = sb_free_blocks(rs);
  1614. buf->f_bavail = buf->f_bfree;
  1615. buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
  1616. buf->f_bsize = dentry->d_sb->s_blocksize;
  1617. /* changed to accommodate gcc folks. */
  1618. buf->f_type = REISERFS_SUPER_MAGIC;
  1619. return 0;
  1620. }
  1621. #ifdef CONFIG_QUOTA
  1622. static int reiserfs_dquot_initialize(struct inode *inode, int type)
  1623. {
  1624. struct reiserfs_transaction_handle th;
  1625. int ret, err;
  1626. /* We may create quota structure so we need to reserve enough blocks */
  1627. reiserfs_write_lock(inode->i_sb);
  1628. ret =
  1629. journal_begin(&th, inode->i_sb,
  1630. 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
  1631. if (ret)
  1632. goto out;
  1633. ret = dquot_initialize(inode, type);
  1634. err =
  1635. journal_end(&th, inode->i_sb,
  1636. 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
  1637. if (!ret && err)
  1638. ret = err;
  1639. out:
  1640. reiserfs_write_unlock(inode->i_sb);
  1641. return ret;
  1642. }
  1643. static int reiserfs_dquot_drop(struct inode *inode)
  1644. {
  1645. struct reiserfs_transaction_handle th;
  1646. int ret, err;
  1647. /* We may delete quota structure so we need to reserve enough blocks */
  1648. reiserfs_write_lock(inode->i_sb);
  1649. ret =
  1650. journal_begin(&th, inode->i_sb,
  1651. 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
  1652. if (ret)
  1653. goto out;
  1654. ret = dquot_drop(inode);
  1655. err =
  1656. journal_end(&th, inode->i_sb,
  1657. 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
  1658. if (!ret && err)
  1659. ret = err;
  1660. out:
  1661. reiserfs_write_unlock(inode->i_sb);
  1662. return ret;
  1663. }
  1664. static int reiserfs_write_dquot(struct dquot *dquot)
  1665. {
  1666. struct reiserfs_transaction_handle th;
  1667. int ret, err;
  1668. reiserfs_write_lock(dquot->dq_sb);
  1669. ret =
  1670. journal_begin(&th, dquot->dq_sb,
  1671. REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  1672. if (ret)
  1673. goto out;
  1674. ret = dquot_commit(dquot);
  1675. err =
  1676. journal_end(&th, dquot->dq_sb,
  1677. REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  1678. if (!ret && err)
  1679. ret = err;
  1680. out:
  1681. reiserfs_write_unlock(dquot->dq_sb);
  1682. return ret;
  1683. }
  1684. static int reiserfs_acquire_dquot(struct dquot *dquot)
  1685. {
  1686. struct reiserfs_transaction_handle th;
  1687. int ret, err;
  1688. reiserfs_write_lock(dquot->dq_sb);
  1689. ret =
  1690. journal_begin(&th, dquot->dq_sb,
  1691. REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  1692. if (ret)
  1693. goto out;
  1694. ret = dquot_acquire(dquot);
  1695. err =
  1696. journal_end(&th, dquot->dq_sb,
  1697. REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  1698. if (!ret && err)
  1699. ret = err;
  1700. out:
  1701. reiserfs_write_unlock(dquot->dq_sb);
  1702. return ret;
  1703. }
  1704. static int reiserfs_release_dquot(struct dquot *dquot)
  1705. {
  1706. struct reiserfs_transaction_handle th;
  1707. int ret, err;
  1708. reiserfs_write_lock(dquot->dq_sb);
  1709. ret =
  1710. journal_begin(&th, dquot->dq_sb,
  1711. REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  1712. if (ret)
  1713. goto out;
  1714. ret = dquot_release(dquot);
  1715. err =
  1716. journal_end(&th, dquot->dq_sb,
  1717. REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  1718. if (!ret && err)
  1719. ret = err;
  1720. out:
  1721. reiserfs_write_unlock(dquot->dq_sb);
  1722. return ret;
  1723. }
  1724. static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
  1725. {
  1726. /* Are we journalling quotas? */
  1727. if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
  1728. REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
  1729. dquot_mark_dquot_dirty(dquot);
  1730. return reiserfs_write_dquot(dquot);
  1731. } else
  1732. return dquot_mark_dquot_dirty(dquot);
  1733. }
  1734. static int reiserfs_write_info(struct super_block *sb, int type)
  1735. {
  1736. struct reiserfs_transaction_handle th;
  1737. int ret, err;
  1738. /* Data block + inode block */
  1739. reiserfs_write_lock(sb);
  1740. ret = journal_begin(&th, sb, 2);
  1741. if (ret)
  1742. goto out;
  1743. ret = dquot_commit_info(sb, type);
  1744. err = journal_end(&th, sb, 2);
  1745. if (!ret && err)
  1746. ret = err;
  1747. out:
  1748. reiserfs_write_unlock(sb);
  1749. return ret;
  1750. }
  1751. /*
  1752. * Turn on quotas during mount time - we need to find the quota file and such...
  1753. */
  1754. static int reiserfs_quota_on_mount(struct super_block *sb, int type)
  1755. {
  1756. return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
  1757. REISERFS_SB(sb)->s_jquota_fmt, type);
  1758. }
  1759. /*
  1760. * Standard function to be called on quota_on
  1761. */
  1762. static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
  1763. char *path)
  1764. {
  1765. int err;
  1766. struct nameidata nd;
  1767. if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
  1768. return -EINVAL;
  1769. err = path_lookup(path, LOOKUP_FOLLOW, &nd);
  1770. if (err)
  1771. return err;
  1772. /* Quotafile not on the same filesystem? */
  1773. if (nd.mnt->mnt_sb != sb) {
  1774. path_release(&nd);
  1775. return -EXDEV;
  1776. }
  1777. /* We must not pack tails for quota files on reiserfs for quota IO to work */
  1778. if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
  1779. reiserfs_warning(sb,
  1780. "reiserfs: Quota file must have tail packing disabled.");
  1781. path_release(&nd);
  1782. return -EINVAL;
  1783. }
  1784. /* Not journalling quota? No more tests needed... */
  1785. if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
  1786. !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
  1787. path_release(&nd);
  1788. return vfs_quota_on(sb, type, format_id, path);
  1789. }
  1790. /* Quotafile not of fs root? */
  1791. if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
  1792. reiserfs_warning(sb,
  1793. "reiserfs: Quota file not on filesystem root. "
  1794. "Journalled quota will not work.");
  1795. path_release(&nd);
  1796. return vfs_quota_on(sb, type, format_id, path);
  1797. }
  1798. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1799. * acquiring the locks... As quota files are never truncated and quota code
  1800. * itself serializes the operations (and noone else should touch the files)
  1801. * we don't have to be afraid of races */
  1802. static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
  1803. size_t len, loff_t off)
  1804. {
  1805. struct inode *inode = sb_dqopt(sb)->files[type];
  1806. unsigned long blk = off >> sb->s_blocksize_bits;
  1807. int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
  1808. size_t toread;
  1809. struct buffer_head tmp_bh, *bh;
  1810. loff_t i_size = i_size_read(inode);
  1811. if (off > i_size)
  1812. return 0;
  1813. if (off + len > i_size)
  1814. len = i_size - off;
  1815. toread = len;
  1816. while (toread > 0) {
  1817. tocopy =
  1818. sb->s_blocksize - offset <
  1819. toread ? sb->s_blocksize - offset : toread;
  1820. tmp_bh.b_state = 0;
  1821. /* Quota files are without tails so we can safely use this function */
  1822. reiserfs_write_lock(sb);
  1823. err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
  1824. reiserfs_write_unlock(sb);
  1825. if (err)
  1826. return err;
  1827. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1828. memset(data, 0, tocopy);
  1829. else {
  1830. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1831. if (!bh)
  1832. return -EIO;
  1833. memcpy(data, bh->b_data + offset, tocopy);
  1834. brelse(bh);
  1835. }
  1836. offset = 0;
  1837. toread -= tocopy;
  1838. data += tocopy;
  1839. blk++;
  1840. }
  1841. return len;
  1842. }
  1843. /* Write to quotafile (we know the transaction is already started and has
  1844. * enough credits) */
  1845. static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
  1846. const char *data, size_t len, loff_t off)
  1847. {
  1848. struct inode *inode = sb_dqopt(sb)->files[type];
  1849. unsigned long blk = off >> sb->s_blocksize_bits;
  1850. int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
  1851. int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
  1852. size_t towrite = len;
  1853. struct buffer_head tmp_bh, *bh;
  1854. mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
  1855. while (towrite > 0) {
  1856. tocopy = sb->s_blocksize - offset < towrite ?
  1857. sb->s_blocksize - offset : towrite;
  1858. tmp_bh.b_state = 0;
  1859. err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
  1860. if (err)
  1861. goto out;
  1862. if (offset || tocopy != sb->s_blocksize)
  1863. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1864. else
  1865. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1866. if (!bh) {
  1867. err = -EIO;
  1868. goto out;
  1869. }
  1870. lock_buffer(bh);
  1871. memcpy(bh->b_data + offset, data, tocopy);
  1872. flush_dcache_page(bh->b_page);
  1873. set_buffer_uptodate(bh);
  1874. unlock_buffer(bh);
  1875. reiserfs_prepare_for_journal(sb, bh, 1);
  1876. journal_mark_dirty(current->journal_info, sb, bh);
  1877. if (!journal_quota)
  1878. reiserfs_add_ordered_list(inode, bh);
  1879. brelse(bh);
  1880. offset = 0;
  1881. towrite -= tocopy;
  1882. data += tocopy;
  1883. blk++;
  1884. }
  1885. out:
  1886. if (len == towrite)
  1887. return err;
  1888. if (inode->i_size < off + len - towrite)
  1889. i_size_write(inode, off + len - towrite);
  1890. inode->i_version++;
  1891. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  1892. mark_inode_dirty(inode);
  1893. mutex_unlock(&inode->i_mutex);
  1894. return len - towrite;
  1895. }
  1896. #endif
  1897. static int get_super_block(struct file_system_type *fs_type,
  1898. int flags, const char *dev_name,
  1899. void *data, struct vfsmount *mnt)
  1900. {
  1901. return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super,
  1902. mnt);
  1903. }
  1904. static int __init init_reiserfs_fs(void)
  1905. {
  1906. int ret;
  1907. if ((ret = init_inodecache())) {
  1908. return ret;
  1909. }
  1910. if ((ret = reiserfs_xattr_register_handlers()))
  1911. goto failed_reiserfs_xattr_register_handlers;
  1912. reiserfs_proc_info_global_init();
  1913. reiserfs_proc_register_global("version",
  1914. reiserfs_global_version_in_proc);
  1915. ret = register_filesystem(&reiserfs_fs_type);
  1916. if (ret == 0) {
  1917. return 0;
  1918. }
  1919. reiserfs_xattr_unregister_handlers();
  1920. failed_reiserfs_xattr_register_handlers:
  1921. reiserfs_proc_unregister_global("version");
  1922. reiserfs_proc_info_global_done();
  1923. destroy_inodecache();
  1924. return ret;
  1925. }
  1926. static void __exit exit_reiserfs_fs(void)
  1927. {
  1928. reiserfs_xattr_unregister_handlers();
  1929. reiserfs_proc_unregister_global("version");
  1930. reiserfs_proc_info_global_done();
  1931. unregister_filesystem(&reiserfs_fs_type);
  1932. destroy_inodecache();
  1933. }
  1934. struct file_system_type reiserfs_fs_type = {
  1935. .owner = THIS_MODULE,
  1936. .name = "reiserfs",
  1937. .get_sb = get_super_block,
  1938. .kill_sb = reiserfs_kill_sb,
  1939. .fs_flags = FS_REQUIRES_DEV,
  1940. };
  1941. MODULE_DESCRIPTION("ReiserFS journaled filesystem");
  1942. MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
  1943. MODULE_LICENSE("GPL");
  1944. module_init(init_reiserfs_fs);
  1945. module_exit(exit_reiserfs_fs);