super.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * super.c
  5. *
  6. * load/unload driver, mount/dismount volumes
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/utsname.h>
  31. #include <linux/init.h>
  32. #include <linux/random.h>
  33. #include <linux/statfs.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/socket.h>
  37. #include <linux/inet.h>
  38. #include <linux/parser.h>
  39. #include <linux/crc32.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/mount.h>
  42. #include <linux/seq_file.h>
  43. #include <linux/quotaops.h>
  44. #define MLOG_MASK_PREFIX ML_SUPER
  45. #include <cluster/masklog.h>
  46. #include "ocfs2.h"
  47. /* this should be the only file to include a version 1 header */
  48. #include "ocfs1_fs_compat.h"
  49. #include "alloc.h"
  50. #include "blockcheck.h"
  51. #include "dlmglue.h"
  52. #include "export.h"
  53. #include "extent_map.h"
  54. #include "heartbeat.h"
  55. #include "inode.h"
  56. #include "journal.h"
  57. #include "localalloc.h"
  58. #include "namei.h"
  59. #include "slot_map.h"
  60. #include "super.h"
  61. #include "sysfile.h"
  62. #include "uptodate.h"
  63. #include "ver.h"
  64. #include "xattr.h"
  65. #include "quota.h"
  66. #include "buffer_head_io.h"
  67. static struct kmem_cache *ocfs2_inode_cachep = NULL;
  68. struct kmem_cache *ocfs2_dquot_cachep;
  69. struct kmem_cache *ocfs2_qf_chunk_cachep;
  70. /* OCFS2 needs to schedule several differnt types of work which
  71. * require cluster locking, disk I/O, recovery waits, etc. Since these
  72. * types of work tend to be heavy we avoid using the kernel events
  73. * workqueue and schedule on our own. */
  74. struct workqueue_struct *ocfs2_wq = NULL;
  75. static struct dentry *ocfs2_debugfs_root = NULL;
  76. MODULE_AUTHOR("Oracle");
  77. MODULE_LICENSE("GPL");
  78. struct mount_options
  79. {
  80. unsigned long commit_interval;
  81. unsigned long mount_opt;
  82. unsigned int atime_quantum;
  83. signed short slot;
  84. unsigned int localalloc_opt;
  85. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  86. };
  87. static int ocfs2_parse_options(struct super_block *sb, char *options,
  88. struct mount_options *mopt,
  89. int is_remount);
  90. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
  91. static void ocfs2_put_super(struct super_block *sb);
  92. static int ocfs2_mount_volume(struct super_block *sb);
  93. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  94. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  95. static int ocfs2_initialize_mem_caches(void);
  96. static void ocfs2_free_mem_caches(void);
  97. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  98. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  99. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  100. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  101. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  102. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  103. static int ocfs2_check_volume(struct ocfs2_super *osb);
  104. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  105. struct buffer_head *bh,
  106. u32 sectsize);
  107. static int ocfs2_initialize_super(struct super_block *sb,
  108. struct buffer_head *bh,
  109. int sector_size);
  110. static int ocfs2_get_sector(struct super_block *sb,
  111. struct buffer_head **bh,
  112. int block,
  113. int sect_size);
  114. static void ocfs2_write_super(struct super_block *sb);
  115. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  116. static void ocfs2_destroy_inode(struct inode *inode);
  117. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  118. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  119. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  120. static const struct super_operations ocfs2_sops = {
  121. .statfs = ocfs2_statfs,
  122. .alloc_inode = ocfs2_alloc_inode,
  123. .destroy_inode = ocfs2_destroy_inode,
  124. .drop_inode = ocfs2_drop_inode,
  125. .clear_inode = ocfs2_clear_inode,
  126. .delete_inode = ocfs2_delete_inode,
  127. .sync_fs = ocfs2_sync_fs,
  128. .write_super = ocfs2_write_super,
  129. .put_super = ocfs2_put_super,
  130. .remount_fs = ocfs2_remount,
  131. .show_options = ocfs2_show_options,
  132. .quota_read = ocfs2_quota_read,
  133. .quota_write = ocfs2_quota_write,
  134. };
  135. enum {
  136. Opt_barrier,
  137. Opt_err_panic,
  138. Opt_err_ro,
  139. Opt_intr,
  140. Opt_nointr,
  141. Opt_hb_none,
  142. Opt_hb_local,
  143. Opt_data_ordered,
  144. Opt_data_writeback,
  145. Opt_atime_quantum,
  146. Opt_slot,
  147. Opt_commit,
  148. Opt_localalloc,
  149. Opt_localflocks,
  150. Opt_stack,
  151. Opt_user_xattr,
  152. Opt_nouser_xattr,
  153. Opt_inode64,
  154. Opt_acl,
  155. Opt_noacl,
  156. Opt_usrquota,
  157. Opt_grpquota,
  158. Opt_err,
  159. };
  160. static const match_table_t tokens = {
  161. {Opt_barrier, "barrier=%u"},
  162. {Opt_err_panic, "errors=panic"},
  163. {Opt_err_ro, "errors=remount-ro"},
  164. {Opt_intr, "intr"},
  165. {Opt_nointr, "nointr"},
  166. {Opt_hb_none, OCFS2_HB_NONE},
  167. {Opt_hb_local, OCFS2_HB_LOCAL},
  168. {Opt_data_ordered, "data=ordered"},
  169. {Opt_data_writeback, "data=writeback"},
  170. {Opt_atime_quantum, "atime_quantum=%u"},
  171. {Opt_slot, "preferred_slot=%u"},
  172. {Opt_commit, "commit=%u"},
  173. {Opt_localalloc, "localalloc=%d"},
  174. {Opt_localflocks, "localflocks"},
  175. {Opt_stack, "cluster_stack=%s"},
  176. {Opt_user_xattr, "user_xattr"},
  177. {Opt_nouser_xattr, "nouser_xattr"},
  178. {Opt_inode64, "inode64"},
  179. {Opt_acl, "acl"},
  180. {Opt_noacl, "noacl"},
  181. {Opt_usrquota, "usrquota"},
  182. {Opt_grpquota, "grpquota"},
  183. {Opt_err, NULL}
  184. };
  185. #ifdef CONFIG_DEBUG_FS
  186. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  187. {
  188. int out = 0;
  189. int i;
  190. struct ocfs2_cluster_connection *cconn = osb->cconn;
  191. struct ocfs2_recovery_map *rm = osb->recovery_map;
  192. struct ocfs2_orphan_scan *os;
  193. out += snprintf(buf + out, len - out,
  194. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  195. "Device", osb->dev_str, osb->uuid_str,
  196. osb->fs_generation, osb->vol_label);
  197. out += snprintf(buf + out, len - out,
  198. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  199. atomic_read(&osb->vol_state), osb->osb_flags);
  200. out += snprintf(buf + out, len - out,
  201. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  202. osb->sb->s_blocksize, osb->s_clustersize);
  203. out += snprintf(buf + out, len - out,
  204. "%10s => Compat: 0x%X Incompat: 0x%X "
  205. "ROcompat: 0x%X\n",
  206. "Features", osb->s_feature_compat,
  207. osb->s_feature_incompat, osb->s_feature_ro_compat);
  208. out += snprintf(buf + out, len - out,
  209. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  210. osb->s_mount_opt, osb->s_atime_quantum);
  211. out += snprintf(buf + out, len - out,
  212. "%10s => Stack: %s Name: %*s Version: %d.%d\n",
  213. "Cluster",
  214. (*osb->osb_cluster_stack == '\0' ?
  215. "o2cb" : osb->osb_cluster_stack),
  216. cconn->cc_namelen, cconn->cc_name,
  217. cconn->cc_version.pv_major, cconn->cc_version.pv_minor);
  218. spin_lock(&osb->dc_task_lock);
  219. out += snprintf(buf + out, len - out,
  220. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  221. "WorkSeq: %lu\n", "DownCnvt",
  222. task_pid_nr(osb->dc_task), osb->blocked_lock_count,
  223. osb->dc_wake_sequence, osb->dc_work_sequence);
  224. spin_unlock(&osb->dc_task_lock);
  225. spin_lock(&osb->osb_lock);
  226. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  227. "Recovery",
  228. (osb->recovery_thread_task ?
  229. task_pid_nr(osb->recovery_thread_task) : -1));
  230. if (rm->rm_used == 0)
  231. out += snprintf(buf + out, len - out, " None\n");
  232. else {
  233. for (i = 0; i < rm->rm_used; i++)
  234. out += snprintf(buf + out, len - out, " %d",
  235. rm->rm_entries[i]);
  236. out += snprintf(buf + out, len - out, "\n");
  237. }
  238. spin_unlock(&osb->osb_lock);
  239. out += snprintf(buf + out, len - out,
  240. "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
  241. task_pid_nr(osb->commit_task), osb->osb_commit_interval,
  242. atomic_read(&osb->needs_checkpoint));
  243. out += snprintf(buf + out, len - out,
  244. "%10s => State: %d NumTxns: %d TxnId: %lu\n",
  245. "Journal", osb->journal->j_state,
  246. atomic_read(&osb->journal->j_num_trans),
  247. osb->journal->j_trans_id);
  248. out += snprintf(buf + out, len - out,
  249. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  250. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  251. "Stats",
  252. atomic_read(&osb->alloc_stats.bitmap_data),
  253. atomic_read(&osb->alloc_stats.local_data),
  254. atomic_read(&osb->alloc_stats.bg_allocs),
  255. atomic_read(&osb->alloc_stats.moves),
  256. atomic_read(&osb->alloc_stats.bg_extends));
  257. out += snprintf(buf + out, len - out,
  258. "%10s => State: %u Descriptor: %llu Size: %u bits "
  259. "Default: %u bits\n",
  260. "LocalAlloc", osb->local_alloc_state,
  261. (unsigned long long)osb->la_last_gd,
  262. osb->local_alloc_bits, osb->local_alloc_default_bits);
  263. spin_lock(&osb->osb_lock);
  264. out += snprintf(buf + out, len - out,
  265. "%10s => Slot: %d NumStolen: %d\n", "Steal",
  266. osb->s_inode_steal_slot,
  267. atomic_read(&osb->s_num_inodes_stolen));
  268. spin_unlock(&osb->osb_lock);
  269. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  270. "Slots", "Num", "RecoGen");
  271. for (i = 0; i < osb->max_slots; ++i) {
  272. out += snprintf(buf + out, len - out,
  273. "%10s %c %3d %10d\n",
  274. " ",
  275. (i == osb->slot_num ? '*' : ' '),
  276. i, osb->slot_recovery_generations[i]);
  277. }
  278. os = &osb->osb_orphan_scan;
  279. out += snprintf(buf + out, len - out, "Orphan Scan=> ");
  280. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  281. os->os_count, os->os_seqno);
  282. out += snprintf(buf + out, len - out, " Last Scan: %lu seconds ago\n",
  283. (get_seconds() - os->os_scantime.tv_sec));
  284. return out;
  285. }
  286. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  287. {
  288. struct ocfs2_super *osb = inode->i_private;
  289. char *buf = NULL;
  290. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  291. if (!buf)
  292. goto bail;
  293. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  294. file->private_data = buf;
  295. return 0;
  296. bail:
  297. return -ENOMEM;
  298. }
  299. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  300. {
  301. kfree(file->private_data);
  302. return 0;
  303. }
  304. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  305. size_t nbytes, loff_t *ppos)
  306. {
  307. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  308. i_size_read(file->f_mapping->host));
  309. }
  310. #else
  311. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  312. {
  313. return 0;
  314. }
  315. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  316. {
  317. return 0;
  318. }
  319. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  320. size_t nbytes, loff_t *ppos)
  321. {
  322. return 0;
  323. }
  324. #endif /* CONFIG_DEBUG_FS */
  325. static struct file_operations ocfs2_osb_debug_fops = {
  326. .open = ocfs2_osb_debug_open,
  327. .release = ocfs2_debug_release,
  328. .read = ocfs2_debug_read,
  329. .llseek = generic_file_llseek,
  330. };
  331. /*
  332. * write_super and sync_fs ripped right out of ext3.
  333. */
  334. static void ocfs2_write_super(struct super_block *sb)
  335. {
  336. if (mutex_trylock(&sb->s_lock) != 0)
  337. BUG();
  338. sb->s_dirt = 0;
  339. }
  340. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  341. {
  342. int status;
  343. tid_t target;
  344. struct ocfs2_super *osb = OCFS2_SB(sb);
  345. sb->s_dirt = 0;
  346. if (ocfs2_is_hard_readonly(osb))
  347. return -EROFS;
  348. if (wait) {
  349. status = ocfs2_flush_truncate_log(osb);
  350. if (status < 0)
  351. mlog_errno(status);
  352. } else {
  353. ocfs2_schedule_truncate_log_flush(osb, 0);
  354. }
  355. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  356. &target)) {
  357. if (wait)
  358. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  359. target);
  360. }
  361. return 0;
  362. }
  363. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  364. {
  365. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  366. && (ino == USER_QUOTA_SYSTEM_INODE
  367. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  368. return 0;
  369. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  370. && (ino == GROUP_QUOTA_SYSTEM_INODE
  371. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  372. return 0;
  373. return 1;
  374. }
  375. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  376. {
  377. struct inode *new = NULL;
  378. int status = 0;
  379. int i;
  380. mlog_entry_void();
  381. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  382. if (IS_ERR(new)) {
  383. status = PTR_ERR(new);
  384. mlog_errno(status);
  385. goto bail;
  386. }
  387. osb->root_inode = new;
  388. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  389. if (IS_ERR(new)) {
  390. status = PTR_ERR(new);
  391. mlog_errno(status);
  392. goto bail;
  393. }
  394. osb->sys_root_inode = new;
  395. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  396. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  397. if (!ocfs2_need_system_inode(osb, i))
  398. continue;
  399. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  400. if (!new) {
  401. ocfs2_release_system_inodes(osb);
  402. status = -EINVAL;
  403. mlog_errno(status);
  404. /* FIXME: Should ERROR_RO_FS */
  405. mlog(ML_ERROR, "Unable to load system inode %d, "
  406. "possibly corrupt fs?", i);
  407. goto bail;
  408. }
  409. // the array now has one ref, so drop this one
  410. iput(new);
  411. }
  412. bail:
  413. mlog_exit(status);
  414. return status;
  415. }
  416. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  417. {
  418. struct inode *new = NULL;
  419. int status = 0;
  420. int i;
  421. mlog_entry_void();
  422. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  423. i < NUM_SYSTEM_INODES;
  424. i++) {
  425. if (!ocfs2_need_system_inode(osb, i))
  426. continue;
  427. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  428. if (!new) {
  429. ocfs2_release_system_inodes(osb);
  430. status = -EINVAL;
  431. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  432. status, i, osb->slot_num);
  433. goto bail;
  434. }
  435. /* the array now has one ref, so drop this one */
  436. iput(new);
  437. }
  438. bail:
  439. mlog_exit(status);
  440. return status;
  441. }
  442. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  443. {
  444. int i;
  445. struct inode *inode;
  446. mlog_entry_void();
  447. for (i = 0; i < NUM_SYSTEM_INODES; i++) {
  448. inode = osb->system_inodes[i];
  449. if (inode) {
  450. iput(inode);
  451. osb->system_inodes[i] = NULL;
  452. }
  453. }
  454. inode = osb->sys_root_inode;
  455. if (inode) {
  456. iput(inode);
  457. osb->sys_root_inode = NULL;
  458. }
  459. inode = osb->root_inode;
  460. if (inode) {
  461. iput(inode);
  462. osb->root_inode = NULL;
  463. }
  464. mlog_exit(0);
  465. }
  466. /* We're allocating fs objects, use GFP_NOFS */
  467. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  468. {
  469. struct ocfs2_inode_info *oi;
  470. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  471. if (!oi)
  472. return NULL;
  473. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  474. return &oi->vfs_inode;
  475. }
  476. static void ocfs2_destroy_inode(struct inode *inode)
  477. {
  478. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  479. }
  480. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  481. unsigned int cbits)
  482. {
  483. unsigned int bytes = 1 << cbits;
  484. unsigned int trim = bytes;
  485. unsigned int bitshift = 32;
  486. /*
  487. * i_size and all block offsets in ocfs2 are always 64 bits
  488. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  489. * 64 bit platforms, cluster size will be the limiting factor.
  490. */
  491. #if BITS_PER_LONG == 32
  492. # if defined(CONFIG_LBD)
  493. BUILD_BUG_ON(sizeof(sector_t) != 8);
  494. /*
  495. * We might be limited by page cache size.
  496. */
  497. if (bytes > PAGE_CACHE_SIZE) {
  498. bytes = PAGE_CACHE_SIZE;
  499. trim = 1;
  500. /*
  501. * Shift by 31 here so that we don't get larger than
  502. * MAX_LFS_FILESIZE
  503. */
  504. bitshift = 31;
  505. }
  506. # else
  507. /*
  508. * We are limited by the size of sector_t. Use block size, as
  509. * that's what we expose to the VFS.
  510. */
  511. bytes = 1 << bbits;
  512. trim = 1;
  513. bitshift = 31;
  514. # endif
  515. #endif
  516. /*
  517. * Trim by a whole cluster when we can actually approach the
  518. * on-disk limits. Otherwise we can overflow i_clusters when
  519. * an extent start is at the max offset.
  520. */
  521. return (((unsigned long long)bytes) << bitshift) - trim;
  522. }
  523. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  524. {
  525. int incompat_features;
  526. int ret = 0;
  527. struct mount_options parsed_options;
  528. struct ocfs2_super *osb = OCFS2_SB(sb);
  529. if (!ocfs2_parse_options(sb, data, &parsed_options, 1)) {
  530. ret = -EINVAL;
  531. goto out;
  532. }
  533. if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
  534. (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  535. ret = -EINVAL;
  536. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  537. goto out;
  538. }
  539. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  540. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  541. ret = -EINVAL;
  542. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  543. goto out;
  544. }
  545. /* Probably don't want this on remount; it might
  546. * mess with other nodes */
  547. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  548. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  549. ret = -EINVAL;
  550. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  551. goto out;
  552. }
  553. /* We're going to/from readonly mode. */
  554. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  555. /* Disable quota accounting before remounting RO */
  556. if (*flags & MS_RDONLY) {
  557. ret = ocfs2_susp_quotas(osb, 0);
  558. if (ret < 0)
  559. goto out;
  560. }
  561. /* Lock here so the check of HARD_RO and the potential
  562. * setting of SOFT_RO is atomic. */
  563. spin_lock(&osb->osb_lock);
  564. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  565. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  566. ret = -EROFS;
  567. goto unlock_osb;
  568. }
  569. if (*flags & MS_RDONLY) {
  570. mlog(0, "Going to ro mode.\n");
  571. sb->s_flags |= MS_RDONLY;
  572. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  573. } else {
  574. mlog(0, "Making ro filesystem writeable.\n");
  575. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  576. mlog(ML_ERROR, "Cannot remount RDWR "
  577. "filesystem due to previous errors.\n");
  578. ret = -EROFS;
  579. goto unlock_osb;
  580. }
  581. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  582. if (incompat_features) {
  583. mlog(ML_ERROR, "Cannot remount RDWR because "
  584. "of unsupported optional features "
  585. "(%x).\n", incompat_features);
  586. ret = -EINVAL;
  587. goto unlock_osb;
  588. }
  589. sb->s_flags &= ~MS_RDONLY;
  590. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  591. }
  592. unlock_osb:
  593. spin_unlock(&osb->osb_lock);
  594. /* Enable quota accounting after remounting RW */
  595. if (!ret && !(*flags & MS_RDONLY)) {
  596. if (sb_any_quota_suspended(sb))
  597. ret = ocfs2_susp_quotas(osb, 1);
  598. else
  599. ret = ocfs2_enable_quotas(osb);
  600. if (ret < 0) {
  601. /* Return back changes... */
  602. spin_lock(&osb->osb_lock);
  603. sb->s_flags |= MS_RDONLY;
  604. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  605. spin_unlock(&osb->osb_lock);
  606. goto out;
  607. }
  608. }
  609. }
  610. if (!ret) {
  611. /* Only save off the new mount options in case of a successful
  612. * remount. */
  613. if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
  614. parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  615. osb->s_mount_opt = parsed_options.mount_opt;
  616. osb->s_atime_quantum = parsed_options.atime_quantum;
  617. osb->preferred_slot = parsed_options.slot;
  618. if (parsed_options.commit_interval)
  619. osb->osb_commit_interval = parsed_options.commit_interval;
  620. if (!ocfs2_is_hard_readonly(osb))
  621. ocfs2_set_journal_params(osb);
  622. }
  623. out:
  624. return ret;
  625. }
  626. static int ocfs2_sb_probe(struct super_block *sb,
  627. struct buffer_head **bh,
  628. int *sector_size)
  629. {
  630. int status, tmpstat;
  631. struct ocfs1_vol_disk_hdr *hdr;
  632. struct ocfs2_dinode *di;
  633. int blksize;
  634. *bh = NULL;
  635. /* may be > 512 */
  636. *sector_size = bdev_hardsect_size(sb->s_bdev);
  637. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  638. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  639. *sector_size, OCFS2_MAX_BLOCKSIZE);
  640. status = -EINVAL;
  641. goto bail;
  642. }
  643. /* Can this really happen? */
  644. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  645. *sector_size = OCFS2_MIN_BLOCKSIZE;
  646. /* check block zero for old format */
  647. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  648. if (status < 0) {
  649. mlog_errno(status);
  650. goto bail;
  651. }
  652. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  653. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  654. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  655. hdr->major_version, hdr->minor_version);
  656. status = -EINVAL;
  657. }
  658. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  659. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  660. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  661. hdr->signature);
  662. status = -EINVAL;
  663. }
  664. brelse(*bh);
  665. *bh = NULL;
  666. if (status < 0) {
  667. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  668. "upgraded before mounting with ocfs v2\n");
  669. goto bail;
  670. }
  671. /*
  672. * Now check at magic offset for 512, 1024, 2048, 4096
  673. * blocksizes. 4096 is the maximum blocksize because it is
  674. * the minimum clustersize.
  675. */
  676. status = -EINVAL;
  677. for (blksize = *sector_size;
  678. blksize <= OCFS2_MAX_BLOCKSIZE;
  679. blksize <<= 1) {
  680. tmpstat = ocfs2_get_sector(sb, bh,
  681. OCFS2_SUPER_BLOCK_BLKNO,
  682. blksize);
  683. if (tmpstat < 0) {
  684. status = tmpstat;
  685. mlog_errno(status);
  686. goto bail;
  687. }
  688. di = (struct ocfs2_dinode *) (*bh)->b_data;
  689. status = ocfs2_verify_volume(di, *bh, blksize);
  690. if (status >= 0)
  691. goto bail;
  692. brelse(*bh);
  693. *bh = NULL;
  694. if (status != -EAGAIN)
  695. break;
  696. }
  697. bail:
  698. return status;
  699. }
  700. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  701. {
  702. if (ocfs2_mount_local(osb)) {
  703. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  704. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  705. "mounted device.\n");
  706. return -EINVAL;
  707. }
  708. }
  709. if (ocfs2_userspace_stack(osb)) {
  710. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  711. mlog(ML_ERROR, "Userspace stack expected, but "
  712. "o2cb heartbeat arguments passed to mount\n");
  713. return -EINVAL;
  714. }
  715. }
  716. if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  717. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  718. !ocfs2_userspace_stack(osb)) {
  719. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  720. "a read-write clustered device.\n");
  721. return -EINVAL;
  722. }
  723. }
  724. return 0;
  725. }
  726. /*
  727. * If we're using a userspace stack, mount should have passed
  728. * a name that matches the disk. If not, mount should not
  729. * have passed a stack.
  730. */
  731. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  732. struct mount_options *mopt)
  733. {
  734. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  735. mlog(ML_ERROR,
  736. "cluster stack passed to mount, but this filesystem "
  737. "does not support it\n");
  738. return -EINVAL;
  739. }
  740. if (ocfs2_userspace_stack(osb) &&
  741. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  742. OCFS2_STACK_LABEL_LEN)) {
  743. mlog(ML_ERROR,
  744. "cluster stack passed to mount (\"%s\") does not "
  745. "match the filesystem (\"%s\")\n",
  746. mopt->cluster_stack,
  747. osb->osb_cluster_stack);
  748. return -EINVAL;
  749. }
  750. return 0;
  751. }
  752. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  753. {
  754. int type;
  755. struct super_block *sb = osb->sb;
  756. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  757. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  758. int status = 0;
  759. for (type = 0; type < MAXQUOTAS; type++) {
  760. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  761. continue;
  762. if (unsuspend)
  763. status = vfs_quota_enable(
  764. sb_dqopt(sb)->files[type],
  765. type, QFMT_OCFS2,
  766. DQUOT_SUSPENDED);
  767. else
  768. status = vfs_quota_disable(sb, type,
  769. DQUOT_SUSPENDED);
  770. if (status < 0)
  771. break;
  772. }
  773. if (status < 0)
  774. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  775. "remount (error = %d).\n", status);
  776. return status;
  777. }
  778. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  779. {
  780. struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  781. struct super_block *sb = osb->sb;
  782. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  783. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  784. unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  785. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  786. int status;
  787. int type;
  788. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  789. for (type = 0; type < MAXQUOTAS; type++) {
  790. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  791. continue;
  792. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  793. osb->slot_num);
  794. if (!inode[type]) {
  795. status = -ENOENT;
  796. goto out_quota_off;
  797. }
  798. status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
  799. DQUOT_USAGE_ENABLED);
  800. if (status < 0)
  801. goto out_quota_off;
  802. }
  803. for (type = 0; type < MAXQUOTAS; type++)
  804. iput(inode[type]);
  805. return 0;
  806. out_quota_off:
  807. ocfs2_disable_quotas(osb);
  808. for (type = 0; type < MAXQUOTAS; type++)
  809. iput(inode[type]);
  810. mlog_errno(status);
  811. return status;
  812. }
  813. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  814. {
  815. int type;
  816. struct inode *inode;
  817. struct super_block *sb = osb->sb;
  818. /* We mostly ignore errors in this function because there's not much
  819. * we can do when we see them */
  820. for (type = 0; type < MAXQUOTAS; type++) {
  821. if (!sb_has_quota_loaded(sb, type))
  822. continue;
  823. inode = igrab(sb->s_dquot.files[type]);
  824. /* Turn off quotas. This will remove all dquot structures from
  825. * memory and so they will be automatically synced to global
  826. * quota files */
  827. vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
  828. DQUOT_LIMITS_ENABLED);
  829. if (!inode)
  830. continue;
  831. iput(inode);
  832. }
  833. }
  834. /* Handle quota on quotactl */
  835. static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
  836. char *path, int remount)
  837. {
  838. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  839. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  840. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  841. return -EINVAL;
  842. if (remount)
  843. return 0; /* Just ignore it has been handled in
  844. * ocfs2_remount() */
  845. return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
  846. format_id, DQUOT_LIMITS_ENABLED);
  847. }
  848. /* Handle quota off quotactl */
  849. static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
  850. {
  851. if (remount)
  852. return 0; /* Ignore now and handle later in
  853. * ocfs2_remount() */
  854. return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
  855. }
  856. static struct quotactl_ops ocfs2_quotactl_ops = {
  857. .quota_on = ocfs2_quota_on,
  858. .quota_off = ocfs2_quota_off,
  859. .quota_sync = vfs_quota_sync,
  860. .get_info = vfs_get_dqinfo,
  861. .set_info = vfs_set_dqinfo,
  862. .get_dqblk = vfs_get_dqblk,
  863. .set_dqblk = vfs_set_dqblk,
  864. };
  865. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  866. {
  867. struct dentry *root;
  868. int status, sector_size;
  869. struct mount_options parsed_options;
  870. struct inode *inode = NULL;
  871. struct ocfs2_super *osb = NULL;
  872. struct buffer_head *bh = NULL;
  873. char nodestr[8];
  874. mlog_entry("%p, %p, %i", sb, data, silent);
  875. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  876. status = -EINVAL;
  877. goto read_super_error;
  878. }
  879. /* probe for superblock */
  880. status = ocfs2_sb_probe(sb, &bh, &sector_size);
  881. if (status < 0) {
  882. mlog(ML_ERROR, "superblock probe failed!\n");
  883. goto read_super_error;
  884. }
  885. status = ocfs2_initialize_super(sb, bh, sector_size);
  886. osb = OCFS2_SB(sb);
  887. if (status < 0) {
  888. mlog_errno(status);
  889. goto read_super_error;
  890. }
  891. brelse(bh);
  892. bh = NULL;
  893. if (!(osb->s_feature_incompat & OCFS2_FEATURE_INCOMPAT_XATTR))
  894. parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  895. osb->s_mount_opt = parsed_options.mount_opt;
  896. osb->s_atime_quantum = parsed_options.atime_quantum;
  897. osb->preferred_slot = parsed_options.slot;
  898. osb->osb_commit_interval = parsed_options.commit_interval;
  899. osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
  900. osb->local_alloc_bits = osb->local_alloc_default_bits;
  901. if (osb->s_mount_opt & OCFS2_MOUNT_USRQUOTA &&
  902. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  903. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  904. status = -EINVAL;
  905. mlog(ML_ERROR, "User quotas were requested, but this "
  906. "filesystem does not have the feature enabled.\n");
  907. goto read_super_error;
  908. }
  909. if (osb->s_mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  910. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  911. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  912. status = -EINVAL;
  913. mlog(ML_ERROR, "Group quotas were requested, but this "
  914. "filesystem does not have the feature enabled.\n");
  915. goto read_super_error;
  916. }
  917. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  918. if (status)
  919. goto read_super_error;
  920. sb->s_magic = OCFS2_SUPER_MAGIC;
  921. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  922. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  923. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  924. * heartbeat=none */
  925. if (bdev_read_only(sb->s_bdev)) {
  926. if (!(sb->s_flags & MS_RDONLY)) {
  927. status = -EACCES;
  928. mlog(ML_ERROR, "Readonly device detected but readonly "
  929. "mount was not specified.\n");
  930. goto read_super_error;
  931. }
  932. /* You should not be able to start a local heartbeat
  933. * on a readonly device. */
  934. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  935. status = -EROFS;
  936. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  937. "device.\n");
  938. goto read_super_error;
  939. }
  940. status = ocfs2_check_journals_nolocks(osb);
  941. if (status < 0) {
  942. if (status == -EROFS)
  943. mlog(ML_ERROR, "Recovery required on readonly "
  944. "file system, but write access is "
  945. "unavailable.\n");
  946. else
  947. mlog_errno(status);
  948. goto read_super_error;
  949. }
  950. ocfs2_set_ro_flag(osb, 1);
  951. printk(KERN_NOTICE "Readonly device detected. No cluster "
  952. "services will be utilized for this mount. Recovery "
  953. "will be skipped.\n");
  954. }
  955. if (!ocfs2_is_hard_readonly(osb)) {
  956. if (sb->s_flags & MS_RDONLY)
  957. ocfs2_set_ro_flag(osb, 0);
  958. }
  959. status = ocfs2_verify_heartbeat(osb);
  960. if (status < 0) {
  961. mlog_errno(status);
  962. goto read_super_error;
  963. }
  964. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  965. ocfs2_debugfs_root);
  966. if (!osb->osb_debug_root) {
  967. status = -EINVAL;
  968. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  969. goto read_super_error;
  970. }
  971. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  972. osb->osb_debug_root,
  973. osb,
  974. &ocfs2_osb_debug_fops);
  975. if (!osb->osb_ctxt) {
  976. status = -EINVAL;
  977. mlog_errno(status);
  978. goto read_super_error;
  979. }
  980. status = ocfs2_mount_volume(sb);
  981. if (osb->root_inode)
  982. inode = igrab(osb->root_inode);
  983. if (status < 0)
  984. goto read_super_error;
  985. if (!inode) {
  986. status = -EIO;
  987. mlog_errno(status);
  988. goto read_super_error;
  989. }
  990. root = d_alloc_root(inode);
  991. if (!root) {
  992. status = -ENOMEM;
  993. mlog_errno(status);
  994. goto read_super_error;
  995. }
  996. sb->s_root = root;
  997. ocfs2_complete_mount_recovery(osb);
  998. if (ocfs2_mount_local(osb))
  999. snprintf(nodestr, sizeof(nodestr), "local");
  1000. else
  1001. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1002. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1003. "with %s data mode.\n",
  1004. osb->dev_str, nodestr, osb->slot_num,
  1005. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1006. "ordered");
  1007. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1008. wake_up(&osb->osb_mount_event);
  1009. /* Now we can initialize quotas because we can afford to wait
  1010. * for cluster locks recovery now. That also means that truncation
  1011. * log recovery can happen but that waits for proper quota setup */
  1012. if (!(sb->s_flags & MS_RDONLY)) {
  1013. status = ocfs2_enable_quotas(osb);
  1014. if (status < 0) {
  1015. /* We have to err-out specially here because
  1016. * s_root is already set */
  1017. mlog_errno(status);
  1018. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1019. wake_up(&osb->osb_mount_event);
  1020. mlog_exit(status);
  1021. return status;
  1022. }
  1023. }
  1024. ocfs2_complete_quota_recovery(osb);
  1025. /* Now we wake up again for processes waiting for quotas */
  1026. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1027. wake_up(&osb->osb_mount_event);
  1028. mlog_exit(status);
  1029. return status;
  1030. read_super_error:
  1031. brelse(bh);
  1032. if (inode)
  1033. iput(inode);
  1034. if (osb) {
  1035. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1036. wake_up(&osb->osb_mount_event);
  1037. ocfs2_dismount_volume(sb, 1);
  1038. }
  1039. mlog_exit(status);
  1040. return status;
  1041. }
  1042. static int ocfs2_get_sb(struct file_system_type *fs_type,
  1043. int flags,
  1044. const char *dev_name,
  1045. void *data,
  1046. struct vfsmount *mnt)
  1047. {
  1048. return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
  1049. mnt);
  1050. }
  1051. static struct file_system_type ocfs2_fs_type = {
  1052. .owner = THIS_MODULE,
  1053. .name = "ocfs2",
  1054. .get_sb = ocfs2_get_sb, /* is this called when we mount
  1055. * the fs? */
  1056. .kill_sb = kill_block_super, /* set to the generic one
  1057. * right now, but do we
  1058. * need to change that? */
  1059. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1060. .next = NULL
  1061. };
  1062. static int ocfs2_parse_options(struct super_block *sb,
  1063. char *options,
  1064. struct mount_options *mopt,
  1065. int is_remount)
  1066. {
  1067. int status;
  1068. char *p;
  1069. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  1070. options ? options : "(none)");
  1071. mopt->commit_interval = 0;
  1072. mopt->mount_opt = 0;
  1073. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1074. mopt->slot = OCFS2_INVALID_SLOT;
  1075. mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
  1076. mopt->cluster_stack[0] = '\0';
  1077. if (!options) {
  1078. status = 1;
  1079. goto bail;
  1080. }
  1081. while ((p = strsep(&options, ",")) != NULL) {
  1082. int token, option;
  1083. substring_t args[MAX_OPT_ARGS];
  1084. if (!*p)
  1085. continue;
  1086. token = match_token(p, tokens, args);
  1087. switch (token) {
  1088. case Opt_hb_local:
  1089. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1090. break;
  1091. case Opt_hb_none:
  1092. mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
  1093. break;
  1094. case Opt_barrier:
  1095. if (match_int(&args[0], &option)) {
  1096. status = 0;
  1097. goto bail;
  1098. }
  1099. if (option)
  1100. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1101. else
  1102. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1103. break;
  1104. case Opt_intr:
  1105. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1106. break;
  1107. case Opt_nointr:
  1108. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1109. break;
  1110. case Opt_err_panic:
  1111. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1112. break;
  1113. case Opt_err_ro:
  1114. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1115. break;
  1116. case Opt_data_ordered:
  1117. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1118. break;
  1119. case Opt_data_writeback:
  1120. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1121. break;
  1122. case Opt_user_xattr:
  1123. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1124. break;
  1125. case Opt_nouser_xattr:
  1126. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1127. break;
  1128. case Opt_atime_quantum:
  1129. if (match_int(&args[0], &option)) {
  1130. status = 0;
  1131. goto bail;
  1132. }
  1133. if (option >= 0)
  1134. mopt->atime_quantum = option;
  1135. break;
  1136. case Opt_slot:
  1137. option = 0;
  1138. if (match_int(&args[0], &option)) {
  1139. status = 0;
  1140. goto bail;
  1141. }
  1142. if (option)
  1143. mopt->slot = (s16)option;
  1144. break;
  1145. case Opt_commit:
  1146. option = 0;
  1147. if (match_int(&args[0], &option)) {
  1148. status = 0;
  1149. goto bail;
  1150. }
  1151. if (option < 0)
  1152. return 0;
  1153. if (option == 0)
  1154. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1155. mopt->commit_interval = HZ * option;
  1156. break;
  1157. case Opt_localalloc:
  1158. option = 0;
  1159. if (match_int(&args[0], &option)) {
  1160. status = 0;
  1161. goto bail;
  1162. }
  1163. if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
  1164. mopt->localalloc_opt = option;
  1165. break;
  1166. case Opt_localflocks:
  1167. /*
  1168. * Changing this during remount could race
  1169. * flock() requests, or "unbalance" existing
  1170. * ones (e.g., a lock is taken in one mode but
  1171. * dropped in the other). If users care enough
  1172. * to flip locking modes during remount, we
  1173. * could add a "local" flag to individual
  1174. * flock structures for proper tracking of
  1175. * state.
  1176. */
  1177. if (!is_remount)
  1178. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1179. break;
  1180. case Opt_stack:
  1181. /* Check both that the option we were passed
  1182. * is of the right length and that it is a proper
  1183. * string of the right length.
  1184. */
  1185. if (((args[0].to - args[0].from) !=
  1186. OCFS2_STACK_LABEL_LEN) ||
  1187. (strnlen(args[0].from,
  1188. OCFS2_STACK_LABEL_LEN) !=
  1189. OCFS2_STACK_LABEL_LEN)) {
  1190. mlog(ML_ERROR,
  1191. "Invalid cluster_stack option\n");
  1192. status = 0;
  1193. goto bail;
  1194. }
  1195. memcpy(mopt->cluster_stack, args[0].from,
  1196. OCFS2_STACK_LABEL_LEN);
  1197. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1198. break;
  1199. case Opt_inode64:
  1200. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1201. break;
  1202. case Opt_usrquota:
  1203. /* We check only on remount, otherwise features
  1204. * aren't yet initialized. */
  1205. if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1206. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1207. mlog(ML_ERROR, "User quota requested but "
  1208. "filesystem feature is not set\n");
  1209. status = 0;
  1210. goto bail;
  1211. }
  1212. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1213. break;
  1214. case Opt_grpquota:
  1215. if (is_remount && !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1216. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1217. mlog(ML_ERROR, "Group quota requested but "
  1218. "filesystem feature is not set\n");
  1219. status = 0;
  1220. goto bail;
  1221. }
  1222. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1223. break;
  1224. #ifdef CONFIG_OCFS2_FS_POSIX_ACL
  1225. case Opt_acl:
  1226. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1227. break;
  1228. case Opt_noacl:
  1229. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1230. break;
  1231. #else
  1232. case Opt_acl:
  1233. case Opt_noacl:
  1234. printk(KERN_INFO "ocfs2 (no)acl options not supported\n");
  1235. break;
  1236. #endif
  1237. default:
  1238. mlog(ML_ERROR,
  1239. "Unrecognized mount option \"%s\" "
  1240. "or missing value\n", p);
  1241. status = 0;
  1242. goto bail;
  1243. }
  1244. }
  1245. status = 1;
  1246. bail:
  1247. mlog_exit(status);
  1248. return status;
  1249. }
  1250. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1251. {
  1252. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  1253. unsigned long opts = osb->s_mount_opt;
  1254. unsigned int local_alloc_megs;
  1255. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1256. seq_printf(s, ",_netdev,heartbeat=local");
  1257. else
  1258. seq_printf(s, ",heartbeat=none");
  1259. if (opts & OCFS2_MOUNT_NOINTR)
  1260. seq_printf(s, ",nointr");
  1261. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1262. seq_printf(s, ",data=writeback");
  1263. else
  1264. seq_printf(s, ",data=ordered");
  1265. if (opts & OCFS2_MOUNT_BARRIER)
  1266. seq_printf(s, ",barrier=1");
  1267. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1268. seq_printf(s, ",errors=panic");
  1269. else
  1270. seq_printf(s, ",errors=remount-ro");
  1271. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1272. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1273. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  1274. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1275. if (osb->osb_commit_interval)
  1276. seq_printf(s, ",commit=%u",
  1277. (unsigned) (osb->osb_commit_interval / HZ));
  1278. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1279. if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
  1280. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1281. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1282. seq_printf(s, ",localflocks,");
  1283. if (osb->osb_cluster_stack[0])
  1284. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  1285. osb->osb_cluster_stack);
  1286. if (opts & OCFS2_MOUNT_USRQUOTA)
  1287. seq_printf(s, ",usrquota");
  1288. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1289. seq_printf(s, ",grpquota");
  1290. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1291. seq_printf(s, ",nouser_xattr");
  1292. else
  1293. seq_printf(s, ",user_xattr");
  1294. if (opts & OCFS2_MOUNT_INODE64)
  1295. seq_printf(s, ",inode64");
  1296. #ifdef CONFIG_OCFS2_FS_POSIX_ACL
  1297. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1298. seq_printf(s, ",acl");
  1299. else
  1300. seq_printf(s, ",noacl");
  1301. #endif
  1302. return 0;
  1303. }
  1304. static int __init ocfs2_init(void)
  1305. {
  1306. int status;
  1307. mlog_entry_void();
  1308. ocfs2_print_version();
  1309. status = init_ocfs2_uptodate_cache();
  1310. if (status < 0) {
  1311. mlog_errno(status);
  1312. goto leave;
  1313. }
  1314. status = ocfs2_initialize_mem_caches();
  1315. if (status < 0) {
  1316. mlog_errno(status);
  1317. goto leave;
  1318. }
  1319. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  1320. if (!ocfs2_wq) {
  1321. status = -ENOMEM;
  1322. goto leave;
  1323. }
  1324. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1325. if (!ocfs2_debugfs_root) {
  1326. status = -EFAULT;
  1327. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1328. }
  1329. status = ocfs2_quota_setup();
  1330. if (status)
  1331. goto leave;
  1332. ocfs2_set_locking_protocol();
  1333. status = register_quota_format(&ocfs2_quota_format);
  1334. leave:
  1335. if (status < 0) {
  1336. ocfs2_quota_shutdown();
  1337. ocfs2_free_mem_caches();
  1338. exit_ocfs2_uptodate_cache();
  1339. }
  1340. mlog_exit(status);
  1341. if (status >= 0) {
  1342. return register_filesystem(&ocfs2_fs_type);
  1343. } else
  1344. return -1;
  1345. }
  1346. static void __exit ocfs2_exit(void)
  1347. {
  1348. mlog_entry_void();
  1349. ocfs2_quota_shutdown();
  1350. if (ocfs2_wq) {
  1351. flush_workqueue(ocfs2_wq);
  1352. destroy_workqueue(ocfs2_wq);
  1353. }
  1354. unregister_quota_format(&ocfs2_quota_format);
  1355. debugfs_remove(ocfs2_debugfs_root);
  1356. ocfs2_free_mem_caches();
  1357. unregister_filesystem(&ocfs2_fs_type);
  1358. exit_ocfs2_uptodate_cache();
  1359. mlog_exit_void();
  1360. }
  1361. static void ocfs2_put_super(struct super_block *sb)
  1362. {
  1363. mlog_entry("(0x%p)\n", sb);
  1364. ocfs2_sync_blockdev(sb);
  1365. ocfs2_dismount_volume(sb, 0);
  1366. mlog_exit_void();
  1367. }
  1368. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1369. {
  1370. struct ocfs2_super *osb;
  1371. u32 numbits, freebits;
  1372. int status;
  1373. struct ocfs2_dinode *bm_lock;
  1374. struct buffer_head *bh = NULL;
  1375. struct inode *inode = NULL;
  1376. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  1377. osb = OCFS2_SB(dentry->d_sb);
  1378. inode = ocfs2_get_system_file_inode(osb,
  1379. GLOBAL_BITMAP_SYSTEM_INODE,
  1380. OCFS2_INVALID_SLOT);
  1381. if (!inode) {
  1382. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1383. status = -EIO;
  1384. goto bail;
  1385. }
  1386. status = ocfs2_inode_lock(inode, &bh, 0);
  1387. if (status < 0) {
  1388. mlog_errno(status);
  1389. goto bail;
  1390. }
  1391. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1392. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1393. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1394. buf->f_type = OCFS2_SUPER_MAGIC;
  1395. buf->f_bsize = dentry->d_sb->s_blocksize;
  1396. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1397. buf->f_blocks = ((sector_t) numbits) *
  1398. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1399. buf->f_bfree = ((sector_t) freebits) *
  1400. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1401. buf->f_bavail = buf->f_bfree;
  1402. buf->f_files = numbits;
  1403. buf->f_ffree = freebits;
  1404. brelse(bh);
  1405. ocfs2_inode_unlock(inode, 0);
  1406. status = 0;
  1407. bail:
  1408. if (inode)
  1409. iput(inode);
  1410. mlog_exit(status);
  1411. return status;
  1412. }
  1413. static void ocfs2_inode_init_once(void *data)
  1414. {
  1415. struct ocfs2_inode_info *oi = data;
  1416. oi->ip_flags = 0;
  1417. oi->ip_open_count = 0;
  1418. spin_lock_init(&oi->ip_lock);
  1419. ocfs2_extent_map_init(&oi->vfs_inode);
  1420. INIT_LIST_HEAD(&oi->ip_io_markers);
  1421. oi->ip_created_trans = 0;
  1422. oi->ip_last_trans = 0;
  1423. oi->ip_dir_start_lookup = 0;
  1424. init_rwsem(&oi->ip_alloc_sem);
  1425. init_rwsem(&oi->ip_xattr_sem);
  1426. mutex_init(&oi->ip_io_mutex);
  1427. oi->ip_blkno = 0ULL;
  1428. oi->ip_clusters = 0;
  1429. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1430. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1431. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1432. ocfs2_metadata_cache_init(&oi->vfs_inode);
  1433. inode_init_once(&oi->vfs_inode);
  1434. }
  1435. static int ocfs2_initialize_mem_caches(void)
  1436. {
  1437. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1438. sizeof(struct ocfs2_inode_info),
  1439. 0,
  1440. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1441. SLAB_MEM_SPREAD),
  1442. ocfs2_inode_init_once);
  1443. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1444. sizeof(struct ocfs2_dquot),
  1445. 0,
  1446. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1447. SLAB_MEM_SPREAD),
  1448. NULL);
  1449. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1450. sizeof(struct ocfs2_quota_chunk),
  1451. 0,
  1452. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1453. NULL);
  1454. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1455. !ocfs2_qf_chunk_cachep) {
  1456. if (ocfs2_inode_cachep)
  1457. kmem_cache_destroy(ocfs2_inode_cachep);
  1458. if (ocfs2_dquot_cachep)
  1459. kmem_cache_destroy(ocfs2_dquot_cachep);
  1460. if (ocfs2_qf_chunk_cachep)
  1461. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1462. return -ENOMEM;
  1463. }
  1464. return 0;
  1465. }
  1466. static void ocfs2_free_mem_caches(void)
  1467. {
  1468. if (ocfs2_inode_cachep)
  1469. kmem_cache_destroy(ocfs2_inode_cachep);
  1470. ocfs2_inode_cachep = NULL;
  1471. if (ocfs2_dquot_cachep)
  1472. kmem_cache_destroy(ocfs2_dquot_cachep);
  1473. ocfs2_dquot_cachep = NULL;
  1474. if (ocfs2_qf_chunk_cachep)
  1475. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1476. ocfs2_qf_chunk_cachep = NULL;
  1477. }
  1478. static int ocfs2_get_sector(struct super_block *sb,
  1479. struct buffer_head **bh,
  1480. int block,
  1481. int sect_size)
  1482. {
  1483. if (!sb_set_blocksize(sb, sect_size)) {
  1484. mlog(ML_ERROR, "unable to set blocksize\n");
  1485. return -EIO;
  1486. }
  1487. *bh = sb_getblk(sb, block);
  1488. if (!*bh) {
  1489. mlog_errno(-EIO);
  1490. return -EIO;
  1491. }
  1492. lock_buffer(*bh);
  1493. if (!buffer_dirty(*bh))
  1494. clear_buffer_uptodate(*bh);
  1495. unlock_buffer(*bh);
  1496. ll_rw_block(READ, 1, bh);
  1497. wait_on_buffer(*bh);
  1498. if (!buffer_uptodate(*bh)) {
  1499. mlog_errno(-EIO);
  1500. brelse(*bh);
  1501. *bh = NULL;
  1502. return -EIO;
  1503. }
  1504. return 0;
  1505. }
  1506. static int ocfs2_mount_volume(struct super_block *sb)
  1507. {
  1508. int status = 0;
  1509. int unlock_super = 0;
  1510. struct ocfs2_super *osb = OCFS2_SB(sb);
  1511. mlog_entry_void();
  1512. if (ocfs2_is_hard_readonly(osb))
  1513. goto leave;
  1514. status = ocfs2_dlm_init(osb);
  1515. if (status < 0) {
  1516. mlog_errno(status);
  1517. goto leave;
  1518. }
  1519. status = ocfs2_super_lock(osb, 1);
  1520. if (status < 0) {
  1521. mlog_errno(status);
  1522. goto leave;
  1523. }
  1524. unlock_super = 1;
  1525. /* This will load up the node map and add ourselves to it. */
  1526. status = ocfs2_find_slot(osb);
  1527. if (status < 0) {
  1528. mlog_errno(status);
  1529. goto leave;
  1530. }
  1531. /* load all node-local system inodes */
  1532. status = ocfs2_init_local_system_inodes(osb);
  1533. if (status < 0) {
  1534. mlog_errno(status);
  1535. goto leave;
  1536. }
  1537. status = ocfs2_check_volume(osb);
  1538. if (status < 0) {
  1539. mlog_errno(status);
  1540. goto leave;
  1541. }
  1542. status = ocfs2_truncate_log_init(osb);
  1543. if (status < 0) {
  1544. mlog_errno(status);
  1545. goto leave;
  1546. }
  1547. if (ocfs2_mount_local(osb))
  1548. goto leave;
  1549. leave:
  1550. if (unlock_super)
  1551. ocfs2_super_unlock(osb, 1);
  1552. mlog_exit(status);
  1553. return status;
  1554. }
  1555. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1556. {
  1557. int tmp, hangup_needed = 0;
  1558. struct ocfs2_super *osb = NULL;
  1559. char nodestr[8];
  1560. mlog_entry("(0x%p)\n", sb);
  1561. BUG_ON(!sb);
  1562. osb = OCFS2_SB(sb);
  1563. BUG_ON(!osb);
  1564. debugfs_remove(osb->osb_ctxt);
  1565. ocfs2_disable_quotas(osb);
  1566. ocfs2_shutdown_local_alloc(osb);
  1567. ocfs2_truncate_log_shutdown(osb);
  1568. ocfs2_orphan_scan_stop(osb);
  1569. /* This will disable recovery and flush any recovery work. */
  1570. ocfs2_recovery_exit(osb);
  1571. ocfs2_journal_shutdown(osb);
  1572. ocfs2_sync_blockdev(sb);
  1573. /* No cluster connection means we've failed during mount, so skip
  1574. * all the steps which depended on that to complete. */
  1575. if (osb->cconn) {
  1576. tmp = ocfs2_super_lock(osb, 1);
  1577. if (tmp < 0) {
  1578. mlog_errno(tmp);
  1579. return;
  1580. }
  1581. }
  1582. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1583. ocfs2_put_slot(osb);
  1584. if (osb->cconn)
  1585. ocfs2_super_unlock(osb, 1);
  1586. ocfs2_release_system_inodes(osb);
  1587. /*
  1588. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1589. * up heartbeat. If we're a local mount, there is no heartbeat.
  1590. * If we failed before we got a uuid_str yet, we can't stop
  1591. * heartbeat. Otherwise, do it.
  1592. */
  1593. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1594. hangup_needed = 1;
  1595. if (osb->cconn)
  1596. ocfs2_dlm_shutdown(osb, hangup_needed);
  1597. debugfs_remove(osb->osb_debug_root);
  1598. if (hangup_needed)
  1599. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1600. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1601. if (ocfs2_mount_local(osb))
  1602. snprintf(nodestr, sizeof(nodestr), "local");
  1603. else
  1604. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1605. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1606. osb->dev_str, nodestr);
  1607. ocfs2_delete_osb(osb);
  1608. kfree(osb);
  1609. sb->s_dev = 0;
  1610. sb->s_fs_info = NULL;
  1611. }
  1612. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1613. unsigned uuid_bytes)
  1614. {
  1615. int i, ret;
  1616. char *ptr;
  1617. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1618. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1619. if (osb->uuid_str == NULL)
  1620. return -ENOMEM;
  1621. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1622. /* print with null */
  1623. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1624. if (ret != 2) /* drop super cleans up */
  1625. return -EINVAL;
  1626. /* then only advance past the last char */
  1627. ptr += 2;
  1628. }
  1629. return 0;
  1630. }
  1631. static int ocfs2_initialize_super(struct super_block *sb,
  1632. struct buffer_head *bh,
  1633. int sector_size)
  1634. {
  1635. int status;
  1636. int i, cbits, bbits;
  1637. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1638. struct inode *inode = NULL;
  1639. struct ocfs2_journal *journal;
  1640. __le32 uuid_net_key;
  1641. struct ocfs2_super *osb;
  1642. mlog_entry_void();
  1643. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1644. if (!osb) {
  1645. status = -ENOMEM;
  1646. mlog_errno(status);
  1647. goto bail;
  1648. }
  1649. sb->s_fs_info = osb;
  1650. sb->s_op = &ocfs2_sops;
  1651. sb->s_export_op = &ocfs2_export_ops;
  1652. sb->s_qcop = &ocfs2_quotactl_ops;
  1653. sb->dq_op = &ocfs2_quota_operations;
  1654. sb->s_xattr = ocfs2_xattr_handlers;
  1655. sb->s_time_gran = 1;
  1656. sb->s_flags |= MS_NOATIME;
  1657. /* this is needed to support O_LARGEFILE */
  1658. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1659. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1660. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1661. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1662. for (i = 0; i < 3; i++)
  1663. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1664. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1665. osb->sb = sb;
  1666. /* Save off for ocfs2_rw_direct */
  1667. osb->s_sectsize_bits = blksize_bits(sector_size);
  1668. BUG_ON(!osb->s_sectsize_bits);
  1669. spin_lock_init(&osb->dc_task_lock);
  1670. init_waitqueue_head(&osb->dc_event);
  1671. osb->dc_work_sequence = 0;
  1672. osb->dc_wake_sequence = 0;
  1673. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1674. osb->blocked_lock_count = 0;
  1675. spin_lock_init(&osb->osb_lock);
  1676. spin_lock_init(&osb->osb_xattr_lock);
  1677. ocfs2_init_inode_steal_slot(osb);
  1678. atomic_set(&osb->alloc_stats.moves, 0);
  1679. atomic_set(&osb->alloc_stats.local_data, 0);
  1680. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1681. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1682. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1683. ocfs2_init_node_maps(osb);
  1684. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1685. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1686. status = ocfs2_recovery_init(osb);
  1687. if (status) {
  1688. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1689. mlog_errno(status);
  1690. goto bail;
  1691. }
  1692. status = ocfs2_orphan_scan_init(osb);
  1693. if (status) {
  1694. mlog(ML_ERROR, "Unable to initialize delayed orphan scan\n");
  1695. mlog_errno(status);
  1696. goto bail;
  1697. }
  1698. init_waitqueue_head(&osb->checkpoint_event);
  1699. atomic_set(&osb->needs_checkpoint, 0);
  1700. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1701. osb->slot_num = OCFS2_INVALID_SLOT;
  1702. osb->s_xattr_inline_size = le16_to_cpu(
  1703. di->id2.i_super.s_xattr_inline_size);
  1704. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1705. osb->local_alloc_bh = NULL;
  1706. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1707. init_waitqueue_head(&osb->osb_mount_event);
  1708. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1709. if (!osb->vol_label) {
  1710. mlog(ML_ERROR, "unable to alloc vol label\n");
  1711. status = -ENOMEM;
  1712. goto bail;
  1713. }
  1714. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1715. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1716. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1717. osb->max_slots);
  1718. status = -EINVAL;
  1719. goto bail;
  1720. }
  1721. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1722. osb->slot_recovery_generations =
  1723. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1724. GFP_KERNEL);
  1725. if (!osb->slot_recovery_generations) {
  1726. status = -ENOMEM;
  1727. mlog_errno(status);
  1728. goto bail;
  1729. }
  1730. init_waitqueue_head(&osb->osb_wipe_event);
  1731. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1732. sizeof(*osb->osb_orphan_wipes),
  1733. GFP_KERNEL);
  1734. if (!osb->osb_orphan_wipes) {
  1735. status = -ENOMEM;
  1736. mlog_errno(status);
  1737. goto bail;
  1738. }
  1739. osb->s_feature_compat =
  1740. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1741. osb->s_feature_ro_compat =
  1742. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1743. osb->s_feature_incompat =
  1744. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1745. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1746. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1747. "optional features (%x).\n", i);
  1748. status = -EINVAL;
  1749. goto bail;
  1750. }
  1751. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1752. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1753. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1754. "unsupported optional features (%x).\n", i);
  1755. status = -EINVAL;
  1756. goto bail;
  1757. }
  1758. if (ocfs2_userspace_stack(osb)) {
  1759. memcpy(osb->osb_cluster_stack,
  1760. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1761. OCFS2_STACK_LABEL_LEN);
  1762. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1763. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1764. mlog(ML_ERROR,
  1765. "couldn't mount because of an invalid "
  1766. "cluster stack label (%s) \n",
  1767. osb->osb_cluster_stack);
  1768. status = -EINVAL;
  1769. goto bail;
  1770. }
  1771. } else {
  1772. /* The empty string is identical with classic tools that
  1773. * don't know about s_cluster_info. */
  1774. osb->osb_cluster_stack[0] = '\0';
  1775. }
  1776. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1777. /* FIXME
  1778. * This should be done in ocfs2_journal_init(), but unknown
  1779. * ordering issues will cause the filesystem to crash.
  1780. * If anyone wants to figure out what part of the code
  1781. * refers to osb->journal before ocfs2_journal_init() is run,
  1782. * be my guest.
  1783. */
  1784. /* initialize our journal structure */
  1785. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1786. if (!journal) {
  1787. mlog(ML_ERROR, "unable to alloc journal\n");
  1788. status = -ENOMEM;
  1789. goto bail;
  1790. }
  1791. osb->journal = journal;
  1792. journal->j_osb = osb;
  1793. atomic_set(&journal->j_num_trans, 0);
  1794. init_rwsem(&journal->j_trans_barrier);
  1795. init_waitqueue_head(&journal->j_checkpointed);
  1796. spin_lock_init(&journal->j_lock);
  1797. journal->j_trans_id = (unsigned long) 1;
  1798. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1799. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1800. journal->j_state = OCFS2_JOURNAL_FREE;
  1801. INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  1802. osb->dentry_lock_list = NULL;
  1803. /* get some pseudo constants for clustersize bits */
  1804. osb->s_clustersize_bits =
  1805. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1806. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1807. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1808. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1809. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1810. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1811. osb->s_clustersize);
  1812. status = -EINVAL;
  1813. goto bail;
  1814. }
  1815. if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
  1816. > (u32)~0UL) {
  1817. mlog(ML_ERROR, "Volume might try to write to blocks beyond "
  1818. "what jbd can address in 32 bits.\n");
  1819. status = -EINVAL;
  1820. goto bail;
  1821. }
  1822. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1823. sizeof(di->id2.i_super.s_uuid))) {
  1824. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1825. status = -ENOMEM;
  1826. goto bail;
  1827. }
  1828. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  1829. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  1830. osb->vol_label[63] = '\0';
  1831. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1832. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1833. osb->first_cluster_group_blkno =
  1834. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1835. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1836. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1837. mlog(0, "vol_label: %s\n", osb->vol_label);
  1838. mlog(0, "uuid: %s\n", osb->uuid_str);
  1839. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  1840. (unsigned long long)osb->root_blkno,
  1841. (unsigned long long)osb->system_dir_blkno);
  1842. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1843. if (!osb->osb_dlm_debug) {
  1844. status = -ENOMEM;
  1845. mlog_errno(status);
  1846. goto bail;
  1847. }
  1848. atomic_set(&osb->vol_state, VOLUME_INIT);
  1849. /* load root, system_dir, and all global system inodes */
  1850. status = ocfs2_init_global_system_inodes(osb);
  1851. if (status < 0) {
  1852. mlog_errno(status);
  1853. goto bail;
  1854. }
  1855. /*
  1856. * global bitmap
  1857. */
  1858. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  1859. OCFS2_INVALID_SLOT);
  1860. if (!inode) {
  1861. status = -EINVAL;
  1862. mlog_errno(status);
  1863. goto bail;
  1864. }
  1865. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  1866. iput(inode);
  1867. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
  1868. status = ocfs2_init_slot_info(osb);
  1869. if (status < 0) {
  1870. mlog_errno(status);
  1871. goto bail;
  1872. }
  1873. bail:
  1874. mlog_exit(status);
  1875. return status;
  1876. }
  1877. /*
  1878. * will return: -EAGAIN if it is ok to keep searching for superblocks
  1879. * -EINVAL if there is a bad superblock
  1880. * 0 on success
  1881. */
  1882. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  1883. struct buffer_head *bh,
  1884. u32 blksz)
  1885. {
  1886. int status = -EAGAIN;
  1887. mlog_entry_void();
  1888. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  1889. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  1890. /* We have to do a raw check of the feature here */
  1891. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  1892. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  1893. status = ocfs2_block_check_validate(bh->b_data,
  1894. bh->b_size,
  1895. &di->i_check);
  1896. if (status)
  1897. goto out;
  1898. }
  1899. status = -EINVAL;
  1900. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  1901. mlog(ML_ERROR, "found superblock with incorrect block "
  1902. "size: found %u, should be %u\n",
  1903. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  1904. blksz);
  1905. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  1906. OCFS2_MAJOR_REV_LEVEL ||
  1907. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  1908. OCFS2_MINOR_REV_LEVEL) {
  1909. mlog(ML_ERROR, "found superblock with bad version: "
  1910. "found %u.%u, should be %u.%u\n",
  1911. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  1912. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  1913. OCFS2_MAJOR_REV_LEVEL,
  1914. OCFS2_MINOR_REV_LEVEL);
  1915. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  1916. mlog(ML_ERROR, "bad block number on superblock: "
  1917. "found %llu, should be %llu\n",
  1918. (unsigned long long)le64_to_cpu(di->i_blkno),
  1919. (unsigned long long)bh->b_blocknr);
  1920. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  1921. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  1922. mlog(ML_ERROR, "bad cluster size found: %u\n",
  1923. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  1924. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  1925. mlog(ML_ERROR, "bad root_blkno: 0\n");
  1926. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  1927. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  1928. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  1929. mlog(ML_ERROR,
  1930. "Superblock slots found greater than file system "
  1931. "maximum: found %u, max %u\n",
  1932. le16_to_cpu(di->id2.i_super.s_max_slots),
  1933. OCFS2_MAX_SLOTS);
  1934. } else {
  1935. /* found it! */
  1936. status = 0;
  1937. }
  1938. }
  1939. out:
  1940. mlog_exit(status);
  1941. return status;
  1942. }
  1943. static int ocfs2_check_volume(struct ocfs2_super *osb)
  1944. {
  1945. int status;
  1946. int dirty;
  1947. int local;
  1948. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  1949. * recover
  1950. * ourselves. */
  1951. mlog_entry_void();
  1952. /* Init our journal object. */
  1953. status = ocfs2_journal_init(osb->journal, &dirty);
  1954. if (status < 0) {
  1955. mlog(ML_ERROR, "Could not initialize journal!\n");
  1956. goto finally;
  1957. }
  1958. /* If the journal was unmounted cleanly then we don't want to
  1959. * recover anything. Otherwise, journal_load will do that
  1960. * dirty work for us :) */
  1961. if (!dirty) {
  1962. status = ocfs2_journal_wipe(osb->journal, 0);
  1963. if (status < 0) {
  1964. mlog_errno(status);
  1965. goto finally;
  1966. }
  1967. } else {
  1968. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  1969. "recovering volume.\n");
  1970. }
  1971. local = ocfs2_mount_local(osb);
  1972. /* will play back anything left in the journal. */
  1973. status = ocfs2_journal_load(osb->journal, local, dirty);
  1974. if (status < 0) {
  1975. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  1976. goto finally;
  1977. }
  1978. if (dirty) {
  1979. /* recover my local alloc if we didn't unmount cleanly. */
  1980. status = ocfs2_begin_local_alloc_recovery(osb,
  1981. osb->slot_num,
  1982. &local_alloc);
  1983. if (status < 0) {
  1984. mlog_errno(status);
  1985. goto finally;
  1986. }
  1987. /* we complete the recovery process after we've marked
  1988. * ourselves as mounted. */
  1989. }
  1990. mlog(0, "Journal loaded.\n");
  1991. status = ocfs2_load_local_alloc(osb);
  1992. if (status < 0) {
  1993. mlog_errno(status);
  1994. goto finally;
  1995. }
  1996. if (dirty) {
  1997. /* Recovery will be completed after we've mounted the
  1998. * rest of the volume. */
  1999. osb->dirty = 1;
  2000. osb->local_alloc_copy = local_alloc;
  2001. local_alloc = NULL;
  2002. }
  2003. /* go through each journal, trylock it and if you get the
  2004. * lock, and it's marked as dirty, set the bit in the recover
  2005. * map and launch a recovery thread for it. */
  2006. status = ocfs2_mark_dead_nodes(osb);
  2007. if (status < 0) {
  2008. mlog_errno(status);
  2009. goto finally;
  2010. }
  2011. status = ocfs2_compute_replay_slots(osb);
  2012. if (status < 0)
  2013. mlog_errno(status);
  2014. finally:
  2015. if (local_alloc)
  2016. kfree(local_alloc);
  2017. mlog_exit(status);
  2018. return status;
  2019. }
  2020. /*
  2021. * The routine gets called from dismount or close whenever a dismount on
  2022. * volume is requested and the osb open count becomes 1.
  2023. * It will remove the osb from the global list and also free up all the
  2024. * initialized resources and fileobject.
  2025. */
  2026. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2027. {
  2028. mlog_entry_void();
  2029. /* This function assumes that the caller has the main osb resource */
  2030. ocfs2_free_slot_info(osb);
  2031. kfree(osb->osb_orphan_wipes);
  2032. kfree(osb->slot_recovery_generations);
  2033. /* FIXME
  2034. * This belongs in journal shutdown, but because we have to
  2035. * allocate osb->journal at the start of ocfs2_initalize_osb(),
  2036. * we free it here.
  2037. */
  2038. kfree(osb->journal);
  2039. if (osb->local_alloc_copy)
  2040. kfree(osb->local_alloc_copy);
  2041. kfree(osb->uuid_str);
  2042. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2043. memset(osb, 0, sizeof(struct ocfs2_super));
  2044. mlog_exit_void();
  2045. }
  2046. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  2047. * panic(). We do not support continue-on-error operation. */
  2048. static void ocfs2_handle_error(struct super_block *sb)
  2049. {
  2050. struct ocfs2_super *osb = OCFS2_SB(sb);
  2051. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  2052. panic("OCFS2: (device %s): panic forced after error\n",
  2053. sb->s_id);
  2054. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2055. if (sb->s_flags & MS_RDONLY &&
  2056. (ocfs2_is_soft_readonly(osb) ||
  2057. ocfs2_is_hard_readonly(osb)))
  2058. return;
  2059. printk(KERN_CRIT "File system is now read-only due to the potential "
  2060. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  2061. "system is unmounted.\n");
  2062. sb->s_flags |= MS_RDONLY;
  2063. ocfs2_set_ro_flag(osb, 0);
  2064. }
  2065. static char error_buf[1024];
  2066. void __ocfs2_error(struct super_block *sb,
  2067. const char *function,
  2068. const char *fmt, ...)
  2069. {
  2070. va_list args;
  2071. va_start(args, fmt);
  2072. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2073. va_end(args);
  2074. /* Not using mlog here because we want to show the actual
  2075. * function the error came from. */
  2076. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  2077. sb->s_id, function, error_buf);
  2078. ocfs2_handle_error(sb);
  2079. }
  2080. /* Handle critical errors. This is intentionally more drastic than
  2081. * ocfs2_handle_error, so we only use for things like journal errors,
  2082. * etc. */
  2083. void __ocfs2_abort(struct super_block* sb,
  2084. const char *function,
  2085. const char *fmt, ...)
  2086. {
  2087. va_list args;
  2088. va_start(args, fmt);
  2089. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2090. va_end(args);
  2091. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  2092. sb->s_id, function, error_buf);
  2093. /* We don't have the cluster support yet to go straight to
  2094. * hard readonly in here. Until then, we want to keep
  2095. * ocfs2_abort() so that we can at least mark critical
  2096. * errors.
  2097. *
  2098. * TODO: This should abort the journal and alert other nodes
  2099. * that our slot needs recovery. */
  2100. /* Force a panic(). This stinks, but it's better than letting
  2101. * things continue without having a proper hard readonly
  2102. * here. */
  2103. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2104. ocfs2_handle_error(sb);
  2105. }
  2106. module_init(ocfs2_init);
  2107. module_exit(ocfs2_exit);