super.c 67 KB

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