drbd_nl.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306
  1. /*
  2. drbd_nl.c
  3. This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
  4. Copyright (C) 2001-2008, LINBIT Information Technologies GmbH.
  5. Copyright (C) 1999-2008, Philipp Reisner <philipp.reisner@linbit.com>.
  6. Copyright (C) 2002-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
  7. drbd is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11. drbd is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with drbd; see the file COPYING. If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/drbd.h>
  21. #include <linux/in.h>
  22. #include <linux/fs.h>
  23. #include <linux/file.h>
  24. #include <linux/slab.h>
  25. #include <linux/blkpg.h>
  26. #include <linux/cpumask.h>
  27. #include "drbd_int.h"
  28. #include "drbd_req.h"
  29. #include "drbd_wrappers.h"
  30. #include <asm/unaligned.h>
  31. #include <linux/drbd_limits.h>
  32. #include <linux/kthread.h>
  33. #include <net/genetlink.h>
  34. /* .doit */
  35. // int drbd_adm_create_resource(struct sk_buff *skb, struct genl_info *info);
  36. // int drbd_adm_delete_resource(struct sk_buff *skb, struct genl_info *info);
  37. int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info);
  38. int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info);
  39. int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info);
  40. int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info);
  41. int drbd_adm_down(struct sk_buff *skb, struct genl_info *info);
  42. int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info);
  43. int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info);
  44. int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info);
  45. int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info);
  46. int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info);
  47. int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info);
  48. int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info);
  49. int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info);
  50. int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info);
  51. int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info);
  52. int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info);
  53. int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info);
  54. int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info);
  55. int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info);
  56. int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info);
  57. int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info);
  58. int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info);
  59. int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info);
  60. int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info);
  61. int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info);
  62. /* .dumpit */
  63. int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb);
  64. #include <linux/drbd_genl_api.h>
  65. #include "drbd_nla.h"
  66. #include <linux/genl_magic_func.h>
  67. /* used blkdev_get_by_path, to claim our meta data device(s) */
  68. static char *drbd_m_holder = "Hands off! this is DRBD's meta data device.";
  69. /* Configuration is strictly serialized, because generic netlink message
  70. * processing is strictly serialized by the genl_lock().
  71. * Which means we can use one static global drbd_config_context struct.
  72. */
  73. static struct drbd_config_context {
  74. /* assigned from drbd_genlmsghdr */
  75. unsigned int minor;
  76. /* assigned from request attributes, if present */
  77. unsigned int volume;
  78. #define VOLUME_UNSPECIFIED (-1U)
  79. /* pointer into the request skb,
  80. * limited lifetime! */
  81. char *resource_name;
  82. struct nlattr *my_addr;
  83. struct nlattr *peer_addr;
  84. /* reply buffer */
  85. struct sk_buff *reply_skb;
  86. /* pointer into reply buffer */
  87. struct drbd_genlmsghdr *reply_dh;
  88. /* resolved from attributes, if possible */
  89. struct drbd_conf *mdev;
  90. struct drbd_tconn *tconn;
  91. } adm_ctx;
  92. static void drbd_adm_send_reply(struct sk_buff *skb, struct genl_info *info)
  93. {
  94. genlmsg_end(skb, genlmsg_data(nlmsg_data(nlmsg_hdr(skb))));
  95. if (genlmsg_reply(skb, info))
  96. printk(KERN_ERR "drbd: error sending genl reply\n");
  97. }
  98. /* Used on a fresh "drbd_adm_prepare"d reply_skb, this cannot fail: The only
  99. * reason it could fail was no space in skb, and there are 4k available. */
  100. int drbd_msg_put_info(const char *info)
  101. {
  102. struct sk_buff *skb = adm_ctx.reply_skb;
  103. struct nlattr *nla;
  104. int err = -EMSGSIZE;
  105. if (!info || !info[0])
  106. return 0;
  107. nla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY);
  108. if (!nla)
  109. return err;
  110. err = nla_put_string(skb, T_info_text, info);
  111. if (err) {
  112. nla_nest_cancel(skb, nla);
  113. return err;
  114. } else
  115. nla_nest_end(skb, nla);
  116. return 0;
  117. }
  118. /* This would be a good candidate for a "pre_doit" hook,
  119. * and per-family private info->pointers.
  120. * But we need to stay compatible with older kernels.
  121. * If it returns successfully, adm_ctx members are valid.
  122. */
  123. #define DRBD_ADM_NEED_MINOR 1
  124. #define DRBD_ADM_NEED_RESOURCE 2
  125. #define DRBD_ADM_NEED_CONNECTION 4
  126. static int drbd_adm_prepare(struct sk_buff *skb, struct genl_info *info,
  127. unsigned flags)
  128. {
  129. struct drbd_genlmsghdr *d_in = info->userhdr;
  130. const u8 cmd = info->genlhdr->cmd;
  131. int err;
  132. memset(&adm_ctx, 0, sizeof(adm_ctx));
  133. /* genl_rcv_msg only checks for CAP_NET_ADMIN on "GENL_ADMIN_PERM" :( */
  134. if (cmd != DRBD_ADM_GET_STATUS
  135. && security_netlink_recv(skb, CAP_SYS_ADMIN))
  136. return -EPERM;
  137. adm_ctx.reply_skb = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
  138. if (!adm_ctx.reply_skb) {
  139. err = -ENOMEM;
  140. goto fail;
  141. }
  142. adm_ctx.reply_dh = genlmsg_put_reply(adm_ctx.reply_skb,
  143. info, &drbd_genl_family, 0, cmd);
  144. /* put of a few bytes into a fresh skb of >= 4k will always succeed.
  145. * but anyways */
  146. if (!adm_ctx.reply_dh) {
  147. err = -ENOMEM;
  148. goto fail;
  149. }
  150. adm_ctx.reply_dh->minor = d_in->minor;
  151. adm_ctx.reply_dh->ret_code = NO_ERROR;
  152. adm_ctx.volume = VOLUME_UNSPECIFIED;
  153. if (info->attrs[DRBD_NLA_CFG_CONTEXT]) {
  154. struct nlattr *nla;
  155. /* parse and validate only */
  156. err = drbd_cfg_context_from_attrs(NULL, info);
  157. if (err)
  158. goto fail;
  159. /* It was present, and valid,
  160. * copy it over to the reply skb. */
  161. err = nla_put_nohdr(adm_ctx.reply_skb,
  162. info->attrs[DRBD_NLA_CFG_CONTEXT]->nla_len,
  163. info->attrs[DRBD_NLA_CFG_CONTEXT]);
  164. if (err)
  165. goto fail;
  166. /* and assign stuff to the global adm_ctx */
  167. nla = nested_attr_tb[__nla_type(T_ctx_volume)];
  168. if (nla)
  169. adm_ctx.volume = nla_get_u32(nla);
  170. nla = nested_attr_tb[__nla_type(T_ctx_resource_name)];
  171. if (nla)
  172. adm_ctx.resource_name = nla_data(nla);
  173. adm_ctx.my_addr = nested_attr_tb[__nla_type(T_ctx_my_addr)];
  174. adm_ctx.peer_addr = nested_attr_tb[__nla_type(T_ctx_peer_addr)];
  175. if ((adm_ctx.my_addr &&
  176. nla_len(adm_ctx.my_addr) > sizeof(adm_ctx.tconn->my_addr)) ||
  177. (adm_ctx.peer_addr &&
  178. nla_len(adm_ctx.peer_addr) > sizeof(adm_ctx.tconn->peer_addr))) {
  179. err = -EINVAL;
  180. goto fail;
  181. }
  182. }
  183. adm_ctx.minor = d_in->minor;
  184. adm_ctx.mdev = minor_to_mdev(d_in->minor);
  185. adm_ctx.tconn = conn_get_by_name(adm_ctx.resource_name);
  186. if (!adm_ctx.mdev && (flags & DRBD_ADM_NEED_MINOR)) {
  187. drbd_msg_put_info("unknown minor");
  188. return ERR_MINOR_INVALID;
  189. }
  190. if (!adm_ctx.tconn && (flags & DRBD_ADM_NEED_RESOURCE)) {
  191. drbd_msg_put_info("unknown resource");
  192. return ERR_INVALID_REQUEST;
  193. }
  194. if (flags & DRBD_ADM_NEED_CONNECTION) {
  195. if (adm_ctx.tconn && !(flags & DRBD_ADM_NEED_RESOURCE)) {
  196. drbd_msg_put_info("no resource name expected");
  197. return ERR_INVALID_REQUEST;
  198. }
  199. if (adm_ctx.mdev) {
  200. drbd_msg_put_info("no minor number expected");
  201. return ERR_INVALID_REQUEST;
  202. }
  203. if (adm_ctx.my_addr && adm_ctx.peer_addr)
  204. adm_ctx.tconn = conn_get_by_addrs(nla_data(adm_ctx.my_addr),
  205. nla_len(adm_ctx.my_addr),
  206. nla_data(adm_ctx.peer_addr),
  207. nla_len(adm_ctx.peer_addr));
  208. if (!adm_ctx.tconn) {
  209. drbd_msg_put_info("unknown connection");
  210. return ERR_INVALID_REQUEST;
  211. }
  212. }
  213. /* some more paranoia, if the request was over-determined */
  214. if (adm_ctx.mdev && adm_ctx.tconn &&
  215. adm_ctx.mdev->tconn != adm_ctx.tconn) {
  216. pr_warning("request: minor=%u, resource=%s; but that minor belongs to connection %s\n",
  217. adm_ctx.minor, adm_ctx.resource_name,
  218. adm_ctx.mdev->tconn->name);
  219. drbd_msg_put_info("minor exists in different resource");
  220. return ERR_INVALID_REQUEST;
  221. }
  222. if (adm_ctx.mdev &&
  223. adm_ctx.volume != VOLUME_UNSPECIFIED &&
  224. adm_ctx.volume != adm_ctx.mdev->vnr) {
  225. pr_warning("request: minor=%u, volume=%u; but that minor is volume %u in %s\n",
  226. adm_ctx.minor, adm_ctx.volume,
  227. adm_ctx.mdev->vnr, adm_ctx.mdev->tconn->name);
  228. drbd_msg_put_info("minor exists as different volume");
  229. return ERR_INVALID_REQUEST;
  230. }
  231. return NO_ERROR;
  232. fail:
  233. nlmsg_free(adm_ctx.reply_skb);
  234. adm_ctx.reply_skb = NULL;
  235. return err;
  236. }
  237. static int drbd_adm_finish(struct genl_info *info, int retcode)
  238. {
  239. if (adm_ctx.tconn) {
  240. kref_put(&adm_ctx.tconn->kref, &conn_destroy);
  241. adm_ctx.tconn = NULL;
  242. }
  243. if (!adm_ctx.reply_skb)
  244. return -ENOMEM;
  245. adm_ctx.reply_dh->ret_code = retcode;
  246. drbd_adm_send_reply(adm_ctx.reply_skb, info);
  247. return 0;
  248. }
  249. static void setup_khelper_env(struct drbd_tconn *tconn, char **envp)
  250. {
  251. char *afs;
  252. /* FIXME: A future version will not allow this case. */
  253. if (tconn->my_addr_len == 0 || tconn->peer_addr_len == 0)
  254. return;
  255. switch (((struct sockaddr *)&tconn->peer_addr)->sa_family) {
  256. case AF_INET6:
  257. afs = "ipv6";
  258. snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI6",
  259. &((struct sockaddr_in6 *)&tconn->peer_addr)->sin6_addr);
  260. break;
  261. case AF_INET:
  262. afs = "ipv4";
  263. snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4",
  264. &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr);
  265. break;
  266. default:
  267. afs = "ssocks";
  268. snprintf(envp[4], 60, "DRBD_PEER_ADDRESS=%pI4",
  269. &((struct sockaddr_in *)&tconn->peer_addr)->sin_addr);
  270. }
  271. snprintf(envp[3], 20, "DRBD_PEER_AF=%s", afs);
  272. }
  273. int drbd_khelper(struct drbd_conf *mdev, char *cmd)
  274. {
  275. char *envp[] = { "HOME=/",
  276. "TERM=linux",
  277. "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
  278. (char[20]) { }, /* address family */
  279. (char[60]) { }, /* address */
  280. NULL };
  281. char mb[12];
  282. char *argv[] = {usermode_helper, cmd, mb, NULL };
  283. struct drbd_tconn *tconn = mdev->tconn;
  284. struct sib_info sib;
  285. int ret;
  286. if (current == tconn->worker.task)
  287. set_bit(CALLBACK_PENDING, &tconn->flags);
  288. snprintf(mb, 12, "minor-%d", mdev_to_minor(mdev));
  289. setup_khelper_env(tconn, envp);
  290. /* The helper may take some time.
  291. * write out any unsynced meta data changes now */
  292. drbd_md_sync(mdev);
  293. dev_info(DEV, "helper command: %s %s %s\n", usermode_helper, cmd, mb);
  294. sib.sib_reason = SIB_HELPER_PRE;
  295. sib.helper_name = cmd;
  296. drbd_bcast_event(mdev, &sib);
  297. ret = call_usermodehelper(usermode_helper, argv, envp, 1);
  298. if (ret)
  299. dev_warn(DEV, "helper command: %s %s %s exit code %u (0x%x)\n",
  300. usermode_helper, cmd, mb,
  301. (ret >> 8) & 0xff, ret);
  302. else
  303. dev_info(DEV, "helper command: %s %s %s exit code %u (0x%x)\n",
  304. usermode_helper, cmd, mb,
  305. (ret >> 8) & 0xff, ret);
  306. sib.sib_reason = SIB_HELPER_POST;
  307. sib.helper_exit_code = ret;
  308. drbd_bcast_event(mdev, &sib);
  309. if (current == tconn->worker.task)
  310. clear_bit(CALLBACK_PENDING, &tconn->flags);
  311. if (ret < 0) /* Ignore any ERRNOs we got. */
  312. ret = 0;
  313. return ret;
  314. }
  315. static void conn_md_sync(struct drbd_tconn *tconn)
  316. {
  317. struct drbd_conf *mdev;
  318. int vnr;
  319. rcu_read_lock();
  320. idr_for_each_entry(&tconn->volumes, mdev, vnr) {
  321. kref_get(&mdev->kref);
  322. rcu_read_unlock();
  323. drbd_md_sync(mdev);
  324. kref_put(&mdev->kref, &drbd_minor_destroy);
  325. rcu_read_lock();
  326. }
  327. rcu_read_unlock();
  328. }
  329. int conn_khelper(struct drbd_tconn *tconn, char *cmd)
  330. {
  331. char *envp[] = { "HOME=/",
  332. "TERM=linux",
  333. "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
  334. (char[20]) { }, /* address family */
  335. (char[60]) { }, /* address */
  336. NULL };
  337. char *argv[] = {usermode_helper, cmd, tconn->name, NULL };
  338. int ret;
  339. setup_khelper_env(tconn, envp);
  340. conn_md_sync(tconn);
  341. conn_info(tconn, "helper command: %s %s %s\n", usermode_helper, cmd, tconn->name);
  342. /* TODO: conn_bcast_event() ?? */
  343. ret = call_usermodehelper(usermode_helper, argv, envp, 1);
  344. if (ret)
  345. conn_warn(tconn, "helper command: %s %s %s exit code %u (0x%x)\n",
  346. usermode_helper, cmd, tconn->name,
  347. (ret >> 8) & 0xff, ret);
  348. else
  349. conn_info(tconn, "helper command: %s %s %s exit code %u (0x%x)\n",
  350. usermode_helper, cmd, tconn->name,
  351. (ret >> 8) & 0xff, ret);
  352. /* TODO: conn_bcast_event() ?? */
  353. if (ret < 0) /* Ignore any ERRNOs we got. */
  354. ret = 0;
  355. return ret;
  356. }
  357. static enum drbd_fencing_p highest_fencing_policy(struct drbd_tconn *tconn)
  358. {
  359. enum drbd_fencing_p fp = FP_NOT_AVAIL;
  360. struct drbd_conf *mdev;
  361. int vnr;
  362. rcu_read_lock();
  363. idr_for_each_entry(&tconn->volumes, mdev, vnr) {
  364. if (get_ldev_if_state(mdev, D_CONSISTENT)) {
  365. fp = max_t(enum drbd_fencing_p, fp,
  366. rcu_dereference(mdev->ldev->disk_conf)->fencing);
  367. put_ldev(mdev);
  368. }
  369. }
  370. rcu_read_unlock();
  371. return fp;
  372. }
  373. bool conn_try_outdate_peer(struct drbd_tconn *tconn)
  374. {
  375. union drbd_state mask = { };
  376. union drbd_state val = { };
  377. enum drbd_fencing_p fp;
  378. char *ex_to_string;
  379. int r;
  380. if (tconn->cstate >= C_WF_REPORT_PARAMS) {
  381. conn_err(tconn, "Expected cstate < C_WF_REPORT_PARAMS\n");
  382. return false;
  383. }
  384. fp = highest_fencing_policy(tconn);
  385. switch (fp) {
  386. case FP_NOT_AVAIL:
  387. conn_warn(tconn, "Not fencing peer, I'm not even Consistent myself.\n");
  388. goto out;
  389. case FP_DONT_CARE:
  390. return true;
  391. default: ;
  392. }
  393. r = conn_khelper(tconn, "fence-peer");
  394. switch ((r>>8) & 0xff) {
  395. case 3: /* peer is inconsistent */
  396. ex_to_string = "peer is inconsistent or worse";
  397. mask.pdsk = D_MASK;
  398. val.pdsk = D_INCONSISTENT;
  399. break;
  400. case 4: /* peer got outdated, or was already outdated */
  401. ex_to_string = "peer was fenced";
  402. mask.pdsk = D_MASK;
  403. val.pdsk = D_OUTDATED;
  404. break;
  405. case 5: /* peer was down */
  406. if (conn_highest_disk(tconn) == D_UP_TO_DATE) {
  407. /* we will(have) create(d) a new UUID anyways... */
  408. ex_to_string = "peer is unreachable, assumed to be dead";
  409. mask.pdsk = D_MASK;
  410. val.pdsk = D_OUTDATED;
  411. } else {
  412. ex_to_string = "peer unreachable, doing nothing since disk != UpToDate";
  413. }
  414. break;
  415. case 6: /* Peer is primary, voluntarily outdate myself.
  416. * This is useful when an unconnected R_SECONDARY is asked to
  417. * become R_PRIMARY, but finds the other peer being active. */
  418. ex_to_string = "peer is active";
  419. conn_warn(tconn, "Peer is primary, outdating myself.\n");
  420. mask.disk = D_MASK;
  421. val.disk = D_OUTDATED;
  422. break;
  423. case 7:
  424. if (fp != FP_STONITH)
  425. conn_err(tconn, "fence-peer() = 7 && fencing != Stonith !!!\n");
  426. ex_to_string = "peer was stonithed";
  427. mask.pdsk = D_MASK;
  428. val.pdsk = D_OUTDATED;
  429. break;
  430. default:
  431. /* The script is broken ... */
  432. conn_err(tconn, "fence-peer helper broken, returned %d\n", (r>>8)&0xff);
  433. return false; /* Eventually leave IO frozen */
  434. }
  435. conn_info(tconn, "fence-peer helper returned %d (%s)\n",
  436. (r>>8) & 0xff, ex_to_string);
  437. out:
  438. /* Not using
  439. conn_request_state(tconn, mask, val, CS_VERBOSE);
  440. here, because we might were able to re-establish the connection in the
  441. meantime. */
  442. spin_lock_irq(&tconn->req_lock);
  443. if (tconn->cstate < C_WF_REPORT_PARAMS && !test_bit(STATE_SENT, &tconn->flags))
  444. _conn_request_state(tconn, mask, val, CS_VERBOSE);
  445. spin_unlock_irq(&tconn->req_lock);
  446. return conn_highest_pdsk(tconn) <= D_OUTDATED;
  447. }
  448. static int _try_outdate_peer_async(void *data)
  449. {
  450. struct drbd_tconn *tconn = (struct drbd_tconn *)data;
  451. conn_try_outdate_peer(tconn);
  452. kref_put(&tconn->kref, &conn_destroy);
  453. return 0;
  454. }
  455. void conn_try_outdate_peer_async(struct drbd_tconn *tconn)
  456. {
  457. struct task_struct *opa;
  458. kref_get(&tconn->kref);
  459. opa = kthread_run(_try_outdate_peer_async, tconn, "drbd_async_h");
  460. if (IS_ERR(opa)) {
  461. conn_err(tconn, "out of mem, failed to invoke fence-peer helper\n");
  462. kref_put(&tconn->kref, &conn_destroy);
  463. }
  464. }
  465. enum drbd_state_rv
  466. drbd_set_role(struct drbd_conf *mdev, enum drbd_role new_role, int force)
  467. {
  468. const int max_tries = 4;
  469. enum drbd_state_rv rv = SS_UNKNOWN_ERROR;
  470. struct net_conf *nc;
  471. int try = 0;
  472. int forced = 0;
  473. union drbd_state mask, val;
  474. if (new_role == R_PRIMARY)
  475. request_ping(mdev->tconn); /* Detect a dead peer ASAP */
  476. mutex_lock(mdev->state_mutex);
  477. mask.i = 0; mask.role = R_MASK;
  478. val.i = 0; val.role = new_role;
  479. while (try++ < max_tries) {
  480. rv = _drbd_request_state(mdev, mask, val, CS_WAIT_COMPLETE);
  481. /* in case we first succeeded to outdate,
  482. * but now suddenly could establish a connection */
  483. if (rv == SS_CW_FAILED_BY_PEER && mask.pdsk != 0) {
  484. val.pdsk = 0;
  485. mask.pdsk = 0;
  486. continue;
  487. }
  488. if (rv == SS_NO_UP_TO_DATE_DISK && force &&
  489. (mdev->state.disk < D_UP_TO_DATE &&
  490. mdev->state.disk >= D_INCONSISTENT)) {
  491. mask.disk = D_MASK;
  492. val.disk = D_UP_TO_DATE;
  493. forced = 1;
  494. continue;
  495. }
  496. if (rv == SS_NO_UP_TO_DATE_DISK &&
  497. mdev->state.disk == D_CONSISTENT && mask.pdsk == 0) {
  498. D_ASSERT(mdev->state.pdsk == D_UNKNOWN);
  499. if (conn_try_outdate_peer(mdev->tconn)) {
  500. val.disk = D_UP_TO_DATE;
  501. mask.disk = D_MASK;
  502. }
  503. continue;
  504. }
  505. if (rv == SS_NOTHING_TO_DO)
  506. goto out;
  507. if (rv == SS_PRIMARY_NOP && mask.pdsk == 0) {
  508. if (!conn_try_outdate_peer(mdev->tconn) && force) {
  509. dev_warn(DEV, "Forced into split brain situation!\n");
  510. mask.pdsk = D_MASK;
  511. val.pdsk = D_OUTDATED;
  512. }
  513. continue;
  514. }
  515. if (rv == SS_TWO_PRIMARIES) {
  516. /* Maybe the peer is detected as dead very soon...
  517. retry at most once more in this case. */
  518. int timeo;
  519. rcu_read_lock();
  520. nc = rcu_dereference(mdev->tconn->net_conf);
  521. timeo = nc ? (nc->ping_timeo + 1) * HZ / 10 : 1;
  522. rcu_read_unlock();
  523. schedule_timeout_interruptible(timeo);
  524. if (try < max_tries)
  525. try = max_tries - 1;
  526. continue;
  527. }
  528. if (rv < SS_SUCCESS) {
  529. rv = _drbd_request_state(mdev, mask, val,
  530. CS_VERBOSE + CS_WAIT_COMPLETE);
  531. if (rv < SS_SUCCESS)
  532. goto out;
  533. }
  534. break;
  535. }
  536. if (rv < SS_SUCCESS)
  537. goto out;
  538. if (forced)
  539. dev_warn(DEV, "Forced to consider local data as UpToDate!\n");
  540. /* Wait until nothing is on the fly :) */
  541. wait_event(mdev->misc_wait, atomic_read(&mdev->ap_pending_cnt) == 0);
  542. /* FIXME also wait for all pending P_BARRIER_ACK? */
  543. if (new_role == R_SECONDARY) {
  544. set_disk_ro(mdev->vdisk, true);
  545. if (get_ldev(mdev)) {
  546. mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
  547. put_ldev(mdev);
  548. }
  549. } else {
  550. mutex_lock(&mdev->tconn->conf_update);
  551. nc = mdev->tconn->net_conf;
  552. if (nc)
  553. nc->discard_my_data = 0; /* without copy; single bit op is atomic */
  554. mutex_unlock(&mdev->tconn->conf_update);
  555. set_disk_ro(mdev->vdisk, false);
  556. if (get_ldev(mdev)) {
  557. if (((mdev->state.conn < C_CONNECTED ||
  558. mdev->state.pdsk <= D_FAILED)
  559. && mdev->ldev->md.uuid[UI_BITMAP] == 0) || forced)
  560. drbd_uuid_new_current(mdev);
  561. mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1;
  562. put_ldev(mdev);
  563. }
  564. }
  565. /* writeout of activity log covered areas of the bitmap
  566. * to stable storage done in after state change already */
  567. if (mdev->state.conn >= C_WF_REPORT_PARAMS) {
  568. /* if this was forced, we should consider sync */
  569. if (forced)
  570. drbd_send_uuids(mdev);
  571. drbd_send_current_state(mdev);
  572. }
  573. drbd_md_sync(mdev);
  574. kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
  575. out:
  576. mutex_unlock(mdev->state_mutex);
  577. return rv;
  578. }
  579. static const char *from_attrs_err_to_txt(int err)
  580. {
  581. return err == -ENOMSG ? "required attribute missing" :
  582. err == -EOPNOTSUPP ? "unknown mandatory attribute" :
  583. err == -EEXIST ? "can not change invariant setting" :
  584. "invalid attribute value";
  585. }
  586. int drbd_adm_set_role(struct sk_buff *skb, struct genl_info *info)
  587. {
  588. struct set_role_parms parms;
  589. int err;
  590. enum drbd_ret_code retcode;
  591. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  592. if (!adm_ctx.reply_skb)
  593. return retcode;
  594. if (retcode != NO_ERROR)
  595. goto out;
  596. memset(&parms, 0, sizeof(parms));
  597. if (info->attrs[DRBD_NLA_SET_ROLE_PARMS]) {
  598. err = set_role_parms_from_attrs(&parms, info);
  599. if (err) {
  600. retcode = ERR_MANDATORY_TAG;
  601. drbd_msg_put_info(from_attrs_err_to_txt(err));
  602. goto out;
  603. }
  604. }
  605. if (info->genlhdr->cmd == DRBD_ADM_PRIMARY)
  606. retcode = drbd_set_role(adm_ctx.mdev, R_PRIMARY, parms.assume_uptodate);
  607. else
  608. retcode = drbd_set_role(adm_ctx.mdev, R_SECONDARY, 0);
  609. out:
  610. drbd_adm_finish(info, retcode);
  611. return 0;
  612. }
  613. /* initializes the md.*_offset members, so we are able to find
  614. * the on disk meta data */
  615. static void drbd_md_set_sector_offsets(struct drbd_conf *mdev,
  616. struct drbd_backing_dev *bdev)
  617. {
  618. sector_t md_size_sect = 0;
  619. int meta_dev_idx;
  620. rcu_read_lock();
  621. meta_dev_idx = rcu_dereference(bdev->disk_conf)->meta_dev_idx;
  622. switch (meta_dev_idx) {
  623. default:
  624. /* v07 style fixed size indexed meta data */
  625. bdev->md.md_size_sect = MD_RESERVED_SECT;
  626. bdev->md.md_offset = drbd_md_ss__(mdev, bdev);
  627. bdev->md.al_offset = MD_AL_OFFSET;
  628. bdev->md.bm_offset = MD_BM_OFFSET;
  629. break;
  630. case DRBD_MD_INDEX_FLEX_EXT:
  631. /* just occupy the full device; unit: sectors */
  632. bdev->md.md_size_sect = drbd_get_capacity(bdev->md_bdev);
  633. bdev->md.md_offset = 0;
  634. bdev->md.al_offset = MD_AL_OFFSET;
  635. bdev->md.bm_offset = MD_BM_OFFSET;
  636. break;
  637. case DRBD_MD_INDEX_INTERNAL:
  638. case DRBD_MD_INDEX_FLEX_INT:
  639. bdev->md.md_offset = drbd_md_ss__(mdev, bdev);
  640. /* al size is still fixed */
  641. bdev->md.al_offset = -MD_AL_SECTORS;
  642. /* we need (slightly less than) ~ this much bitmap sectors: */
  643. md_size_sect = drbd_get_capacity(bdev->backing_bdev);
  644. md_size_sect = ALIGN(md_size_sect, BM_SECT_PER_EXT);
  645. md_size_sect = BM_SECT_TO_EXT(md_size_sect);
  646. md_size_sect = ALIGN(md_size_sect, 8);
  647. /* plus the "drbd meta data super block",
  648. * and the activity log; */
  649. md_size_sect += MD_BM_OFFSET;
  650. bdev->md.md_size_sect = md_size_sect;
  651. /* bitmap offset is adjusted by 'super' block size */
  652. bdev->md.bm_offset = -md_size_sect + MD_AL_OFFSET;
  653. break;
  654. }
  655. rcu_read_unlock();
  656. }
  657. /* input size is expected to be in KB */
  658. char *ppsize(char *buf, unsigned long long size)
  659. {
  660. /* Needs 9 bytes at max including trailing NUL:
  661. * -1ULL ==> "16384 EB" */
  662. static char units[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
  663. int base = 0;
  664. while (size >= 10000 && base < sizeof(units)-1) {
  665. /* shift + round */
  666. size = (size >> 10) + !!(size & (1<<9));
  667. base++;
  668. }
  669. sprintf(buf, "%u %cB", (unsigned)size, units[base]);
  670. return buf;
  671. }
  672. /* there is still a theoretical deadlock when called from receiver
  673. * on an D_INCONSISTENT R_PRIMARY:
  674. * remote READ does inc_ap_bio, receiver would need to receive answer
  675. * packet from remote to dec_ap_bio again.
  676. * receiver receive_sizes(), comes here,
  677. * waits for ap_bio_cnt == 0. -> deadlock.
  678. * but this cannot happen, actually, because:
  679. * R_PRIMARY D_INCONSISTENT, and peer's disk is unreachable
  680. * (not connected, or bad/no disk on peer):
  681. * see drbd_fail_request_early, ap_bio_cnt is zero.
  682. * R_PRIMARY D_INCONSISTENT, and C_SYNC_TARGET:
  683. * peer may not initiate a resize.
  684. */
  685. /* Note these are not to be confused with
  686. * drbd_adm_suspend_io/drbd_adm_resume_io,
  687. * which are (sub) state changes triggered by admin (drbdsetup),
  688. * and can be long lived.
  689. * This changes an mdev->flag, is triggered by drbd internals,
  690. * and should be short-lived. */
  691. void drbd_suspend_io(struct drbd_conf *mdev)
  692. {
  693. set_bit(SUSPEND_IO, &mdev->flags);
  694. if (drbd_suspended(mdev))
  695. return;
  696. wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_bio_cnt));
  697. }
  698. void drbd_resume_io(struct drbd_conf *mdev)
  699. {
  700. clear_bit(SUSPEND_IO, &mdev->flags);
  701. wake_up(&mdev->misc_wait);
  702. }
  703. /**
  704. * drbd_determine_dev_size() - Sets the right device size obeying all constraints
  705. * @mdev: DRBD device.
  706. *
  707. * Returns 0 on success, negative return values indicate errors.
  708. * You should call drbd_md_sync() after calling this function.
  709. */
  710. enum determine_dev_size drbd_determine_dev_size(struct drbd_conf *mdev, enum dds_flags flags) __must_hold(local)
  711. {
  712. sector_t prev_first_sect, prev_size; /* previous meta location */
  713. sector_t la_size, u_size;
  714. sector_t size;
  715. char ppb[10];
  716. int md_moved, la_size_changed;
  717. enum determine_dev_size rv = unchanged;
  718. /* race:
  719. * application request passes inc_ap_bio,
  720. * but then cannot get an AL-reference.
  721. * this function later may wait on ap_bio_cnt == 0. -> deadlock.
  722. *
  723. * to avoid that:
  724. * Suspend IO right here.
  725. * still lock the act_log to not trigger ASSERTs there.
  726. */
  727. drbd_suspend_io(mdev);
  728. /* no wait necessary anymore, actually we could assert that */
  729. wait_event(mdev->al_wait, lc_try_lock(mdev->act_log));
  730. prev_first_sect = drbd_md_first_sector(mdev->ldev);
  731. prev_size = mdev->ldev->md.md_size_sect;
  732. la_size = mdev->ldev->md.la_size_sect;
  733. /* TODO: should only be some assert here, not (re)init... */
  734. drbd_md_set_sector_offsets(mdev, mdev->ldev);
  735. rcu_read_lock();
  736. u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size;
  737. rcu_read_unlock();
  738. size = drbd_new_dev_size(mdev, mdev->ldev, u_size, flags & DDSF_FORCED);
  739. if (drbd_get_capacity(mdev->this_bdev) != size ||
  740. drbd_bm_capacity(mdev) != size) {
  741. int err;
  742. err = drbd_bm_resize(mdev, size, !(flags & DDSF_NO_RESYNC));
  743. if (unlikely(err)) {
  744. /* currently there is only one error: ENOMEM! */
  745. size = drbd_bm_capacity(mdev)>>1;
  746. if (size == 0) {
  747. dev_err(DEV, "OUT OF MEMORY! "
  748. "Could not allocate bitmap!\n");
  749. } else {
  750. dev_err(DEV, "BM resizing failed. "
  751. "Leaving size unchanged at size = %lu KB\n",
  752. (unsigned long)size);
  753. }
  754. rv = dev_size_error;
  755. }
  756. /* racy, see comments above. */
  757. drbd_set_my_capacity(mdev, size);
  758. mdev->ldev->md.la_size_sect = size;
  759. dev_info(DEV, "size = %s (%llu KB)\n", ppsize(ppb, size>>1),
  760. (unsigned long long)size>>1);
  761. }
  762. if (rv == dev_size_error)
  763. goto out;
  764. la_size_changed = (la_size != mdev->ldev->md.la_size_sect);
  765. md_moved = prev_first_sect != drbd_md_first_sector(mdev->ldev)
  766. || prev_size != mdev->ldev->md.md_size_sect;
  767. if (la_size_changed || md_moved) {
  768. int err;
  769. drbd_al_shrink(mdev); /* All extents inactive. */
  770. dev_info(DEV, "Writing the whole bitmap, %s\n",
  771. la_size_changed && md_moved ? "size changed and md moved" :
  772. la_size_changed ? "size changed" : "md moved");
  773. /* next line implicitly does drbd_suspend_io()+drbd_resume_io() */
  774. err = drbd_bitmap_io(mdev, &drbd_bm_write,
  775. "size changed", BM_LOCKED_MASK);
  776. if (err) {
  777. rv = dev_size_error;
  778. goto out;
  779. }
  780. drbd_md_mark_dirty(mdev);
  781. }
  782. if (size > la_size)
  783. rv = grew;
  784. if (size < la_size)
  785. rv = shrunk;
  786. out:
  787. lc_unlock(mdev->act_log);
  788. wake_up(&mdev->al_wait);
  789. drbd_resume_io(mdev);
  790. return rv;
  791. }
  792. sector_t
  793. drbd_new_dev_size(struct drbd_conf *mdev, struct drbd_backing_dev *bdev,
  794. sector_t u_size, int assume_peer_has_space)
  795. {
  796. sector_t p_size = mdev->p_size; /* partner's disk size. */
  797. sector_t la_size = bdev->md.la_size_sect; /* last agreed size. */
  798. sector_t m_size; /* my size */
  799. sector_t size = 0;
  800. m_size = drbd_get_max_capacity(bdev);
  801. if (mdev->state.conn < C_CONNECTED && assume_peer_has_space) {
  802. dev_warn(DEV, "Resize while not connected was forced by the user!\n");
  803. p_size = m_size;
  804. }
  805. if (p_size && m_size) {
  806. size = min_t(sector_t, p_size, m_size);
  807. } else {
  808. if (la_size) {
  809. size = la_size;
  810. if (m_size && m_size < size)
  811. size = m_size;
  812. if (p_size && p_size < size)
  813. size = p_size;
  814. } else {
  815. if (m_size)
  816. size = m_size;
  817. if (p_size)
  818. size = p_size;
  819. }
  820. }
  821. if (size == 0)
  822. dev_err(DEV, "Both nodes diskless!\n");
  823. if (u_size) {
  824. if (u_size > size)
  825. dev_err(DEV, "Requested disk size is too big (%lu > %lu)\n",
  826. (unsigned long)u_size>>1, (unsigned long)size>>1);
  827. else
  828. size = u_size;
  829. }
  830. return size;
  831. }
  832. /**
  833. * drbd_check_al_size() - Ensures that the AL is of the right size
  834. * @mdev: DRBD device.
  835. *
  836. * Returns -EBUSY if current al lru is still used, -ENOMEM when allocation
  837. * failed, and 0 on success. You should call drbd_md_sync() after you called
  838. * this function.
  839. */
  840. static int drbd_check_al_size(struct drbd_conf *mdev, struct disk_conf *dc)
  841. {
  842. struct lru_cache *n, *t;
  843. struct lc_element *e;
  844. unsigned int in_use;
  845. int i;
  846. if (mdev->act_log &&
  847. mdev->act_log->nr_elements == dc->al_extents)
  848. return 0;
  849. in_use = 0;
  850. t = mdev->act_log;
  851. n = lc_create("act_log", drbd_al_ext_cache, AL_UPDATES_PER_TRANSACTION,
  852. dc->al_extents, sizeof(struct lc_element), 0);
  853. if (n == NULL) {
  854. dev_err(DEV, "Cannot allocate act_log lru!\n");
  855. return -ENOMEM;
  856. }
  857. spin_lock_irq(&mdev->al_lock);
  858. if (t) {
  859. for (i = 0; i < t->nr_elements; i++) {
  860. e = lc_element_by_index(t, i);
  861. if (e->refcnt)
  862. dev_err(DEV, "refcnt(%d)==%d\n",
  863. e->lc_number, e->refcnt);
  864. in_use += e->refcnt;
  865. }
  866. }
  867. if (!in_use)
  868. mdev->act_log = n;
  869. spin_unlock_irq(&mdev->al_lock);
  870. if (in_use) {
  871. dev_err(DEV, "Activity log still in use!\n");
  872. lc_destroy(n);
  873. return -EBUSY;
  874. } else {
  875. if (t)
  876. lc_destroy(t);
  877. }
  878. drbd_md_mark_dirty(mdev); /* we changed mdev->act_log->nr_elemens */
  879. return 0;
  880. }
  881. static void drbd_setup_queue_param(struct drbd_conf *mdev, unsigned int max_bio_size)
  882. {
  883. struct request_queue * const q = mdev->rq_queue;
  884. int max_hw_sectors = max_bio_size >> 9;
  885. int max_segments = 0;
  886. if (get_ldev_if_state(mdev, D_ATTACHING)) {
  887. struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue;
  888. max_hw_sectors = min(queue_max_hw_sectors(b), max_bio_size >> 9);
  889. rcu_read_lock();
  890. max_segments = rcu_dereference(mdev->ldev->disk_conf)->max_bio_bvecs;
  891. rcu_read_unlock();
  892. put_ldev(mdev);
  893. }
  894. blk_queue_logical_block_size(q, 512);
  895. blk_queue_max_hw_sectors(q, max_hw_sectors);
  896. /* This is the workaround for "bio would need to, but cannot, be split" */
  897. blk_queue_max_segments(q, max_segments ? max_segments : BLK_MAX_SEGMENTS);
  898. blk_queue_segment_boundary(q, PAGE_CACHE_SIZE-1);
  899. if (get_ldev_if_state(mdev, D_ATTACHING)) {
  900. struct request_queue * const b = mdev->ldev->backing_bdev->bd_disk->queue;
  901. blk_queue_stack_limits(q, b);
  902. if (q->backing_dev_info.ra_pages != b->backing_dev_info.ra_pages) {
  903. dev_info(DEV, "Adjusting my ra_pages to backing device's (%lu -> %lu)\n",
  904. q->backing_dev_info.ra_pages,
  905. b->backing_dev_info.ra_pages);
  906. q->backing_dev_info.ra_pages = b->backing_dev_info.ra_pages;
  907. }
  908. put_ldev(mdev);
  909. }
  910. }
  911. void drbd_reconsider_max_bio_size(struct drbd_conf *mdev)
  912. {
  913. int now, new, local, peer;
  914. now = queue_max_hw_sectors(mdev->rq_queue) << 9;
  915. local = mdev->local_max_bio_size; /* Eventually last known value, from volatile memory */
  916. peer = mdev->peer_max_bio_size; /* Eventually last known value, from meta data */
  917. if (get_ldev_if_state(mdev, D_ATTACHING)) {
  918. local = queue_max_hw_sectors(mdev->ldev->backing_bdev->bd_disk->queue) << 9;
  919. mdev->local_max_bio_size = local;
  920. put_ldev(mdev);
  921. }
  922. /* We may ignore peer limits if the peer is modern enough.
  923. Because new from 8.3.8 onwards the peer can use multiple
  924. BIOs for a single peer_request */
  925. if (mdev->state.conn >= C_CONNECTED) {
  926. if (mdev->tconn->agreed_pro_version < 94)
  927. peer = min_t(int, mdev->peer_max_bio_size, DRBD_MAX_SIZE_H80_PACKET);
  928. /* Correct old drbd (up to 8.3.7) if it believes it can do more than 32KiB */
  929. else if (mdev->tconn->agreed_pro_version == 94)
  930. peer = DRBD_MAX_SIZE_H80_PACKET;
  931. else if (mdev->tconn->agreed_pro_version < 100)
  932. peer = DRBD_MAX_BIO_SIZE_P95; /* drbd 8.3.8 onwards, before 8.4.0 */
  933. else
  934. peer = DRBD_MAX_BIO_SIZE;
  935. }
  936. new = min_t(int, local, peer);
  937. if (mdev->state.role == R_PRIMARY && new < now)
  938. dev_err(DEV, "ASSERT FAILED new < now; (%d < %d)\n", new, now);
  939. if (new != now)
  940. dev_info(DEV, "max BIO size = %u\n", new);
  941. drbd_setup_queue_param(mdev, new);
  942. }
  943. /* Starts the worker thread */
  944. static void conn_reconfig_start(struct drbd_tconn *tconn)
  945. {
  946. drbd_thread_start(&tconn->worker);
  947. conn_flush_workqueue(tconn);
  948. }
  949. /* if still unconfigured, stops worker again. */
  950. static void conn_reconfig_done(struct drbd_tconn *tconn)
  951. {
  952. bool stop_threads;
  953. spin_lock_irq(&tconn->req_lock);
  954. stop_threads = conn_all_vols_unconf(tconn) &&
  955. tconn->cstate == C_STANDALONE;
  956. spin_unlock_irq(&tconn->req_lock);
  957. if (stop_threads) {
  958. /* asender is implicitly stopped by receiver
  959. * in conn_disconnect() */
  960. drbd_thread_stop(&tconn->receiver);
  961. drbd_thread_stop(&tconn->worker);
  962. }
  963. }
  964. /* Make sure IO is suspended before calling this function(). */
  965. static void drbd_suspend_al(struct drbd_conf *mdev)
  966. {
  967. int s = 0;
  968. if (!lc_try_lock(mdev->act_log)) {
  969. dev_warn(DEV, "Failed to lock al in drbd_suspend_al()\n");
  970. return;
  971. }
  972. drbd_al_shrink(mdev);
  973. spin_lock_irq(&mdev->tconn->req_lock);
  974. if (mdev->state.conn < C_CONNECTED)
  975. s = !test_and_set_bit(AL_SUSPENDED, &mdev->flags);
  976. spin_unlock_irq(&mdev->tconn->req_lock);
  977. lc_unlock(mdev->act_log);
  978. if (s)
  979. dev_info(DEV, "Suspended AL updates\n");
  980. }
  981. static bool should_set_defaults(struct genl_info *info)
  982. {
  983. unsigned flags = ((struct drbd_genlmsghdr*)info->userhdr)->flags;
  984. return 0 != (flags & DRBD_GENL_F_SET_DEFAULTS);
  985. }
  986. static void enforce_disk_conf_limits(struct disk_conf *dc)
  987. {
  988. if (dc->al_extents < DRBD_AL_EXTENTS_MIN)
  989. dc->al_extents = DRBD_AL_EXTENTS_MIN;
  990. if (dc->al_extents > DRBD_AL_EXTENTS_MAX)
  991. dc->al_extents = DRBD_AL_EXTENTS_MAX;
  992. if (dc->c_plan_ahead > DRBD_C_PLAN_AHEAD_MAX)
  993. dc->c_plan_ahead = DRBD_C_PLAN_AHEAD_MAX;
  994. }
  995. int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info)
  996. {
  997. enum drbd_ret_code retcode;
  998. struct drbd_conf *mdev;
  999. struct disk_conf *new_disk_conf, *old_disk_conf;
  1000. struct fifo_buffer *old_plan = NULL, *new_plan = NULL;
  1001. int err, fifo_size;
  1002. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  1003. if (!adm_ctx.reply_skb)
  1004. return retcode;
  1005. if (retcode != NO_ERROR)
  1006. goto out;
  1007. mdev = adm_ctx.mdev;
  1008. /* we also need a disk
  1009. * to change the options on */
  1010. if (!get_ldev(mdev)) {
  1011. retcode = ERR_NO_DISK;
  1012. goto out;
  1013. }
  1014. new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
  1015. if (!new_disk_conf) {
  1016. retcode = ERR_NOMEM;
  1017. goto fail;
  1018. }
  1019. mutex_lock(&mdev->tconn->conf_update);
  1020. old_disk_conf = mdev->ldev->disk_conf;
  1021. *new_disk_conf = *old_disk_conf;
  1022. if (should_set_defaults(info))
  1023. set_disk_conf_defaults(new_disk_conf);
  1024. err = disk_conf_from_attrs_for_change(new_disk_conf, info);
  1025. if (err && err != -ENOMSG) {
  1026. retcode = ERR_MANDATORY_TAG;
  1027. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1028. }
  1029. if (!expect(new_disk_conf->resync_rate >= 1))
  1030. new_disk_conf->resync_rate = 1;
  1031. enforce_disk_conf_limits(new_disk_conf);
  1032. fifo_size = (new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ;
  1033. if (fifo_size != mdev->rs_plan_s->size) {
  1034. new_plan = fifo_alloc(fifo_size);
  1035. if (!new_plan) {
  1036. dev_err(DEV, "kmalloc of fifo_buffer failed");
  1037. retcode = ERR_NOMEM;
  1038. goto fail_unlock;
  1039. }
  1040. }
  1041. wait_event(mdev->al_wait, lc_try_lock(mdev->act_log));
  1042. drbd_al_shrink(mdev);
  1043. err = drbd_check_al_size(mdev, new_disk_conf);
  1044. lc_unlock(mdev->act_log);
  1045. wake_up(&mdev->al_wait);
  1046. if (err) {
  1047. retcode = ERR_NOMEM;
  1048. goto fail_unlock;
  1049. }
  1050. write_lock_irq(&global_state_lock);
  1051. retcode = drbd_resync_after_valid(mdev, new_disk_conf->resync_after);
  1052. if (retcode == NO_ERROR) {
  1053. rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf);
  1054. drbd_resync_after_changed(mdev);
  1055. }
  1056. write_unlock_irq(&global_state_lock);
  1057. if (retcode != NO_ERROR)
  1058. goto fail_unlock;
  1059. if (new_plan) {
  1060. old_plan = mdev->rs_plan_s;
  1061. rcu_assign_pointer(mdev->rs_plan_s, new_plan);
  1062. }
  1063. mutex_unlock(&mdev->tconn->conf_update);
  1064. if (new_disk_conf->al_updates)
  1065. mdev->ldev->md.flags &= MDF_AL_DISABLED;
  1066. else
  1067. mdev->ldev->md.flags |= MDF_AL_DISABLED;
  1068. drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush);
  1069. drbd_md_sync(mdev);
  1070. if (mdev->state.conn >= C_CONNECTED)
  1071. drbd_send_sync_param(mdev);
  1072. synchronize_rcu();
  1073. kfree(old_disk_conf);
  1074. kfree(old_plan);
  1075. mod_timer(&mdev->request_timer, jiffies + HZ);
  1076. goto success;
  1077. fail_unlock:
  1078. mutex_unlock(&mdev->tconn->conf_update);
  1079. fail:
  1080. kfree(new_disk_conf);
  1081. kfree(new_plan);
  1082. success:
  1083. put_ldev(mdev);
  1084. out:
  1085. drbd_adm_finish(info, retcode);
  1086. return 0;
  1087. }
  1088. int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info)
  1089. {
  1090. struct drbd_conf *mdev;
  1091. int err;
  1092. enum drbd_ret_code retcode;
  1093. enum determine_dev_size dd;
  1094. sector_t max_possible_sectors;
  1095. sector_t min_md_device_sectors;
  1096. struct drbd_backing_dev *nbc = NULL; /* new_backing_conf */
  1097. struct disk_conf *new_disk_conf = NULL;
  1098. struct block_device *bdev;
  1099. struct lru_cache *resync_lru = NULL;
  1100. struct fifo_buffer *new_plan = NULL;
  1101. union drbd_state ns, os;
  1102. enum drbd_state_rv rv;
  1103. struct net_conf *nc;
  1104. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  1105. if (!adm_ctx.reply_skb)
  1106. return retcode;
  1107. if (retcode != NO_ERROR)
  1108. goto finish;
  1109. mdev = adm_ctx.mdev;
  1110. conn_reconfig_start(mdev->tconn);
  1111. /* if you want to reconfigure, please tear down first */
  1112. if (mdev->state.disk > D_DISKLESS) {
  1113. retcode = ERR_DISK_CONFIGURED;
  1114. goto fail;
  1115. }
  1116. /* It may just now have detached because of IO error. Make sure
  1117. * drbd_ldev_destroy is done already, we may end up here very fast,
  1118. * e.g. if someone calls attach from the on-io-error handler,
  1119. * to realize a "hot spare" feature (not that I'd recommend that) */
  1120. wait_event(mdev->misc_wait, !atomic_read(&mdev->local_cnt));
  1121. /* make sure there is no leftover from previous force-detach attempts */
  1122. clear_bit(FORCE_DETACH, &mdev->flags);
  1123. /* allocation not in the IO path, drbdsetup context */
  1124. nbc = kzalloc(sizeof(struct drbd_backing_dev), GFP_KERNEL);
  1125. if (!nbc) {
  1126. retcode = ERR_NOMEM;
  1127. goto fail;
  1128. }
  1129. new_disk_conf = kzalloc(sizeof(struct disk_conf), GFP_KERNEL);
  1130. if (!new_disk_conf) {
  1131. retcode = ERR_NOMEM;
  1132. goto fail;
  1133. }
  1134. nbc->disk_conf = new_disk_conf;
  1135. set_disk_conf_defaults(new_disk_conf);
  1136. err = disk_conf_from_attrs(new_disk_conf, info);
  1137. if (err) {
  1138. retcode = ERR_MANDATORY_TAG;
  1139. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1140. goto fail;
  1141. }
  1142. enforce_disk_conf_limits(new_disk_conf);
  1143. new_plan = fifo_alloc((new_disk_conf->c_plan_ahead * 10 * SLEEP_TIME) / HZ);
  1144. if (!new_plan) {
  1145. retcode = ERR_NOMEM;
  1146. goto fail;
  1147. }
  1148. if (new_disk_conf->meta_dev_idx < DRBD_MD_INDEX_FLEX_INT) {
  1149. retcode = ERR_MD_IDX_INVALID;
  1150. goto fail;
  1151. }
  1152. rcu_read_lock();
  1153. nc = rcu_dereference(mdev->tconn->net_conf);
  1154. if (nc) {
  1155. if (new_disk_conf->fencing == FP_STONITH && nc->wire_protocol == DRBD_PROT_A) {
  1156. rcu_read_unlock();
  1157. retcode = ERR_STONITH_AND_PROT_A;
  1158. goto fail;
  1159. }
  1160. }
  1161. rcu_read_unlock();
  1162. bdev = blkdev_get_by_path(new_disk_conf->backing_dev,
  1163. FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev);
  1164. if (IS_ERR(bdev)) {
  1165. dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->backing_dev,
  1166. PTR_ERR(bdev));
  1167. retcode = ERR_OPEN_DISK;
  1168. goto fail;
  1169. }
  1170. nbc->backing_bdev = bdev;
  1171. /*
  1172. * meta_dev_idx >= 0: external fixed size, possibly multiple
  1173. * drbd sharing one meta device. TODO in that case, paranoia
  1174. * check that [md_bdev, meta_dev_idx] is not yet used by some
  1175. * other drbd minor! (if you use drbd.conf + drbdadm, that
  1176. * should check it for you already; but if you don't, or
  1177. * someone fooled it, we need to double check here)
  1178. */
  1179. bdev = blkdev_get_by_path(new_disk_conf->meta_dev,
  1180. FMODE_READ | FMODE_WRITE | FMODE_EXCL,
  1181. (new_disk_conf->meta_dev_idx < 0) ?
  1182. (void *)mdev : (void *)drbd_m_holder);
  1183. if (IS_ERR(bdev)) {
  1184. dev_err(DEV, "open(\"%s\") failed with %ld\n", new_disk_conf->meta_dev,
  1185. PTR_ERR(bdev));
  1186. retcode = ERR_OPEN_MD_DISK;
  1187. goto fail;
  1188. }
  1189. nbc->md_bdev = bdev;
  1190. if ((nbc->backing_bdev == nbc->md_bdev) !=
  1191. (new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_INTERNAL ||
  1192. new_disk_conf->meta_dev_idx == DRBD_MD_INDEX_FLEX_INT)) {
  1193. retcode = ERR_MD_IDX_INVALID;
  1194. goto fail;
  1195. }
  1196. resync_lru = lc_create("resync", drbd_bm_ext_cache,
  1197. 1, 61, sizeof(struct bm_extent),
  1198. offsetof(struct bm_extent, lce));
  1199. if (!resync_lru) {
  1200. retcode = ERR_NOMEM;
  1201. goto fail;
  1202. }
  1203. /* RT - for drbd_get_max_capacity() DRBD_MD_INDEX_FLEX_INT */
  1204. drbd_md_set_sector_offsets(mdev, nbc);
  1205. if (drbd_get_max_capacity(nbc) < new_disk_conf->disk_size) {
  1206. dev_err(DEV, "max capacity %llu smaller than disk size %llu\n",
  1207. (unsigned long long) drbd_get_max_capacity(nbc),
  1208. (unsigned long long) new_disk_conf->disk_size);
  1209. retcode = ERR_DISK_TOO_SMALL;
  1210. goto fail;
  1211. }
  1212. if (new_disk_conf->meta_dev_idx < 0) {
  1213. max_possible_sectors = DRBD_MAX_SECTORS_FLEX;
  1214. /* at least one MB, otherwise it does not make sense */
  1215. min_md_device_sectors = (2<<10);
  1216. } else {
  1217. max_possible_sectors = DRBD_MAX_SECTORS;
  1218. min_md_device_sectors = MD_RESERVED_SECT * (new_disk_conf->meta_dev_idx + 1);
  1219. }
  1220. if (drbd_get_capacity(nbc->md_bdev) < min_md_device_sectors) {
  1221. retcode = ERR_MD_DISK_TOO_SMALL;
  1222. dev_warn(DEV, "refusing attach: md-device too small, "
  1223. "at least %llu sectors needed for this meta-disk type\n",
  1224. (unsigned long long) min_md_device_sectors);
  1225. goto fail;
  1226. }
  1227. /* Make sure the new disk is big enough
  1228. * (we may currently be R_PRIMARY with no local disk...) */
  1229. if (drbd_get_max_capacity(nbc) <
  1230. drbd_get_capacity(mdev->this_bdev)) {
  1231. retcode = ERR_DISK_TOO_SMALL;
  1232. goto fail;
  1233. }
  1234. nbc->known_size = drbd_get_capacity(nbc->backing_bdev);
  1235. if (nbc->known_size > max_possible_sectors) {
  1236. dev_warn(DEV, "==> truncating very big lower level device "
  1237. "to currently maximum possible %llu sectors <==\n",
  1238. (unsigned long long) max_possible_sectors);
  1239. if (new_disk_conf->meta_dev_idx >= 0)
  1240. dev_warn(DEV, "==>> using internal or flexible "
  1241. "meta data may help <<==\n");
  1242. }
  1243. drbd_suspend_io(mdev);
  1244. /* also wait for the last barrier ack. */
  1245. /* FIXME see also https://daiquiri.linbit/cgi-bin/bugzilla/show_bug.cgi?id=171
  1246. * We need a way to either ignore barrier acks for barriers sent before a device
  1247. * was attached, or a way to wait for all pending barrier acks to come in.
  1248. * As barriers are counted per resource,
  1249. * we'd need to suspend io on all devices of a resource.
  1250. */
  1251. wait_event(mdev->misc_wait, !atomic_read(&mdev->ap_pending_cnt) || drbd_suspended(mdev));
  1252. /* and for any other previously queued work */
  1253. drbd_flush_workqueue(mdev);
  1254. rv = _drbd_request_state(mdev, NS(disk, D_ATTACHING), CS_VERBOSE);
  1255. retcode = rv; /* FIXME: Type mismatch. */
  1256. drbd_resume_io(mdev);
  1257. if (rv < SS_SUCCESS)
  1258. goto fail;
  1259. if (!get_ldev_if_state(mdev, D_ATTACHING))
  1260. goto force_diskless;
  1261. drbd_md_set_sector_offsets(mdev, nbc);
  1262. if (!mdev->bitmap) {
  1263. if (drbd_bm_init(mdev)) {
  1264. retcode = ERR_NOMEM;
  1265. goto force_diskless_dec;
  1266. }
  1267. }
  1268. retcode = drbd_md_read(mdev, nbc);
  1269. if (retcode != NO_ERROR)
  1270. goto force_diskless_dec;
  1271. if (mdev->state.conn < C_CONNECTED &&
  1272. mdev->state.role == R_PRIMARY &&
  1273. (mdev->ed_uuid & ~((u64)1)) != (nbc->md.uuid[UI_CURRENT] & ~((u64)1))) {
  1274. dev_err(DEV, "Can only attach to data with current UUID=%016llX\n",
  1275. (unsigned long long)mdev->ed_uuid);
  1276. retcode = ERR_DATA_NOT_CURRENT;
  1277. goto force_diskless_dec;
  1278. }
  1279. /* Since we are diskless, fix the activity log first... */
  1280. if (drbd_check_al_size(mdev, new_disk_conf)) {
  1281. retcode = ERR_NOMEM;
  1282. goto force_diskless_dec;
  1283. }
  1284. /* Prevent shrinking of consistent devices ! */
  1285. if (drbd_md_test_flag(nbc, MDF_CONSISTENT) &&
  1286. drbd_new_dev_size(mdev, nbc, nbc->disk_conf->disk_size, 0) < nbc->md.la_size_sect) {
  1287. dev_warn(DEV, "refusing to truncate a consistent device\n");
  1288. retcode = ERR_DISK_TOO_SMALL;
  1289. goto force_diskless_dec;
  1290. }
  1291. /* Reset the "barriers don't work" bits here, then force meta data to
  1292. * be written, to ensure we determine if barriers are supported. */
  1293. if (new_disk_conf->md_flushes)
  1294. clear_bit(MD_NO_FUA, &mdev->flags);
  1295. else
  1296. set_bit(MD_NO_FUA, &mdev->flags);
  1297. /* Point of no return reached.
  1298. * Devices and memory are no longer released by error cleanup below.
  1299. * now mdev takes over responsibility, and the state engine should
  1300. * clean it up somewhere. */
  1301. D_ASSERT(mdev->ldev == NULL);
  1302. mdev->ldev = nbc;
  1303. mdev->resync = resync_lru;
  1304. mdev->rs_plan_s = new_plan;
  1305. nbc = NULL;
  1306. resync_lru = NULL;
  1307. new_disk_conf = NULL;
  1308. new_plan = NULL;
  1309. drbd_bump_write_ordering(mdev->tconn, WO_bdev_flush);
  1310. if (drbd_md_test_flag(mdev->ldev, MDF_CRASHED_PRIMARY))
  1311. set_bit(CRASHED_PRIMARY, &mdev->flags);
  1312. else
  1313. clear_bit(CRASHED_PRIMARY, &mdev->flags);
  1314. if (drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) &&
  1315. !(mdev->state.role == R_PRIMARY && mdev->tconn->susp_nod))
  1316. set_bit(CRASHED_PRIMARY, &mdev->flags);
  1317. mdev->send_cnt = 0;
  1318. mdev->recv_cnt = 0;
  1319. mdev->read_cnt = 0;
  1320. mdev->writ_cnt = 0;
  1321. drbd_reconsider_max_bio_size(mdev);
  1322. /* If I am currently not R_PRIMARY,
  1323. * but meta data primary indicator is set,
  1324. * I just now recover from a hard crash,
  1325. * and have been R_PRIMARY before that crash.
  1326. *
  1327. * Now, if I had no connection before that crash
  1328. * (have been degraded R_PRIMARY), chances are that
  1329. * I won't find my peer now either.
  1330. *
  1331. * In that case, and _only_ in that case,
  1332. * we use the degr-wfc-timeout instead of the default,
  1333. * so we can automatically recover from a crash of a
  1334. * degraded but active "cluster" after a certain timeout.
  1335. */
  1336. clear_bit(USE_DEGR_WFC_T, &mdev->flags);
  1337. if (mdev->state.role != R_PRIMARY &&
  1338. drbd_md_test_flag(mdev->ldev, MDF_PRIMARY_IND) &&
  1339. !drbd_md_test_flag(mdev->ldev, MDF_CONNECTED_IND))
  1340. set_bit(USE_DEGR_WFC_T, &mdev->flags);
  1341. dd = drbd_determine_dev_size(mdev, 0);
  1342. if (dd == dev_size_error) {
  1343. retcode = ERR_NOMEM_BITMAP;
  1344. goto force_diskless_dec;
  1345. } else if (dd == grew)
  1346. set_bit(RESYNC_AFTER_NEG, &mdev->flags);
  1347. if (drbd_md_test_flag(mdev->ldev, MDF_FULL_SYNC) ||
  1348. (test_bit(CRASHED_PRIMARY, &mdev->flags) &&
  1349. drbd_md_test_flag(mdev->ldev, MDF_AL_DISABLED))) {
  1350. dev_info(DEV, "Assuming that all blocks are out of sync "
  1351. "(aka FullSync)\n");
  1352. if (drbd_bitmap_io(mdev, &drbd_bmio_set_n_write,
  1353. "set_n_write from attaching", BM_LOCKED_MASK)) {
  1354. retcode = ERR_IO_MD_DISK;
  1355. goto force_diskless_dec;
  1356. }
  1357. } else {
  1358. if (drbd_bitmap_io(mdev, &drbd_bm_read,
  1359. "read from attaching", BM_LOCKED_MASK)) {
  1360. retcode = ERR_IO_MD_DISK;
  1361. goto force_diskless_dec;
  1362. }
  1363. }
  1364. if (_drbd_bm_total_weight(mdev) == drbd_bm_bits(mdev))
  1365. drbd_suspend_al(mdev); /* IO is still suspended here... */
  1366. spin_lock_irq(&mdev->tconn->req_lock);
  1367. os = drbd_read_state(mdev);
  1368. ns = os;
  1369. /* If MDF_CONSISTENT is not set go into inconsistent state,
  1370. otherwise investigate MDF_WasUpToDate...
  1371. If MDF_WAS_UP_TO_DATE is not set go into D_OUTDATED disk state,
  1372. otherwise into D_CONSISTENT state.
  1373. */
  1374. if (drbd_md_test_flag(mdev->ldev, MDF_CONSISTENT)) {
  1375. if (drbd_md_test_flag(mdev->ldev, MDF_WAS_UP_TO_DATE))
  1376. ns.disk = D_CONSISTENT;
  1377. else
  1378. ns.disk = D_OUTDATED;
  1379. } else {
  1380. ns.disk = D_INCONSISTENT;
  1381. }
  1382. if (drbd_md_test_flag(mdev->ldev, MDF_PEER_OUT_DATED))
  1383. ns.pdsk = D_OUTDATED;
  1384. rcu_read_lock();
  1385. if (ns.disk == D_CONSISTENT &&
  1386. (ns.pdsk == D_OUTDATED || rcu_dereference(mdev->ldev->disk_conf)->fencing == FP_DONT_CARE))
  1387. ns.disk = D_UP_TO_DATE;
  1388. /* All tests on MDF_PRIMARY_IND, MDF_CONNECTED_IND,
  1389. MDF_CONSISTENT and MDF_WAS_UP_TO_DATE must happen before
  1390. this point, because drbd_request_state() modifies these
  1391. flags. */
  1392. if (rcu_dereference(mdev->ldev->disk_conf)->al_updates)
  1393. mdev->ldev->md.flags &= MDF_AL_DISABLED;
  1394. else
  1395. mdev->ldev->md.flags |= MDF_AL_DISABLED;
  1396. rcu_read_unlock();
  1397. /* In case we are C_CONNECTED postpone any decision on the new disk
  1398. state after the negotiation phase. */
  1399. if (mdev->state.conn == C_CONNECTED) {
  1400. mdev->new_state_tmp.i = ns.i;
  1401. ns.i = os.i;
  1402. ns.disk = D_NEGOTIATING;
  1403. /* We expect to receive up-to-date UUIDs soon.
  1404. To avoid a race in receive_state, free p_uuid while
  1405. holding req_lock. I.e. atomic with the state change */
  1406. kfree(mdev->p_uuid);
  1407. mdev->p_uuid = NULL;
  1408. }
  1409. rv = _drbd_set_state(mdev, ns, CS_VERBOSE, NULL);
  1410. spin_unlock_irq(&mdev->tconn->req_lock);
  1411. if (rv < SS_SUCCESS)
  1412. goto force_diskless_dec;
  1413. mod_timer(&mdev->request_timer, jiffies + HZ);
  1414. if (mdev->state.role == R_PRIMARY)
  1415. mdev->ldev->md.uuid[UI_CURRENT] |= (u64)1;
  1416. else
  1417. mdev->ldev->md.uuid[UI_CURRENT] &= ~(u64)1;
  1418. drbd_md_mark_dirty(mdev);
  1419. drbd_md_sync(mdev);
  1420. kobject_uevent(&disk_to_dev(mdev->vdisk)->kobj, KOBJ_CHANGE);
  1421. put_ldev(mdev);
  1422. conn_reconfig_done(mdev->tconn);
  1423. drbd_adm_finish(info, retcode);
  1424. return 0;
  1425. force_diskless_dec:
  1426. put_ldev(mdev);
  1427. force_diskless:
  1428. drbd_force_state(mdev, NS(disk, D_DISKLESS));
  1429. drbd_md_sync(mdev);
  1430. fail:
  1431. conn_reconfig_done(mdev->tconn);
  1432. if (nbc) {
  1433. if (nbc->backing_bdev)
  1434. blkdev_put(nbc->backing_bdev,
  1435. FMODE_READ | FMODE_WRITE | FMODE_EXCL);
  1436. if (nbc->md_bdev)
  1437. blkdev_put(nbc->md_bdev,
  1438. FMODE_READ | FMODE_WRITE | FMODE_EXCL);
  1439. kfree(nbc);
  1440. }
  1441. kfree(new_disk_conf);
  1442. lc_destroy(resync_lru);
  1443. kfree(new_plan);
  1444. finish:
  1445. drbd_adm_finish(info, retcode);
  1446. return 0;
  1447. }
  1448. static int adm_detach(struct drbd_conf *mdev, int force)
  1449. {
  1450. enum drbd_state_rv retcode;
  1451. int ret;
  1452. if (force) {
  1453. set_bit(FORCE_DETACH, &mdev->flags);
  1454. drbd_force_state(mdev, NS(disk, D_FAILED));
  1455. retcode = SS_SUCCESS;
  1456. goto out;
  1457. }
  1458. drbd_suspend_io(mdev); /* so no-one is stuck in drbd_al_begin_io */
  1459. drbd_md_get_buffer(mdev); /* make sure there is no in-flight meta-data IO */
  1460. retcode = drbd_request_state(mdev, NS(disk, D_FAILED));
  1461. drbd_md_put_buffer(mdev);
  1462. /* D_FAILED will transition to DISKLESS. */
  1463. ret = wait_event_interruptible(mdev->misc_wait,
  1464. mdev->state.disk != D_FAILED);
  1465. drbd_resume_io(mdev);
  1466. if ((int)retcode == (int)SS_IS_DISKLESS)
  1467. retcode = SS_NOTHING_TO_DO;
  1468. if (ret)
  1469. retcode = ERR_INTR;
  1470. out:
  1471. return retcode;
  1472. }
  1473. /* Detaching the disk is a process in multiple stages. First we need to lock
  1474. * out application IO, in-flight IO, IO stuck in drbd_al_begin_io.
  1475. * Then we transition to D_DISKLESS, and wait for put_ldev() to return all
  1476. * internal references as well.
  1477. * Only then we have finally detached. */
  1478. int drbd_adm_detach(struct sk_buff *skb, struct genl_info *info)
  1479. {
  1480. enum drbd_ret_code retcode;
  1481. struct detach_parms parms = { };
  1482. int err;
  1483. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  1484. if (!adm_ctx.reply_skb)
  1485. return retcode;
  1486. if (retcode != NO_ERROR)
  1487. goto out;
  1488. if (info->attrs[DRBD_NLA_DETACH_PARMS]) {
  1489. err = detach_parms_from_attrs(&parms, info);
  1490. if (err) {
  1491. retcode = ERR_MANDATORY_TAG;
  1492. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1493. goto out;
  1494. }
  1495. }
  1496. retcode = adm_detach(adm_ctx.mdev, parms.force_detach);
  1497. out:
  1498. drbd_adm_finish(info, retcode);
  1499. return 0;
  1500. }
  1501. static bool conn_resync_running(struct drbd_tconn *tconn)
  1502. {
  1503. struct drbd_conf *mdev;
  1504. bool rv = false;
  1505. int vnr;
  1506. rcu_read_lock();
  1507. idr_for_each_entry(&tconn->volumes, mdev, vnr) {
  1508. if (mdev->state.conn == C_SYNC_SOURCE ||
  1509. mdev->state.conn == C_SYNC_TARGET ||
  1510. mdev->state.conn == C_PAUSED_SYNC_S ||
  1511. mdev->state.conn == C_PAUSED_SYNC_T) {
  1512. rv = true;
  1513. break;
  1514. }
  1515. }
  1516. rcu_read_unlock();
  1517. return rv;
  1518. }
  1519. static bool conn_ov_running(struct drbd_tconn *tconn)
  1520. {
  1521. struct drbd_conf *mdev;
  1522. bool rv = false;
  1523. int vnr;
  1524. rcu_read_lock();
  1525. idr_for_each_entry(&tconn->volumes, mdev, vnr) {
  1526. if (mdev->state.conn == C_VERIFY_S ||
  1527. mdev->state.conn == C_VERIFY_T) {
  1528. rv = true;
  1529. break;
  1530. }
  1531. }
  1532. rcu_read_unlock();
  1533. return rv;
  1534. }
  1535. static enum drbd_ret_code
  1536. _check_net_options(struct drbd_tconn *tconn, struct net_conf *old_conf, struct net_conf *new_conf)
  1537. {
  1538. struct drbd_conf *mdev;
  1539. int i;
  1540. if (old_conf && tconn->cstate == C_WF_REPORT_PARAMS && tconn->agreed_pro_version < 100) {
  1541. if (new_conf->wire_protocol != old_conf->wire_protocol)
  1542. return ERR_NEED_APV_100;
  1543. if (new_conf->two_primaries != old_conf->two_primaries)
  1544. return ERR_NEED_APV_100;
  1545. if (!new_conf->integrity_alg != !old_conf->integrity_alg)
  1546. return ERR_NEED_APV_100;
  1547. if (strcmp(new_conf->integrity_alg, old_conf->integrity_alg))
  1548. return ERR_NEED_APV_100;
  1549. }
  1550. if (!new_conf->two_primaries &&
  1551. conn_highest_role(tconn) == R_PRIMARY &&
  1552. conn_highest_peer(tconn) == R_PRIMARY)
  1553. return ERR_NEED_ALLOW_TWO_PRI;
  1554. if (new_conf->two_primaries &&
  1555. (new_conf->wire_protocol != DRBD_PROT_C))
  1556. return ERR_NOT_PROTO_C;
  1557. idr_for_each_entry(&tconn->volumes, mdev, i) {
  1558. if (get_ldev(mdev)) {
  1559. enum drbd_fencing_p fp = rcu_dereference(mdev->ldev->disk_conf)->fencing;
  1560. put_ldev(mdev);
  1561. if (new_conf->wire_protocol == DRBD_PROT_A && fp == FP_STONITH)
  1562. return ERR_STONITH_AND_PROT_A;
  1563. }
  1564. if (mdev->state.role == R_PRIMARY && new_conf->discard_my_data)
  1565. return ERR_DISCARD;
  1566. }
  1567. if (new_conf->on_congestion != OC_BLOCK && new_conf->wire_protocol != DRBD_PROT_A)
  1568. return ERR_CONG_NOT_PROTO_A;
  1569. return NO_ERROR;
  1570. }
  1571. static enum drbd_ret_code
  1572. check_net_options(struct drbd_tconn *tconn, struct net_conf *new_conf)
  1573. {
  1574. static enum drbd_ret_code rv;
  1575. struct drbd_conf *mdev;
  1576. int i;
  1577. rcu_read_lock();
  1578. rv = _check_net_options(tconn, rcu_dereference(tconn->net_conf), new_conf);
  1579. rcu_read_unlock();
  1580. /* tconn->volumes protected by genl_lock() here */
  1581. idr_for_each_entry(&tconn->volumes, mdev, i) {
  1582. if (!mdev->bitmap) {
  1583. if(drbd_bm_init(mdev))
  1584. return ERR_NOMEM;
  1585. }
  1586. }
  1587. return rv;
  1588. }
  1589. struct crypto {
  1590. struct crypto_hash *verify_tfm;
  1591. struct crypto_hash *csums_tfm;
  1592. struct crypto_hash *cram_hmac_tfm;
  1593. struct crypto_hash *integrity_tfm;
  1594. };
  1595. static int
  1596. alloc_hash(struct crypto_hash **tfm, char *tfm_name, int err_alg)
  1597. {
  1598. if (!tfm_name[0])
  1599. return NO_ERROR;
  1600. *tfm = crypto_alloc_hash(tfm_name, 0, CRYPTO_ALG_ASYNC);
  1601. if (IS_ERR(*tfm)) {
  1602. *tfm = NULL;
  1603. return err_alg;
  1604. }
  1605. return NO_ERROR;
  1606. }
  1607. static enum drbd_ret_code
  1608. alloc_crypto(struct crypto *crypto, struct net_conf *new_conf)
  1609. {
  1610. char hmac_name[CRYPTO_MAX_ALG_NAME];
  1611. enum drbd_ret_code rv;
  1612. rv = alloc_hash(&crypto->csums_tfm, new_conf->csums_alg,
  1613. ERR_CSUMS_ALG);
  1614. if (rv != NO_ERROR)
  1615. return rv;
  1616. rv = alloc_hash(&crypto->verify_tfm, new_conf->verify_alg,
  1617. ERR_VERIFY_ALG);
  1618. if (rv != NO_ERROR)
  1619. return rv;
  1620. rv = alloc_hash(&crypto->integrity_tfm, new_conf->integrity_alg,
  1621. ERR_INTEGRITY_ALG);
  1622. if (rv != NO_ERROR)
  1623. return rv;
  1624. if (new_conf->cram_hmac_alg[0] != 0) {
  1625. snprintf(hmac_name, CRYPTO_MAX_ALG_NAME, "hmac(%s)",
  1626. new_conf->cram_hmac_alg);
  1627. rv = alloc_hash(&crypto->cram_hmac_tfm, hmac_name,
  1628. ERR_AUTH_ALG);
  1629. }
  1630. return rv;
  1631. }
  1632. static void free_crypto(struct crypto *crypto)
  1633. {
  1634. crypto_free_hash(crypto->cram_hmac_tfm);
  1635. crypto_free_hash(crypto->integrity_tfm);
  1636. crypto_free_hash(crypto->csums_tfm);
  1637. crypto_free_hash(crypto->verify_tfm);
  1638. }
  1639. int drbd_adm_net_opts(struct sk_buff *skb, struct genl_info *info)
  1640. {
  1641. enum drbd_ret_code retcode;
  1642. struct drbd_tconn *tconn;
  1643. struct net_conf *old_conf, *new_conf = NULL;
  1644. int err;
  1645. int ovr; /* online verify running */
  1646. int rsr; /* re-sync running */
  1647. struct crypto crypto = { };
  1648. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION);
  1649. if (!adm_ctx.reply_skb)
  1650. return retcode;
  1651. if (retcode != NO_ERROR)
  1652. goto out;
  1653. tconn = adm_ctx.tconn;
  1654. new_conf = kzalloc(sizeof(struct net_conf), GFP_KERNEL);
  1655. if (!new_conf) {
  1656. retcode = ERR_NOMEM;
  1657. goto out;
  1658. }
  1659. conn_reconfig_start(tconn);
  1660. mutex_lock(&tconn->data.mutex);
  1661. mutex_lock(&tconn->conf_update);
  1662. old_conf = tconn->net_conf;
  1663. if (!old_conf) {
  1664. drbd_msg_put_info("net conf missing, try connect");
  1665. retcode = ERR_INVALID_REQUEST;
  1666. goto fail;
  1667. }
  1668. *new_conf = *old_conf;
  1669. if (should_set_defaults(info))
  1670. set_net_conf_defaults(new_conf);
  1671. err = net_conf_from_attrs_for_change(new_conf, info);
  1672. if (err && err != -ENOMSG) {
  1673. retcode = ERR_MANDATORY_TAG;
  1674. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1675. goto fail;
  1676. }
  1677. retcode = check_net_options(tconn, new_conf);
  1678. if (retcode != NO_ERROR)
  1679. goto fail;
  1680. /* re-sync running */
  1681. rsr = conn_resync_running(tconn);
  1682. if (rsr && strcmp(new_conf->csums_alg, old_conf->csums_alg)) {
  1683. retcode = ERR_CSUMS_RESYNC_RUNNING;
  1684. goto fail;
  1685. }
  1686. /* online verify running */
  1687. ovr = conn_ov_running(tconn);
  1688. if (ovr && strcmp(new_conf->verify_alg, old_conf->verify_alg)) {
  1689. retcode = ERR_VERIFY_RUNNING;
  1690. goto fail;
  1691. }
  1692. retcode = alloc_crypto(&crypto, new_conf);
  1693. if (retcode != NO_ERROR)
  1694. goto fail;
  1695. rcu_assign_pointer(tconn->net_conf, new_conf);
  1696. if (!rsr) {
  1697. crypto_free_hash(tconn->csums_tfm);
  1698. tconn->csums_tfm = crypto.csums_tfm;
  1699. crypto.csums_tfm = NULL;
  1700. }
  1701. if (!ovr) {
  1702. crypto_free_hash(tconn->verify_tfm);
  1703. tconn->verify_tfm = crypto.verify_tfm;
  1704. crypto.verify_tfm = NULL;
  1705. }
  1706. crypto_free_hash(tconn->integrity_tfm);
  1707. tconn->integrity_tfm = crypto.integrity_tfm;
  1708. if (tconn->cstate >= C_WF_REPORT_PARAMS && tconn->agreed_pro_version >= 100)
  1709. /* Do this without trying to take tconn->data.mutex again. */
  1710. __drbd_send_protocol(tconn, P_PROTOCOL_UPDATE);
  1711. crypto_free_hash(tconn->cram_hmac_tfm);
  1712. tconn->cram_hmac_tfm = crypto.cram_hmac_tfm;
  1713. mutex_unlock(&tconn->conf_update);
  1714. mutex_unlock(&tconn->data.mutex);
  1715. synchronize_rcu();
  1716. kfree(old_conf);
  1717. if (tconn->cstate >= C_WF_REPORT_PARAMS)
  1718. drbd_send_sync_param(minor_to_mdev(conn_lowest_minor(tconn)));
  1719. goto done;
  1720. fail:
  1721. mutex_unlock(&tconn->conf_update);
  1722. mutex_unlock(&tconn->data.mutex);
  1723. free_crypto(&crypto);
  1724. kfree(new_conf);
  1725. done:
  1726. conn_reconfig_done(tconn);
  1727. out:
  1728. drbd_adm_finish(info, retcode);
  1729. return 0;
  1730. }
  1731. int drbd_adm_connect(struct sk_buff *skb, struct genl_info *info)
  1732. {
  1733. struct drbd_conf *mdev;
  1734. struct net_conf *old_conf, *new_conf = NULL;
  1735. struct crypto crypto = { };
  1736. struct drbd_tconn *tconn;
  1737. enum drbd_ret_code retcode;
  1738. int i;
  1739. int err;
  1740. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
  1741. if (!adm_ctx.reply_skb)
  1742. return retcode;
  1743. if (retcode != NO_ERROR)
  1744. goto out;
  1745. if (!(adm_ctx.my_addr && adm_ctx.peer_addr)) {
  1746. drbd_msg_put_info("connection endpoint(s) missing");
  1747. retcode = ERR_INVALID_REQUEST;
  1748. goto out;
  1749. }
  1750. /* No need for _rcu here. All reconfiguration is
  1751. * strictly serialized on genl_lock(). We are protected against
  1752. * concurrent reconfiguration/addition/deletion */
  1753. list_for_each_entry(tconn, &drbd_tconns, all_tconn) {
  1754. if (nla_len(adm_ctx.my_addr) == tconn->my_addr_len &&
  1755. !memcmp(nla_data(adm_ctx.my_addr), &tconn->my_addr, tconn->my_addr_len)) {
  1756. retcode = ERR_LOCAL_ADDR;
  1757. goto out;
  1758. }
  1759. if (nla_len(adm_ctx.peer_addr) == tconn->peer_addr_len &&
  1760. !memcmp(nla_data(adm_ctx.peer_addr), &tconn->peer_addr, tconn->peer_addr_len)) {
  1761. retcode = ERR_PEER_ADDR;
  1762. goto out;
  1763. }
  1764. }
  1765. tconn = adm_ctx.tconn;
  1766. conn_reconfig_start(tconn);
  1767. if (tconn->cstate > C_STANDALONE) {
  1768. retcode = ERR_NET_CONFIGURED;
  1769. goto fail;
  1770. }
  1771. /* allocation not in the IO path, drbdsetup / netlink process context */
  1772. new_conf = kzalloc(sizeof(*new_conf), GFP_KERNEL);
  1773. if (!new_conf) {
  1774. retcode = ERR_NOMEM;
  1775. goto fail;
  1776. }
  1777. set_net_conf_defaults(new_conf);
  1778. err = net_conf_from_attrs(new_conf, info);
  1779. if (err && err != -ENOMSG) {
  1780. retcode = ERR_MANDATORY_TAG;
  1781. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1782. goto fail;
  1783. }
  1784. retcode = check_net_options(tconn, new_conf);
  1785. if (retcode != NO_ERROR)
  1786. goto fail;
  1787. retcode = alloc_crypto(&crypto, new_conf);
  1788. if (retcode != NO_ERROR)
  1789. goto fail;
  1790. ((char *)new_conf->shared_secret)[SHARED_SECRET_MAX-1] = 0;
  1791. conn_flush_workqueue(tconn);
  1792. mutex_lock(&tconn->conf_update);
  1793. old_conf = tconn->net_conf;
  1794. if (old_conf) {
  1795. retcode = ERR_NET_CONFIGURED;
  1796. mutex_unlock(&tconn->conf_update);
  1797. goto fail;
  1798. }
  1799. rcu_assign_pointer(tconn->net_conf, new_conf);
  1800. conn_free_crypto(tconn);
  1801. tconn->cram_hmac_tfm = crypto.cram_hmac_tfm;
  1802. tconn->integrity_tfm = crypto.integrity_tfm;
  1803. tconn->csums_tfm = crypto.csums_tfm;
  1804. tconn->verify_tfm = crypto.verify_tfm;
  1805. tconn->my_addr_len = nla_len(adm_ctx.my_addr);
  1806. memcpy(&tconn->my_addr, nla_data(adm_ctx.my_addr), tconn->my_addr_len);
  1807. tconn->peer_addr_len = nla_len(adm_ctx.peer_addr);
  1808. memcpy(&tconn->peer_addr, nla_data(adm_ctx.peer_addr), tconn->peer_addr_len);
  1809. mutex_unlock(&tconn->conf_update);
  1810. rcu_read_lock();
  1811. idr_for_each_entry(&tconn->volumes, mdev, i) {
  1812. mdev->send_cnt = 0;
  1813. mdev->recv_cnt = 0;
  1814. }
  1815. rcu_read_unlock();
  1816. retcode = conn_request_state(tconn, NS(conn, C_UNCONNECTED), CS_VERBOSE);
  1817. conn_reconfig_done(tconn);
  1818. drbd_adm_finish(info, retcode);
  1819. return 0;
  1820. fail:
  1821. free_crypto(&crypto);
  1822. kfree(new_conf);
  1823. conn_reconfig_done(tconn);
  1824. out:
  1825. drbd_adm_finish(info, retcode);
  1826. return 0;
  1827. }
  1828. static enum drbd_state_rv conn_try_disconnect(struct drbd_tconn *tconn, bool force)
  1829. {
  1830. enum drbd_state_rv rv;
  1831. rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING),
  1832. force ? CS_HARD : 0);
  1833. switch (rv) {
  1834. case SS_NOTHING_TO_DO:
  1835. break;
  1836. case SS_ALREADY_STANDALONE:
  1837. return SS_SUCCESS;
  1838. case SS_PRIMARY_NOP:
  1839. /* Our state checking code wants to see the peer outdated. */
  1840. rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING,
  1841. pdsk, D_OUTDATED), CS_VERBOSE);
  1842. break;
  1843. case SS_CW_FAILED_BY_PEER:
  1844. /* The peer probably wants to see us outdated. */
  1845. rv = conn_request_state(tconn, NS2(conn, C_DISCONNECTING,
  1846. disk, D_OUTDATED), 0);
  1847. if (rv == SS_IS_DISKLESS || rv == SS_LOWER_THAN_OUTDATED) {
  1848. rv = conn_request_state(tconn, NS(conn, C_DISCONNECTING),
  1849. CS_HARD);
  1850. }
  1851. break;
  1852. default:;
  1853. /* no special handling necessary */
  1854. }
  1855. if (rv >= SS_SUCCESS) {
  1856. enum drbd_state_rv rv2;
  1857. /* No one else can reconfigure the network while I am here.
  1858. * The state handling only uses drbd_thread_stop_nowait(),
  1859. * we want to really wait here until the receiver is no more.
  1860. */
  1861. drbd_thread_stop(&adm_ctx.tconn->receiver);
  1862. /* Race breaker. This additional state change request may be
  1863. * necessary, if this was a forced disconnect during a receiver
  1864. * restart. We may have "killed" the receiver thread just
  1865. * after drbdd_init() returned. Typically, we should be
  1866. * C_STANDALONE already, now, and this becomes a no-op.
  1867. */
  1868. rv2 = conn_request_state(tconn, NS(conn, C_STANDALONE),
  1869. CS_VERBOSE | CS_HARD);
  1870. if (rv2 < SS_SUCCESS)
  1871. conn_err(tconn,
  1872. "unexpected rv2=%d in conn_try_disconnect()\n",
  1873. rv2);
  1874. }
  1875. return rv;
  1876. }
  1877. int drbd_adm_disconnect(struct sk_buff *skb, struct genl_info *info)
  1878. {
  1879. struct disconnect_parms parms;
  1880. struct drbd_tconn *tconn;
  1881. enum drbd_state_rv rv;
  1882. enum drbd_ret_code retcode;
  1883. int err;
  1884. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_CONNECTION);
  1885. if (!adm_ctx.reply_skb)
  1886. return retcode;
  1887. if (retcode != NO_ERROR)
  1888. goto fail;
  1889. tconn = adm_ctx.tconn;
  1890. memset(&parms, 0, sizeof(parms));
  1891. if (info->attrs[DRBD_NLA_DISCONNECT_PARMS]) {
  1892. err = disconnect_parms_from_attrs(&parms, info);
  1893. if (err) {
  1894. retcode = ERR_MANDATORY_TAG;
  1895. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1896. goto fail;
  1897. }
  1898. }
  1899. rv = conn_try_disconnect(tconn, parms.force_disconnect);
  1900. if (rv < SS_SUCCESS)
  1901. retcode = rv; /* FIXME: Type mismatch. */
  1902. else
  1903. retcode = NO_ERROR;
  1904. fail:
  1905. drbd_adm_finish(info, retcode);
  1906. return 0;
  1907. }
  1908. void resync_after_online_grow(struct drbd_conf *mdev)
  1909. {
  1910. int iass; /* I am sync source */
  1911. dev_info(DEV, "Resync of new storage after online grow\n");
  1912. if (mdev->state.role != mdev->state.peer)
  1913. iass = (mdev->state.role == R_PRIMARY);
  1914. else
  1915. iass = test_bit(DISCARD_CONCURRENT, &mdev->tconn->flags);
  1916. if (iass)
  1917. drbd_start_resync(mdev, C_SYNC_SOURCE);
  1918. else
  1919. _drbd_request_state(mdev, NS(conn, C_WF_SYNC_UUID), CS_VERBOSE + CS_SERIALIZE);
  1920. }
  1921. int drbd_adm_resize(struct sk_buff *skb, struct genl_info *info)
  1922. {
  1923. struct disk_conf *old_disk_conf, *new_disk_conf = NULL;
  1924. struct resize_parms rs;
  1925. struct drbd_conf *mdev;
  1926. enum drbd_ret_code retcode;
  1927. enum determine_dev_size dd;
  1928. enum dds_flags ddsf;
  1929. sector_t u_size;
  1930. int err;
  1931. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  1932. if (!adm_ctx.reply_skb)
  1933. return retcode;
  1934. if (retcode != NO_ERROR)
  1935. goto fail;
  1936. memset(&rs, 0, sizeof(struct resize_parms));
  1937. if (info->attrs[DRBD_NLA_RESIZE_PARMS]) {
  1938. err = resize_parms_from_attrs(&rs, info);
  1939. if (err) {
  1940. retcode = ERR_MANDATORY_TAG;
  1941. drbd_msg_put_info(from_attrs_err_to_txt(err));
  1942. goto fail;
  1943. }
  1944. }
  1945. mdev = adm_ctx.mdev;
  1946. if (mdev->state.conn > C_CONNECTED) {
  1947. retcode = ERR_RESIZE_RESYNC;
  1948. goto fail;
  1949. }
  1950. if (mdev->state.role == R_SECONDARY &&
  1951. mdev->state.peer == R_SECONDARY) {
  1952. retcode = ERR_NO_PRIMARY;
  1953. goto fail;
  1954. }
  1955. if (!get_ldev(mdev)) {
  1956. retcode = ERR_NO_DISK;
  1957. goto fail;
  1958. }
  1959. if (rs.no_resync && mdev->tconn->agreed_pro_version < 93) {
  1960. retcode = ERR_NEED_APV_93;
  1961. goto fail_ldev;
  1962. }
  1963. rcu_read_lock();
  1964. u_size = rcu_dereference(mdev->ldev->disk_conf)->disk_size;
  1965. rcu_read_unlock();
  1966. if (u_size != (sector_t)rs.resize_size) {
  1967. new_disk_conf = kmalloc(sizeof(struct disk_conf), GFP_KERNEL);
  1968. if (!new_disk_conf) {
  1969. retcode = ERR_NOMEM;
  1970. goto fail_ldev;
  1971. }
  1972. }
  1973. if (mdev->ldev->known_size != drbd_get_capacity(mdev->ldev->backing_bdev))
  1974. mdev->ldev->known_size = drbd_get_capacity(mdev->ldev->backing_bdev);
  1975. if (new_disk_conf) {
  1976. mutex_lock(&mdev->tconn->conf_update);
  1977. old_disk_conf = mdev->ldev->disk_conf;
  1978. *new_disk_conf = *old_disk_conf;
  1979. new_disk_conf->disk_size = (sector_t)rs.resize_size;
  1980. rcu_assign_pointer(mdev->ldev->disk_conf, new_disk_conf);
  1981. mutex_unlock(&mdev->tconn->conf_update);
  1982. synchronize_rcu();
  1983. kfree(old_disk_conf);
  1984. }
  1985. ddsf = (rs.resize_force ? DDSF_FORCED : 0) | (rs.no_resync ? DDSF_NO_RESYNC : 0);
  1986. dd = drbd_determine_dev_size(mdev, ddsf);
  1987. drbd_md_sync(mdev);
  1988. put_ldev(mdev);
  1989. if (dd == dev_size_error) {
  1990. retcode = ERR_NOMEM_BITMAP;
  1991. goto fail;
  1992. }
  1993. if (mdev->state.conn == C_CONNECTED) {
  1994. if (dd == grew)
  1995. set_bit(RESIZE_PENDING, &mdev->flags);
  1996. drbd_send_uuids(mdev);
  1997. drbd_send_sizes(mdev, 1, ddsf);
  1998. }
  1999. fail:
  2000. drbd_adm_finish(info, retcode);
  2001. return 0;
  2002. fail_ldev:
  2003. put_ldev(mdev);
  2004. goto fail;
  2005. }
  2006. int drbd_adm_resource_opts(struct sk_buff *skb, struct genl_info *info)
  2007. {
  2008. enum drbd_ret_code retcode;
  2009. struct drbd_tconn *tconn;
  2010. struct res_opts res_opts;
  2011. int err;
  2012. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
  2013. if (!adm_ctx.reply_skb)
  2014. return retcode;
  2015. if (retcode != NO_ERROR)
  2016. goto fail;
  2017. tconn = adm_ctx.tconn;
  2018. res_opts = tconn->res_opts;
  2019. if (should_set_defaults(info))
  2020. set_res_opts_defaults(&res_opts);
  2021. err = res_opts_from_attrs(&res_opts, info);
  2022. if (err && err != -ENOMSG) {
  2023. retcode = ERR_MANDATORY_TAG;
  2024. drbd_msg_put_info(from_attrs_err_to_txt(err));
  2025. goto fail;
  2026. }
  2027. err = set_resource_options(tconn, &res_opts);
  2028. if (err) {
  2029. retcode = ERR_INVALID_REQUEST;
  2030. if (err == -ENOMEM)
  2031. retcode = ERR_NOMEM;
  2032. }
  2033. fail:
  2034. drbd_adm_finish(info, retcode);
  2035. return 0;
  2036. }
  2037. int drbd_adm_invalidate(struct sk_buff *skb, struct genl_info *info)
  2038. {
  2039. struct drbd_conf *mdev;
  2040. int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
  2041. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2042. if (!adm_ctx.reply_skb)
  2043. return retcode;
  2044. if (retcode != NO_ERROR)
  2045. goto out;
  2046. mdev = adm_ctx.mdev;
  2047. /* If there is still bitmap IO pending, probably because of a previous
  2048. * resync just being finished, wait for it before requesting a new resync. */
  2049. drbd_suspend_io(mdev);
  2050. wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags));
  2051. retcode = _drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T), CS_ORDERED);
  2052. if (retcode < SS_SUCCESS && retcode != SS_NEED_CONNECTION)
  2053. retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T));
  2054. while (retcode == SS_NEED_CONNECTION) {
  2055. spin_lock_irq(&mdev->tconn->req_lock);
  2056. if (mdev->state.conn < C_CONNECTED)
  2057. retcode = _drbd_set_state(_NS(mdev, disk, D_INCONSISTENT), CS_VERBOSE, NULL);
  2058. spin_unlock_irq(&mdev->tconn->req_lock);
  2059. if (retcode != SS_NEED_CONNECTION)
  2060. break;
  2061. retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_T));
  2062. }
  2063. drbd_resume_io(mdev);
  2064. out:
  2065. drbd_adm_finish(info, retcode);
  2066. return 0;
  2067. }
  2068. static int drbd_adm_simple_request_state(struct sk_buff *skb, struct genl_info *info,
  2069. union drbd_state mask, union drbd_state val)
  2070. {
  2071. enum drbd_ret_code retcode;
  2072. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2073. if (!adm_ctx.reply_skb)
  2074. return retcode;
  2075. if (retcode != NO_ERROR)
  2076. goto out;
  2077. retcode = drbd_request_state(adm_ctx.mdev, mask, val);
  2078. out:
  2079. drbd_adm_finish(info, retcode);
  2080. return 0;
  2081. }
  2082. static int drbd_bmio_set_susp_al(struct drbd_conf *mdev)
  2083. {
  2084. int rv;
  2085. rv = drbd_bmio_set_n_write(mdev);
  2086. drbd_suspend_al(mdev);
  2087. return rv;
  2088. }
  2089. int drbd_adm_invalidate_peer(struct sk_buff *skb, struct genl_info *info)
  2090. {
  2091. int retcode; /* drbd_ret_code, drbd_state_rv */
  2092. struct drbd_conf *mdev;
  2093. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2094. if (!adm_ctx.reply_skb)
  2095. return retcode;
  2096. if (retcode != NO_ERROR)
  2097. goto out;
  2098. mdev = adm_ctx.mdev;
  2099. /* If there is still bitmap IO pending, probably because of a previous
  2100. * resync just being finished, wait for it before requesting a new resync. */
  2101. drbd_suspend_io(mdev);
  2102. wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags));
  2103. retcode = _drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S), CS_ORDERED);
  2104. if (retcode < SS_SUCCESS) {
  2105. if (retcode == SS_NEED_CONNECTION && mdev->state.role == R_PRIMARY) {
  2106. /* The peer will get a resync upon connect anyways.
  2107. * Just make that into a full resync. */
  2108. retcode = drbd_request_state(mdev, NS(pdsk, D_INCONSISTENT));
  2109. if (retcode >= SS_SUCCESS) {
  2110. if (drbd_bitmap_io(mdev, &drbd_bmio_set_susp_al,
  2111. "set_n_write from invalidate_peer",
  2112. BM_LOCKED_SET_ALLOWED))
  2113. retcode = ERR_IO_MD_DISK;
  2114. }
  2115. } else
  2116. retcode = drbd_request_state(mdev, NS(conn, C_STARTING_SYNC_S));
  2117. }
  2118. drbd_resume_io(mdev);
  2119. out:
  2120. drbd_adm_finish(info, retcode);
  2121. return 0;
  2122. }
  2123. int drbd_adm_pause_sync(struct sk_buff *skb, struct genl_info *info)
  2124. {
  2125. enum drbd_ret_code retcode;
  2126. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2127. if (!adm_ctx.reply_skb)
  2128. return retcode;
  2129. if (retcode != NO_ERROR)
  2130. goto out;
  2131. if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 1)) == SS_NOTHING_TO_DO)
  2132. retcode = ERR_PAUSE_IS_SET;
  2133. out:
  2134. drbd_adm_finish(info, retcode);
  2135. return 0;
  2136. }
  2137. int drbd_adm_resume_sync(struct sk_buff *skb, struct genl_info *info)
  2138. {
  2139. union drbd_dev_state s;
  2140. enum drbd_ret_code retcode;
  2141. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2142. if (!adm_ctx.reply_skb)
  2143. return retcode;
  2144. if (retcode != NO_ERROR)
  2145. goto out;
  2146. if (drbd_request_state(adm_ctx.mdev, NS(user_isp, 0)) == SS_NOTHING_TO_DO) {
  2147. s = adm_ctx.mdev->state;
  2148. if (s.conn == C_PAUSED_SYNC_S || s.conn == C_PAUSED_SYNC_T) {
  2149. retcode = s.aftr_isp ? ERR_PIC_AFTER_DEP :
  2150. s.peer_isp ? ERR_PIC_PEER_DEP : ERR_PAUSE_IS_CLEAR;
  2151. } else {
  2152. retcode = ERR_PAUSE_IS_CLEAR;
  2153. }
  2154. }
  2155. out:
  2156. drbd_adm_finish(info, retcode);
  2157. return 0;
  2158. }
  2159. int drbd_adm_suspend_io(struct sk_buff *skb, struct genl_info *info)
  2160. {
  2161. return drbd_adm_simple_request_state(skb, info, NS(susp, 1));
  2162. }
  2163. int drbd_adm_resume_io(struct sk_buff *skb, struct genl_info *info)
  2164. {
  2165. struct drbd_conf *mdev;
  2166. int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
  2167. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2168. if (!adm_ctx.reply_skb)
  2169. return retcode;
  2170. if (retcode != NO_ERROR)
  2171. goto out;
  2172. mdev = adm_ctx.mdev;
  2173. if (test_bit(NEW_CUR_UUID, &mdev->flags)) {
  2174. drbd_uuid_new_current(mdev);
  2175. clear_bit(NEW_CUR_UUID, &mdev->flags);
  2176. }
  2177. drbd_suspend_io(mdev);
  2178. retcode = drbd_request_state(mdev, NS3(susp, 0, susp_nod, 0, susp_fen, 0));
  2179. if (retcode == SS_SUCCESS) {
  2180. if (mdev->state.conn < C_CONNECTED)
  2181. tl_clear(mdev->tconn);
  2182. if (mdev->state.disk == D_DISKLESS || mdev->state.disk == D_FAILED)
  2183. tl_restart(mdev->tconn, FAIL_FROZEN_DISK_IO);
  2184. }
  2185. drbd_resume_io(mdev);
  2186. out:
  2187. drbd_adm_finish(info, retcode);
  2188. return 0;
  2189. }
  2190. int drbd_adm_outdate(struct sk_buff *skb, struct genl_info *info)
  2191. {
  2192. return drbd_adm_simple_request_state(skb, info, NS(disk, D_OUTDATED));
  2193. }
  2194. int nla_put_drbd_cfg_context(struct sk_buff *skb, struct drbd_tconn *tconn, unsigned vnr)
  2195. {
  2196. struct nlattr *nla;
  2197. nla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT);
  2198. if (!nla)
  2199. goto nla_put_failure;
  2200. if (vnr != VOLUME_UNSPECIFIED &&
  2201. nla_put_u32(skb, T_ctx_volume, vnr))
  2202. goto nla_put_failure;
  2203. if (nla_put_string(skb, T_ctx_resource_name, tconn->name))
  2204. goto nla_put_failure;
  2205. if (tconn->my_addr_len &&
  2206. nla_put(skb, T_ctx_my_addr, tconn->my_addr_len, &tconn->my_addr))
  2207. goto nla_put_failure;
  2208. if (tconn->peer_addr_len &&
  2209. nla_put(skb, T_ctx_peer_addr, tconn->peer_addr_len, &tconn->peer_addr))
  2210. goto nla_put_failure;
  2211. nla_nest_end(skb, nla);
  2212. return 0;
  2213. nla_put_failure:
  2214. if (nla)
  2215. nla_nest_cancel(skb, nla);
  2216. return -EMSGSIZE;
  2217. }
  2218. int nla_put_status_info(struct sk_buff *skb, struct drbd_conf *mdev,
  2219. const struct sib_info *sib)
  2220. {
  2221. struct state_info *si = NULL; /* for sizeof(si->member); */
  2222. struct net_conf *nc;
  2223. struct nlattr *nla;
  2224. int got_ldev;
  2225. int err = 0;
  2226. int exclude_sensitive;
  2227. /* If sib != NULL, this is drbd_bcast_event, which anyone can listen
  2228. * to. So we better exclude_sensitive information.
  2229. *
  2230. * If sib == NULL, this is drbd_adm_get_status, executed synchronously
  2231. * in the context of the requesting user process. Exclude sensitive
  2232. * information, unless current has superuser.
  2233. *
  2234. * NOTE: for drbd_adm_get_status_all(), this is a netlink dump, and
  2235. * relies on the current implementation of netlink_dump(), which
  2236. * executes the dump callback successively from netlink_recvmsg(),
  2237. * always in the context of the receiving process */
  2238. exclude_sensitive = sib || !capable(CAP_SYS_ADMIN);
  2239. got_ldev = get_ldev(mdev);
  2240. /* We need to add connection name and volume number information still.
  2241. * Minor number is in drbd_genlmsghdr. */
  2242. if (nla_put_drbd_cfg_context(skb, mdev->tconn, mdev->vnr))
  2243. goto nla_put_failure;
  2244. if (res_opts_to_skb(skb, &mdev->tconn->res_opts, exclude_sensitive))
  2245. goto nla_put_failure;
  2246. rcu_read_lock();
  2247. if (got_ldev)
  2248. if (disk_conf_to_skb(skb, rcu_dereference(mdev->ldev->disk_conf), exclude_sensitive))
  2249. goto nla_put_failure;
  2250. nc = rcu_dereference(mdev->tconn->net_conf);
  2251. if (nc)
  2252. err = net_conf_to_skb(skb, nc, exclude_sensitive);
  2253. rcu_read_unlock();
  2254. if (err)
  2255. goto nla_put_failure;
  2256. nla = nla_nest_start(skb, DRBD_NLA_STATE_INFO);
  2257. if (!nla)
  2258. goto nla_put_failure;
  2259. if (nla_put_u32(skb, T_sib_reason, sib ? sib->sib_reason : SIB_GET_STATUS_REPLY) ||
  2260. nla_put_u32(skb, T_current_state, mdev->state.i) ||
  2261. nla_put_u64(skb, T_ed_uuid, mdev->ed_uuid) ||
  2262. nla_put_u64(skb, T_capacity, drbd_get_capacity(mdev->this_bdev)))
  2263. goto nla_put_failure;
  2264. if (got_ldev) {
  2265. if (nla_put_u32(skb, T_disk_flags, mdev->ldev->md.flags) ||
  2266. nla_put(skb, T_uuids, sizeof(si->uuids), mdev->ldev->md.uuid) ||
  2267. nla_put_u64(skb, T_bits_total, drbd_bm_bits(mdev)) ||
  2268. nla_put_u64(skb, T_bits_oos, drbd_bm_total_weight(mdev)))
  2269. goto nla_put_failure;
  2270. if (C_SYNC_SOURCE <= mdev->state.conn &&
  2271. C_PAUSED_SYNC_T >= mdev->state.conn) {
  2272. if (nla_put_u64(skb, T_bits_rs_total, mdev->rs_total) ||
  2273. nla_put_u64(skb, T_bits_rs_failed, mdev->rs_failed))
  2274. goto nla_put_failure;
  2275. }
  2276. }
  2277. if (sib) {
  2278. switch(sib->sib_reason) {
  2279. case SIB_SYNC_PROGRESS:
  2280. case SIB_GET_STATUS_REPLY:
  2281. break;
  2282. case SIB_STATE_CHANGE:
  2283. if (nla_put_u32(skb, T_prev_state, sib->os.i) ||
  2284. nla_put_u32(skb, T_new_state, sib->ns.i))
  2285. goto nla_put_failure;
  2286. break;
  2287. case SIB_HELPER_POST:
  2288. if (nla_put_u32(skb, T_helper_exit_code,
  2289. sib->helper_exit_code))
  2290. goto nla_put_failure;
  2291. /* fall through */
  2292. case SIB_HELPER_PRE:
  2293. if (nla_put_string(skb, T_helper, sib->helper_name))
  2294. goto nla_put_failure;
  2295. break;
  2296. }
  2297. }
  2298. nla_nest_end(skb, nla);
  2299. if (0)
  2300. nla_put_failure:
  2301. err = -EMSGSIZE;
  2302. if (got_ldev)
  2303. put_ldev(mdev);
  2304. return err;
  2305. }
  2306. int drbd_adm_get_status(struct sk_buff *skb, struct genl_info *info)
  2307. {
  2308. enum drbd_ret_code retcode;
  2309. int err;
  2310. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2311. if (!adm_ctx.reply_skb)
  2312. return retcode;
  2313. if (retcode != NO_ERROR)
  2314. goto out;
  2315. err = nla_put_status_info(adm_ctx.reply_skb, adm_ctx.mdev, NULL);
  2316. if (err) {
  2317. nlmsg_free(adm_ctx.reply_skb);
  2318. return err;
  2319. }
  2320. out:
  2321. drbd_adm_finish(info, retcode);
  2322. return 0;
  2323. }
  2324. int get_one_status(struct sk_buff *skb, struct netlink_callback *cb)
  2325. {
  2326. struct drbd_conf *mdev;
  2327. struct drbd_genlmsghdr *dh;
  2328. struct drbd_tconn *pos = (struct drbd_tconn*)cb->args[0];
  2329. struct drbd_tconn *tconn = NULL;
  2330. struct drbd_tconn *tmp;
  2331. unsigned volume = cb->args[1];
  2332. /* Open coded, deferred, iteration:
  2333. * list_for_each_entry_safe(tconn, tmp, &drbd_tconns, all_tconn) {
  2334. * idr_for_each_entry(&tconn->volumes, mdev, i) {
  2335. * ...
  2336. * }
  2337. * }
  2338. * where tconn is cb->args[0];
  2339. * and i is cb->args[1];
  2340. *
  2341. * cb->args[2] indicates if we shall loop over all resources,
  2342. * or just dump all volumes of a single resource.
  2343. *
  2344. * This may miss entries inserted after this dump started,
  2345. * or entries deleted before they are reached.
  2346. *
  2347. * We need to make sure the mdev won't disappear while
  2348. * we are looking at it, and revalidate our iterators
  2349. * on each iteration.
  2350. */
  2351. /* synchronize with conn_create()/conn_destroy() */
  2352. rcu_read_lock();
  2353. /* revalidate iterator position */
  2354. list_for_each_entry_rcu(tmp, &drbd_tconns, all_tconn) {
  2355. if (pos == NULL) {
  2356. /* first iteration */
  2357. pos = tmp;
  2358. tconn = pos;
  2359. break;
  2360. }
  2361. if (tmp == pos) {
  2362. tconn = pos;
  2363. break;
  2364. }
  2365. }
  2366. if (tconn) {
  2367. next_tconn:
  2368. mdev = idr_get_next(&tconn->volumes, &volume);
  2369. if (!mdev) {
  2370. /* No more volumes to dump on this tconn.
  2371. * Advance tconn iterator. */
  2372. pos = list_entry_rcu(tconn->all_tconn.next,
  2373. struct drbd_tconn, all_tconn);
  2374. /* Did we dump any volume on this tconn yet? */
  2375. if (volume != 0) {
  2376. /* If we reached the end of the list,
  2377. * or only a single resource dump was requested,
  2378. * we are done. */
  2379. if (&pos->all_tconn == &drbd_tconns || cb->args[2])
  2380. goto out;
  2381. volume = 0;
  2382. tconn = pos;
  2383. goto next_tconn;
  2384. }
  2385. }
  2386. dh = genlmsg_put(skb, NETLINK_CB(cb->skb).pid,
  2387. cb->nlh->nlmsg_seq, &drbd_genl_family,
  2388. NLM_F_MULTI, DRBD_ADM_GET_STATUS);
  2389. if (!dh)
  2390. goto out;
  2391. if (!mdev) {
  2392. /* This is a tconn without a single volume.
  2393. * Suprisingly enough, it may have a network
  2394. * configuration. */
  2395. struct net_conf *nc;
  2396. dh->minor = -1U;
  2397. dh->ret_code = NO_ERROR;
  2398. if (nla_put_drbd_cfg_context(skb, tconn, VOLUME_UNSPECIFIED))
  2399. goto cancel;
  2400. nc = rcu_dereference(tconn->net_conf);
  2401. if (nc && net_conf_to_skb(skb, nc, 1) != 0)
  2402. goto cancel;
  2403. goto done;
  2404. }
  2405. D_ASSERT(mdev->vnr == volume);
  2406. D_ASSERT(mdev->tconn == tconn);
  2407. dh->minor = mdev_to_minor(mdev);
  2408. dh->ret_code = NO_ERROR;
  2409. if (nla_put_status_info(skb, mdev, NULL)) {
  2410. cancel:
  2411. genlmsg_cancel(skb, dh);
  2412. goto out;
  2413. }
  2414. done:
  2415. genlmsg_end(skb, dh);
  2416. }
  2417. out:
  2418. rcu_read_unlock();
  2419. /* where to start the next iteration */
  2420. cb->args[0] = (long)pos;
  2421. cb->args[1] = (pos == tconn) ? volume + 1 : 0;
  2422. /* No more tconns/volumes/minors found results in an empty skb.
  2423. * Which will terminate the dump. */
  2424. return skb->len;
  2425. }
  2426. /*
  2427. * Request status of all resources, or of all volumes within a single resource.
  2428. *
  2429. * This is a dump, as the answer may not fit in a single reply skb otherwise.
  2430. * Which means we cannot use the family->attrbuf or other such members, because
  2431. * dump is NOT protected by the genl_lock(). During dump, we only have access
  2432. * to the incoming skb, and need to opencode "parsing" of the nlattr payload.
  2433. *
  2434. * Once things are setup properly, we call into get_one_status().
  2435. */
  2436. int drbd_adm_get_status_all(struct sk_buff *skb, struct netlink_callback *cb)
  2437. {
  2438. const unsigned hdrlen = GENL_HDRLEN + GENL_MAGIC_FAMILY_HDRSZ;
  2439. struct nlattr *nla;
  2440. const char *resource_name;
  2441. struct drbd_tconn *tconn;
  2442. int maxtype;
  2443. /* Is this a followup call? */
  2444. if (cb->args[0]) {
  2445. /* ... of a single resource dump,
  2446. * and the resource iterator has been advanced already? */
  2447. if (cb->args[2] && cb->args[2] != cb->args[0])
  2448. return 0; /* DONE. */
  2449. goto dump;
  2450. }
  2451. /* First call (from netlink_dump_start). We need to figure out
  2452. * which resource(s) the user wants us to dump. */
  2453. nla = nla_find(nlmsg_attrdata(cb->nlh, hdrlen),
  2454. nlmsg_attrlen(cb->nlh, hdrlen),
  2455. DRBD_NLA_CFG_CONTEXT);
  2456. /* No explicit context given. Dump all. */
  2457. if (!nla)
  2458. goto dump;
  2459. maxtype = ARRAY_SIZE(drbd_cfg_context_nl_policy) - 1;
  2460. nla = drbd_nla_find_nested(maxtype, nla, __nla_type(T_ctx_resource_name));
  2461. if (IS_ERR(nla))
  2462. return PTR_ERR(nla);
  2463. /* context given, but no name present? */
  2464. if (!nla)
  2465. return -EINVAL;
  2466. resource_name = nla_data(nla);
  2467. tconn = conn_get_by_name(resource_name);
  2468. if (!tconn)
  2469. return -ENODEV;
  2470. kref_put(&tconn->kref, &conn_destroy); /* get_one_status() (re)validates tconn by itself */
  2471. /* prime iterators, and set "filter" mode mark:
  2472. * only dump this tconn. */
  2473. cb->args[0] = (long)tconn;
  2474. /* cb->args[1] = 0; passed in this way. */
  2475. cb->args[2] = (long)tconn;
  2476. dump:
  2477. return get_one_status(skb, cb);
  2478. }
  2479. int drbd_adm_get_timeout_type(struct sk_buff *skb, struct genl_info *info)
  2480. {
  2481. enum drbd_ret_code retcode;
  2482. struct timeout_parms tp;
  2483. int err;
  2484. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2485. if (!adm_ctx.reply_skb)
  2486. return retcode;
  2487. if (retcode != NO_ERROR)
  2488. goto out;
  2489. tp.timeout_type =
  2490. adm_ctx.mdev->state.pdsk == D_OUTDATED ? UT_PEER_OUTDATED :
  2491. test_bit(USE_DEGR_WFC_T, &adm_ctx.mdev->flags) ? UT_DEGRADED :
  2492. UT_DEFAULT;
  2493. err = timeout_parms_to_priv_skb(adm_ctx.reply_skb, &tp);
  2494. if (err) {
  2495. nlmsg_free(adm_ctx.reply_skb);
  2496. return err;
  2497. }
  2498. out:
  2499. drbd_adm_finish(info, retcode);
  2500. return 0;
  2501. }
  2502. int drbd_adm_start_ov(struct sk_buff *skb, struct genl_info *info)
  2503. {
  2504. struct drbd_conf *mdev;
  2505. enum drbd_ret_code retcode;
  2506. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2507. if (!adm_ctx.reply_skb)
  2508. return retcode;
  2509. if (retcode != NO_ERROR)
  2510. goto out;
  2511. mdev = adm_ctx.mdev;
  2512. if (info->attrs[DRBD_NLA_START_OV_PARMS]) {
  2513. /* resume from last known position, if possible */
  2514. struct start_ov_parms parms =
  2515. { .ov_start_sector = mdev->ov_start_sector };
  2516. int err = start_ov_parms_from_attrs(&parms, info);
  2517. if (err) {
  2518. retcode = ERR_MANDATORY_TAG;
  2519. drbd_msg_put_info(from_attrs_err_to_txt(err));
  2520. goto out;
  2521. }
  2522. /* w_make_ov_request expects position to be aligned */
  2523. mdev->ov_start_sector = parms.ov_start_sector & ~BM_SECT_PER_BIT;
  2524. }
  2525. /* If there is still bitmap IO pending, e.g. previous resync or verify
  2526. * just being finished, wait for it before requesting a new resync. */
  2527. drbd_suspend_io(mdev);
  2528. wait_event(mdev->misc_wait, !test_bit(BITMAP_IO, &mdev->flags));
  2529. retcode = drbd_request_state(mdev,NS(conn,C_VERIFY_S));
  2530. drbd_resume_io(mdev);
  2531. out:
  2532. drbd_adm_finish(info, retcode);
  2533. return 0;
  2534. }
  2535. int drbd_adm_new_c_uuid(struct sk_buff *skb, struct genl_info *info)
  2536. {
  2537. struct drbd_conf *mdev;
  2538. enum drbd_ret_code retcode;
  2539. int skip_initial_sync = 0;
  2540. int err;
  2541. struct new_c_uuid_parms args;
  2542. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2543. if (!adm_ctx.reply_skb)
  2544. return retcode;
  2545. if (retcode != NO_ERROR)
  2546. goto out_nolock;
  2547. mdev = adm_ctx.mdev;
  2548. memset(&args, 0, sizeof(args));
  2549. if (info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]) {
  2550. err = new_c_uuid_parms_from_attrs(&args, info);
  2551. if (err) {
  2552. retcode = ERR_MANDATORY_TAG;
  2553. drbd_msg_put_info(from_attrs_err_to_txt(err));
  2554. goto out_nolock;
  2555. }
  2556. }
  2557. mutex_lock(mdev->state_mutex); /* Protects us against serialized state changes. */
  2558. if (!get_ldev(mdev)) {
  2559. retcode = ERR_NO_DISK;
  2560. goto out;
  2561. }
  2562. /* this is "skip initial sync", assume to be clean */
  2563. if (mdev->state.conn == C_CONNECTED && mdev->tconn->agreed_pro_version >= 90 &&
  2564. mdev->ldev->md.uuid[UI_CURRENT] == UUID_JUST_CREATED && args.clear_bm) {
  2565. dev_info(DEV, "Preparing to skip initial sync\n");
  2566. skip_initial_sync = 1;
  2567. } else if (mdev->state.conn != C_STANDALONE) {
  2568. retcode = ERR_CONNECTED;
  2569. goto out_dec;
  2570. }
  2571. drbd_uuid_set(mdev, UI_BITMAP, 0); /* Rotate UI_BITMAP to History 1, etc... */
  2572. drbd_uuid_new_current(mdev); /* New current, previous to UI_BITMAP */
  2573. if (args.clear_bm) {
  2574. err = drbd_bitmap_io(mdev, &drbd_bmio_clear_n_write,
  2575. "clear_n_write from new_c_uuid", BM_LOCKED_MASK);
  2576. if (err) {
  2577. dev_err(DEV, "Writing bitmap failed with %d\n",err);
  2578. retcode = ERR_IO_MD_DISK;
  2579. }
  2580. if (skip_initial_sync) {
  2581. drbd_send_uuids_skip_initial_sync(mdev);
  2582. _drbd_uuid_set(mdev, UI_BITMAP, 0);
  2583. drbd_print_uuids(mdev, "cleared bitmap UUID");
  2584. spin_lock_irq(&mdev->tconn->req_lock);
  2585. _drbd_set_state(_NS2(mdev, disk, D_UP_TO_DATE, pdsk, D_UP_TO_DATE),
  2586. CS_VERBOSE, NULL);
  2587. spin_unlock_irq(&mdev->tconn->req_lock);
  2588. }
  2589. }
  2590. drbd_md_sync(mdev);
  2591. out_dec:
  2592. put_ldev(mdev);
  2593. out:
  2594. mutex_unlock(mdev->state_mutex);
  2595. out_nolock:
  2596. drbd_adm_finish(info, retcode);
  2597. return 0;
  2598. }
  2599. static enum drbd_ret_code
  2600. drbd_check_resource_name(const char *name)
  2601. {
  2602. if (!name || !name[0]) {
  2603. drbd_msg_put_info("resource name missing");
  2604. return ERR_MANDATORY_TAG;
  2605. }
  2606. /* if we want to use these in sysfs/configfs/debugfs some day,
  2607. * we must not allow slashes */
  2608. if (strchr(name, '/')) {
  2609. drbd_msg_put_info("invalid resource name");
  2610. return ERR_INVALID_REQUEST;
  2611. }
  2612. return NO_ERROR;
  2613. }
  2614. int drbd_adm_new_resource(struct sk_buff *skb, struct genl_info *info)
  2615. {
  2616. enum drbd_ret_code retcode;
  2617. struct res_opts res_opts;
  2618. int err;
  2619. retcode = drbd_adm_prepare(skb, info, 0);
  2620. if (!adm_ctx.reply_skb)
  2621. return retcode;
  2622. if (retcode != NO_ERROR)
  2623. goto out;
  2624. set_res_opts_defaults(&res_opts);
  2625. err = res_opts_from_attrs(&res_opts, info);
  2626. if (err && err != -ENOMSG) {
  2627. retcode = ERR_MANDATORY_TAG;
  2628. drbd_msg_put_info(from_attrs_err_to_txt(err));
  2629. goto out;
  2630. }
  2631. retcode = drbd_check_resource_name(adm_ctx.resource_name);
  2632. if (retcode != NO_ERROR)
  2633. goto out;
  2634. if (adm_ctx.tconn) {
  2635. if (info->nlhdr->nlmsg_flags & NLM_F_EXCL) {
  2636. retcode = ERR_INVALID_REQUEST;
  2637. drbd_msg_put_info("resource exists");
  2638. }
  2639. /* else: still NO_ERROR */
  2640. goto out;
  2641. }
  2642. if (!conn_create(adm_ctx.resource_name, &res_opts))
  2643. retcode = ERR_NOMEM;
  2644. out:
  2645. drbd_adm_finish(info, retcode);
  2646. return 0;
  2647. }
  2648. int drbd_adm_add_minor(struct sk_buff *skb, struct genl_info *info)
  2649. {
  2650. struct drbd_genlmsghdr *dh = info->userhdr;
  2651. enum drbd_ret_code retcode;
  2652. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
  2653. if (!adm_ctx.reply_skb)
  2654. return retcode;
  2655. if (retcode != NO_ERROR)
  2656. goto out;
  2657. if (dh->minor > MINORMASK) {
  2658. drbd_msg_put_info("requested minor out of range");
  2659. retcode = ERR_INVALID_REQUEST;
  2660. goto out;
  2661. }
  2662. if (adm_ctx.volume > DRBD_VOLUME_MAX) {
  2663. drbd_msg_put_info("requested volume id out of range");
  2664. retcode = ERR_INVALID_REQUEST;
  2665. goto out;
  2666. }
  2667. /* drbd_adm_prepare made sure already
  2668. * that mdev->tconn and mdev->vnr match the request. */
  2669. if (adm_ctx.mdev) {
  2670. if (info->nlhdr->nlmsg_flags & NLM_F_EXCL)
  2671. retcode = ERR_MINOR_EXISTS;
  2672. /* else: still NO_ERROR */
  2673. goto out;
  2674. }
  2675. retcode = conn_new_minor(adm_ctx.tconn, dh->minor, adm_ctx.volume);
  2676. out:
  2677. drbd_adm_finish(info, retcode);
  2678. return 0;
  2679. }
  2680. static enum drbd_ret_code adm_delete_minor(struct drbd_conf *mdev)
  2681. {
  2682. if (mdev->state.disk == D_DISKLESS &&
  2683. /* no need to be mdev->state.conn == C_STANDALONE &&
  2684. * we may want to delete a minor from a live replication group.
  2685. */
  2686. mdev->state.role == R_SECONDARY) {
  2687. _drbd_request_state(mdev, NS(conn, C_WF_REPORT_PARAMS),
  2688. CS_VERBOSE + CS_WAIT_COMPLETE);
  2689. idr_remove(&mdev->tconn->volumes, mdev->vnr);
  2690. idr_remove(&minors, mdev_to_minor(mdev));
  2691. del_gendisk(mdev->vdisk);
  2692. synchronize_rcu();
  2693. kref_put(&mdev->kref, &drbd_minor_destroy);
  2694. return NO_ERROR;
  2695. } else
  2696. return ERR_MINOR_CONFIGURED;
  2697. }
  2698. int drbd_adm_delete_minor(struct sk_buff *skb, struct genl_info *info)
  2699. {
  2700. enum drbd_ret_code retcode;
  2701. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_MINOR);
  2702. if (!adm_ctx.reply_skb)
  2703. return retcode;
  2704. if (retcode != NO_ERROR)
  2705. goto out;
  2706. retcode = adm_delete_minor(adm_ctx.mdev);
  2707. out:
  2708. drbd_adm_finish(info, retcode);
  2709. return 0;
  2710. }
  2711. int drbd_adm_down(struct sk_buff *skb, struct genl_info *info)
  2712. {
  2713. int retcode; /* enum drbd_ret_code rsp. enum drbd_state_rv */
  2714. struct drbd_conf *mdev;
  2715. unsigned i;
  2716. retcode = drbd_adm_prepare(skb, info, 0);
  2717. if (!adm_ctx.reply_skb)
  2718. return retcode;
  2719. if (retcode != NO_ERROR)
  2720. goto out;
  2721. if (!adm_ctx.tconn) {
  2722. retcode = ERR_RES_NOT_KNOWN;
  2723. goto out;
  2724. }
  2725. /* demote */
  2726. idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) {
  2727. retcode = drbd_set_role(mdev, R_SECONDARY, 0);
  2728. if (retcode < SS_SUCCESS) {
  2729. drbd_msg_put_info("failed to demote");
  2730. goto out;
  2731. }
  2732. }
  2733. retcode = conn_try_disconnect(adm_ctx.tconn, 0);
  2734. if (retcode < SS_SUCCESS) {
  2735. drbd_msg_put_info("failed to disconnect");
  2736. goto out;
  2737. }
  2738. /* detach */
  2739. idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) {
  2740. retcode = adm_detach(mdev, 0);
  2741. if (retcode < SS_SUCCESS || retcode > NO_ERROR) {
  2742. drbd_msg_put_info("failed to detach");
  2743. goto out;
  2744. }
  2745. }
  2746. /* If we reach this, all volumes (of this tconn) are Secondary,
  2747. * Disconnected, Diskless, aka Unconfigured. Make sure all threads have
  2748. * actually stopped, state handling only does drbd_thread_stop_nowait(). */
  2749. drbd_thread_stop(&adm_ctx.tconn->worker);
  2750. /* Now, nothing can fail anymore */
  2751. /* delete volumes */
  2752. idr_for_each_entry(&adm_ctx.tconn->volumes, mdev, i) {
  2753. retcode = adm_delete_minor(mdev);
  2754. if (retcode != NO_ERROR) {
  2755. /* "can not happen" */
  2756. drbd_msg_put_info("failed to delete volume");
  2757. goto out;
  2758. }
  2759. }
  2760. /* delete connection */
  2761. if (conn_lowest_minor(adm_ctx.tconn) < 0) {
  2762. list_del_rcu(&adm_ctx.tconn->all_tconn);
  2763. synchronize_rcu();
  2764. kref_put(&adm_ctx.tconn->kref, &conn_destroy);
  2765. retcode = NO_ERROR;
  2766. } else {
  2767. /* "can not happen" */
  2768. retcode = ERR_RES_IN_USE;
  2769. drbd_msg_put_info("failed to delete connection");
  2770. }
  2771. goto out;
  2772. out:
  2773. drbd_adm_finish(info, retcode);
  2774. return 0;
  2775. }
  2776. int drbd_adm_del_resource(struct sk_buff *skb, struct genl_info *info)
  2777. {
  2778. enum drbd_ret_code retcode;
  2779. retcode = drbd_adm_prepare(skb, info, DRBD_ADM_NEED_RESOURCE);
  2780. if (!adm_ctx.reply_skb)
  2781. return retcode;
  2782. if (retcode != NO_ERROR)
  2783. goto out;
  2784. if (conn_lowest_minor(adm_ctx.tconn) < 0) {
  2785. list_del_rcu(&adm_ctx.tconn->all_tconn);
  2786. synchronize_rcu();
  2787. kref_put(&adm_ctx.tconn->kref, &conn_destroy);
  2788. retcode = NO_ERROR;
  2789. } else {
  2790. retcode = ERR_RES_IN_USE;
  2791. }
  2792. if (retcode == NO_ERROR)
  2793. drbd_thread_stop(&adm_ctx.tconn->worker);
  2794. out:
  2795. drbd_adm_finish(info, retcode);
  2796. return 0;
  2797. }
  2798. void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
  2799. {
  2800. static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
  2801. struct sk_buff *msg;
  2802. struct drbd_genlmsghdr *d_out;
  2803. unsigned seq;
  2804. int err = -ENOMEM;
  2805. seq = atomic_inc_return(&drbd_genl_seq);
  2806. msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
  2807. if (!msg)
  2808. goto failed;
  2809. err = -EMSGSIZE;
  2810. d_out = genlmsg_put(msg, 0, seq, &drbd_genl_family, 0, DRBD_EVENT);
  2811. if (!d_out) /* cannot happen, but anyways. */
  2812. goto nla_put_failure;
  2813. d_out->minor = mdev_to_minor(mdev);
  2814. d_out->ret_code = NO_ERROR;
  2815. if (nla_put_status_info(msg, mdev, sib))
  2816. goto nla_put_failure;
  2817. genlmsg_end(msg, d_out);
  2818. err = drbd_genl_multicast_events(msg, 0);
  2819. /* msg has been consumed or freed in netlink_broadcast() */
  2820. if (err && err != -ESRCH)
  2821. goto failed;
  2822. return;
  2823. nla_put_failure:
  2824. nlmsg_free(msg);
  2825. failed:
  2826. dev_err(DEV, "Error %d while broadcasting event. "
  2827. "Event seq:%u sib_reason:%u\n",
  2828. err, seq, sib->sib_reason);
  2829. }