super.c 68 KB

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