irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

libpassthru.cpp
Go to the documentation of this file.
1 
3 // Plugin defining a weighted passthru resource.
4 //
5 // Useful for dialing child votes up or down for both read and write.
7 
8 // =-=-=-=-=-=-=-
9 // irods includes
10 #include "msParam.h"
11 #include "miscServerFunct.hpp"
12 
13 // =-=-=-=-=-=-=-
15 #include "irods_file_object.hpp"
19 #include "irods_error.hpp"
22 #include "irods_lexical_cast.hpp"
23 
24 // =-=-=-=-=-=-=-
25 // stl includes
26 #include <iostream>
27 #include <sstream>
28 #include <vector>
29 #include <string>
30 #include <boost/lexical_cast.hpp>
31 
32 // =-=-=-=-=-=-=-
33 // system includes
34 #ifndef _WIN32
35 #include <sys/file.h>
36 #include <sys/param.h>
37 #endif
38 #include <errno.h>
39 #include <sys/stat.h>
40 #include <string.h>
41 #ifndef _WIN32
42 #include <unistd.h>
43 #endif
44 #include <sys/types.h>
45 #if defined(osx_platform)
46 #include <sys/malloc.h>
47 #else
48 #include <malloc.h>
49 #endif
50 #include <fcntl.h>
51 #ifndef _WIN32
52 #include <sys/file.h>
53 #include <unistd.h>
54 #endif
55 #include <dirent.h>
56 
57 #if defined(solaris_platform)
58 #include <sys/statvfs.h>
59 #endif
60 #if defined(linux_platform)
61 #include <sys/vfs.h>
62 #endif
63 #include <sys/stat.h>
64 
65 #include <string.h>
66 
67 
68 const std::string WRITE_WEIGHT_KW( "write" );
69 const std::string READ_WEIGHT_KW( "read" );
70 
71 
72 // =-=-=-=-=-=-=-
73 // 2. Define operations which will be called by the file*
74 // calls declared in server/driver/include/fileDriver.h
75 // =-=-=-=-=-=-=-
76 
77 // =-=-=-=-=-=-=-
78 // NOTE :: to access properties in the _prop_map do the
79 // :: following :
80 // :: double my_var = 0.0;
81 // :: irods::error ret = _prop_map.get< double >( "my_key", my_var );
82 // =-=-=-=-=-=-=-
83 
85 // Utility functions
86 
87 // =-=-=-=-=-=-=-
91  irods::resource_ptr& _resc ) {
92 
93  irods::resource_child_map* cmap_ref;
94  _props.get< irods::resource_child_map* >(
96  cmap_ref );
97 
98  irods::error result = SUCCESS();
99  std::pair<std::string, irods::resource_ptr> child_pair;
100  if ( cmap_ref->size() != 1 ) {
101  std::stringstream msg;
102  msg << "passthru_get_first_child_resc - Passthru resource can have 1 and only 1 child. This resource has " << cmap_ref->size();
103  result = ERROR( -1, msg.str() );
104  }
105  else {
106  child_pair = cmap_ref->begin()->second;
107  _resc = child_pair.second;
108  }
109  return result;
110 
111 } // passthru_get_first_child_resc
112 
113 // =-=-=-=-=-=-=-
116  irods::plugin_context& _ctx ) {
117  // =-=-=-=-=-=-=-
118  // verify that the resc context is valid
119  irods::error ret = _ctx.valid();
120  if ( !ret.ok() ) {
121  std::stringstream msg;
122  msg << " - resource context is invalid.";
123  return PASSMSG( msg.str(), ret );
124  }
125 
126  return SUCCESS();
127 
128 } // passthru_check_params
129 
130 // =-=-=-=-=-=-=-
131 // interface for POSIX create
133  irods::plugin_context& _ctx ) {
134  irods::error result = SUCCESS();
135  irods::error ret;
136  ret = passthru_check_params( _ctx );
137  if ( !ret.ok() ) {
138  result = PASSMSG( "bad params.", ret );
139  }
140  else {
141  irods::resource_ptr resc;
142  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
143  if ( !ret.ok() ) {
144  result = PASSMSG( "failed getting the first child resource pointer.", ret );
145  }
146  else {
147  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_CREATE, _ctx.fco() );
148  if ( !ret.ok() ) {
149  result = PASSMSG( "failed calling child create.", ret );
150  }
151  }
152  }
153  return result;
154 } // passthru_file_create_plugin
155 
156 // =-=-=-=-=-=-=-
157 // interface for POSIX Open
159  irods::plugin_context& _ctx ) {
160  irods::error result = SUCCESS();
161  irods::error ret;
162 
163  ret = passthru_check_params( _ctx );
164  if ( !ret.ok() ) {
165  result = PASSMSG( "bad params.", ret );
166  }
167  else {
168  irods::resource_ptr resc;
169  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
170  if ( !ret.ok() ) {
171  result = PASSMSG( "failed getting the first child resource pointer.", ret );
172  }
173  else {
174  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_OPEN, _ctx.fco() );
175  result = PASSMSG( "passthru_file_open_plugin - failed calling child open.", ret );
176  }
177  }
178  return result;
179 } // passthru_file_open_plugin
180 
181 // =-=-=-=-=-=-=-
182 // interface for POSIX Read
184  irods::plugin_context& _ctx,
185  void* _buf,
186  int _len ) {
187  irods::error result = SUCCESS();
188  irods::error ret;
189 
190  ret = passthru_check_params( _ctx );
191  if ( !ret.ok() ) {
192  result = PASSMSG( "bad params.", ret );
193  }
194  else {
195  irods::resource_ptr resc;
196  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
197  if ( !ret.ok() ) {
198  result = PASSMSG( "failed getting the first child resource pointer.", ret );
199  }
200  else {
201  ret = resc->call<void*, int>( _ctx.comm(), irods::RESOURCE_OP_READ, _ctx.fco(), _buf, _len );
202  result = PASSMSG( "passthru_file_read_plugin - failed calling child read.", ret );
203  }
204  }
205  return result;
206 } // passthru_file_read_plugin
207 
208 // =-=-=-=-=-=-=-
209 // interface for POSIX Write
211  irods::plugin_context& _ctx,
212  void* _buf,
213  int _len ) {
214  irods::error result = SUCCESS();
215  irods::error ret;
216 
217  ret = passthru_check_params( _ctx );
218  if ( !ret.ok() ) {
219  result = PASSMSG( "bad params.", ret );
220  }
221  else {
222  irods::resource_ptr resc;
223  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
224  if ( !ret.ok() ) {
225  result = PASSMSG( "failed getting the first child resource pointer.", ret );
226  }
227  else {
228  ret = resc->call<void*, int>( _ctx.comm(), irods::RESOURCE_OP_WRITE, _ctx.fco(), _buf, _len );
229  result = PASSMSG( "passthru_file_write_plugin - failed calling child write.", ret );
230  }
231  }
232  return result;
233 } // passthru_file_write_plugin
234 
235 // =-=-=-=-=-=-=-
236 // interface for POSIX Close
238  irods::plugin_context& _ctx ) {
239  irods::error result = SUCCESS();
240  irods::error ret;
241 
242  ret = passthru_check_params( _ctx );
243  if ( !ret.ok() ) {
244  result = PASSMSG( "passthru_file_close_plugin - bad params.", ret );
245  }
246  else {
247  irods::resource_ptr resc;
248  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
249  if ( !ret.ok() ) {
250  result = PASSMSG( "passthru_file_close_plugin - failed getting the first child resource pointer.", ret );
251  }
252  else {
253  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_CLOSE, _ctx.fco() );
254  result = PASSMSG( "passthru_file_close_plugin - failed calling child close.", ret );
255  }
256  }
257  return result;
258 
259 } // passthru_file_close_plugin
260 
261 // =-=-=-=-=-=-=-
262 // interface for POSIX Unlink
264  irods::plugin_context& _ctx ) {
265  irods::error result = SUCCESS();
266  irods::error ret;
267 
268  ret = passthru_check_params( _ctx );
269  if ( !ret.ok() ) {
270  result = PASSMSG( "passthru_file_unlink_plugin - bad params.", ret );
271  }
272  else {
273  irods::resource_ptr resc;
274  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
275  if ( !ret.ok() ) {
276  result = PASSMSG( "passthru_file_unlink_plugin - failed getting the first child resource pointer.", ret );
277  }
278  else {
279  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_UNLINK, _ctx.fco() );
280  result = PASSMSG( "passthru_file_unlink_plugin - failed calling child unlink.", ret );
281  }
282  }
283  return result;
284 } // passthru_file_unlink_plugin
285 
286 // =-=-=-=-=-=-=-
287 // interface for POSIX Stat
289  irods::plugin_context& _ctx,
290  struct stat* _statbuf ) {
291  irods::error result = SUCCESS();
292  irods::error ret;
293 
294  ret = passthru_check_params( _ctx );
295  if ( !ret.ok() ) {
296  result = PASSMSG( "passthru_file_stat_plugin - bad params.", ret );
297  }
298  else {
299  irods::resource_ptr resc;
300  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
301  if ( !ret.ok() ) {
302  result = PASSMSG( "passthru_file_stat_plugin - failed getting the first child resource pointer.", ret );
303  }
304  else {
305  ret = resc->call<struct stat*>( _ctx.comm(), irods::RESOURCE_OP_STAT, _ctx.fco(), _statbuf );
306  result = PASSMSG( "passthru_file_stat_plugin - failed calling child stat.", ret );
307  }
308  }
309  return result;
310 } // passthru_file_stat_plugin
311 
312 // =-=-=-=-=-=-=-
313 // interface for POSIX lseek
315  irods::plugin_context& _ctx,
316  long long _offset,
317  int _whence ) {
318  irods::error result = SUCCESS();
319  irods::error ret;
320 
321  ret = passthru_check_params( _ctx );
322  if ( !ret.ok() ) {
323  result = PASSMSG( "passthru_file_lseek_plugin - bad params.", ret );
324  }
325  else {
326  irods::resource_ptr resc;
327  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
328  if ( !ret.ok() ) {
329  result = PASSMSG( "passthru_file_lseek_plugin - failed getting the first child resource pointer.", ret );
330  }
331  else {
332  ret = resc->call<long long, int>( _ctx.comm(), irods::RESOURCE_OP_LSEEK, _ctx.fco(), _offset, _whence );
333  result = PASSMSG( "passthru_file_lseek_plugin - failed calling child lseek.", ret );
334  }
335  }
336  return result;
337 } // passthru_file_lseek_plugin
338 
339 // =-=-=-=-=-=-=-
340 // interface for POSIX mkdir
342  irods::plugin_context& _ctx ) {
343  irods::error result = SUCCESS();
344  irods::error ret;
345 
346  ret = passthru_check_params( _ctx );
347  if ( !ret.ok() ) {
348  result = PASSMSG( "passthru_file_mkdir_plugin - bad params.", ret );
349  }
350  else {
351  irods::resource_ptr resc;
352  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
353  if ( !ret.ok() ) {
354  result = PASSMSG( "passthru_file_mkdir_plugin - failed getting the first child resource pointer.", ret );
355  }
356  else {
357  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_MKDIR, _ctx.fco() );
358  result = PASSMSG( "passthru_file_mkdir_plugin - failed calling child mkdir.", ret );
359  }
360  }
361  return result;
362 } // passthru_file_mkdir_plugin
363 
364 // =-=-=-=-=-=-=-
365 // interface for POSIX mkdir
367  irods::plugin_context& _ctx ) {
368  irods::error result = SUCCESS();
369  irods::error ret;
370 
371  ret = passthru_check_params( _ctx );
372  if ( !ret.ok() ) {
373  result = PASSMSG( "passthru_file_rmdir_plugin - bad params.", ret );
374  }
375  else {
376  irods::resource_ptr resc;
377  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
378  if ( !ret.ok() ) {
379  result = PASSMSG( "passthru_file_rmdir_plugin - failed getting the first child resource pointer.", ret );
380  }
381  else {
382  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_RMDIR, _ctx.fco() );
383  result = PASSMSG( "passthru_file_rmdir_plugin - failed calling child rmdir.", ret );
384  }
385  }
386  return result;
387 } // passthru_file_rmdir_plugin
388 
389 // =-=-=-=-=-=-=-
390 // interface for POSIX opendir
392  irods::plugin_context& _ctx ) {
393  irods::error result = SUCCESS();
394  irods::error ret;
395 
396  ret = passthru_check_params( _ctx );
397  if ( !ret.ok() ) {
398  result = PASSMSG( "passthru_file_opendir_plugin - bad params.", ret );
399  }
400  else {
401  irods::resource_ptr resc;
402  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
403  if ( !ret.ok() ) {
404  result = PASSMSG( "passthru_file_opendir_plugin - failed getting the first child resource pointer.", ret );
405  }
406  else {
407  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_OPENDIR, _ctx.fco() );
408  result = PASSMSG( "passthru_file_opendir_plugin - failed calling child opendir.", ret );
409  }
410  }
411  return result;
412 } // passthru_file_opendir_plugin
413 
414 // =-=-=-=-=-=-=-
415 // interface for POSIX closedir
417  irods::plugin_context& _ctx ) {
418  irods::error result = SUCCESS();
419  irods::error ret;
420 
421  ret = passthru_check_params( _ctx );
422  if ( !ret.ok() ) {
423  result = PASSMSG( "passthru_file_closedir_plugin - bad params.", ret );
424  }
425  else {
426  irods::resource_ptr resc;
427  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
428  if ( !ret.ok() ) {
429  result = PASSMSG( "passthru_file_closedir_plugin - failed getting the first child resource pointer.", ret );
430  }
431  else {
432  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_CLOSEDIR, _ctx.fco() );
433  result = PASSMSG( "passthru_file_closedir_plugin - failed calling child closedir.", ret );
434  }
435  }
436  return result;
437 } // passthru_file_closedir_plugin
438 
439 // =-=-=-=-=-=-=-
440 // interface for POSIX readdir
442  irods::plugin_context& _ctx,
443  struct rodsDirent** _dirent_ptr ) {
444  irods::error result = SUCCESS();
445  irods::error ret;
446 
447  ret = passthru_check_params( _ctx );
448  if ( !ret.ok() ) {
449  result = PASSMSG( "passthru_file_readdir_plugin - bad params.", ret );
450  }
451  else {
452  irods::resource_ptr resc;
453  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
454  if ( !ret.ok() ) {
455  result = PASSMSG( "passthru_file_readdir_plugin - failed getting the first child resource pointer.", ret );
456  }
457  else {
458  ret = resc->call<struct rodsDirent**>( _ctx.comm(), irods::RESOURCE_OP_READDIR, _ctx.fco(), _dirent_ptr );
459  result = PASSMSG( "passthru_file_readdir_plugin - failed calling child readdir.", ret );
460  }
461  }
462  return result;
463 } // passthru_file_readdir_plugin
464 
465 // =-=-=-=-=-=-=-
466 // interface for POSIX readdir
468  irods::plugin_context& _ctx,
469  const char* _new_file_name ) {
470  irods::error result = SUCCESS();
471  irods::error ret;
472 
473  ret = passthru_check_params( _ctx );
474  if ( !ret.ok() ) {
475  result = PASSMSG( "passthru_file_rename_plugin - bad params.", ret );
476  }
477  else {
478  irods::resource_ptr resc;
479  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
480  if ( !ret.ok() ) {
481  result = PASSMSG( "passthru_file_rename_plugin - failed getting the first child resource pointer.", ret );
482  }
483  else {
484  ret = resc->call<const char*>( _ctx.comm(), irods::RESOURCE_OP_RENAME, _ctx.fco(), _new_file_name );
485  result = PASSMSG( "passthru_file_rename_plugin - failed calling child rename.", ret );
486  }
487  }
488  return result;
489 } // passthru_file_rename_plugin
490 
491 // =-=-=-=-=-=-=-
492 // interface for POSIX truncate
494  irods::plugin_context& _ctx ) {
495  // =-=-=-=-=-=-=-
496  irods::error result = SUCCESS();
497  irods::error ret;
498 
499  ret = passthru_check_params( _ctx );
500  if ( !ret.ok() ) {
501  result = PASSMSG( "passthru_file_truncate_plugin - bad params.", ret );
502  }
503  else {
504  irods::resource_ptr resc;
505  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
506  if ( !ret.ok() ) {
507  result = PASSMSG( "passthru_file_truncate_plugin - failed getting the first child resource pointer.", ret );
508  }
509  else {
510  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_TRUNCATE, _ctx.fco() );
511  result = PASSMSG( "passthru_file_truncate_plugin - failed calling child truncate.", ret );
512  }
513  }
514  return result;
515 } // passthru_file_truncate_plugin
516 
517 // =-=-=-=-=-=-=-
518 // interface to determine free space on a device given a path
520  irods::plugin_context& _ctx ) {
521  irods::error result = SUCCESS();
522  irods::error ret;
523 
524  ret = passthru_check_params( _ctx );
525  if ( !ret.ok() ) {
526  result = PASSMSG( "passthru_file_getfs_freespace_plugin - bad params.", ret );
527  }
528  else {
529  irods::resource_ptr resc;
530  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
531  if ( !ret.ok() ) {
532  result = PASSMSG( "passthru_file_getfs_freespace_plugin - failed getting the first child resource pointer.", ret );
533  }
534  else {
535  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_FREESPACE, _ctx.fco() );
536  result = PASSMSG( "passthru_file_getfs_freespace_plugin - failed calling child freespace.", ret );
537  }
538  }
539  return result;
540 } // passthru_file_getfs_freespace
541 
542 // =-=-=-=-=-=-=-
543 // passthruStageToCache - This routine is for testing the TEST_STAGE_FILE_TYPE.
544 // Just copy the file from filename to cacheFilename. optionalInfo info
545 // is not used.
547  irods::plugin_context& _ctx,
548  const char* _cache_file_name ) {
549  irods::error result = SUCCESS();
550  irods::error ret;
551 
552  ret = passthru_check_params( _ctx );
553  if ( !ret.ok() ) {
554  result = PASSMSG( "passthru_stage_to_cache_plugin - bad params.", ret );
555  }
556  else {
557  irods::resource_ptr resc;
558  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
559  if ( !ret.ok() ) {
560  result = PASSMSG( "passthru_stage_to_cache_plugin - failed getting the first child resource pointer.", ret );
561  }
562  else {
563  ret = resc->call<const char*>( _ctx.comm(), irods::RESOURCE_OP_STAGETOCACHE, _ctx.fco(), _cache_file_name );
564  result = PASSMSG( "passthru_stage_to_cache_plugin - failed calling child stagetocache.", ret );
565  }
566  }
567  return result;
568 } // passthru_stage_to_cache_plugin
569 
570 // =-=-=-=-=-=-=-
571 // passthruSyncToArch - This routine is for testing the TEST_STAGE_FILE_TYPE.
572 // Just copy the file from cacheFilename to filename. optionalInfo info
573 // is not used.
575  irods::plugin_context& _ctx,
576  const char* _cache_file_name ) {
577  irods::error result = SUCCESS();
578  irods::error ret;
579 
580  ret = passthru_check_params( _ctx );
581  if ( !ret.ok() ) {
582  result = PASSMSG( "passthru_file_sync_to_arch_plugin - bad params.", ret );
583  }
584  else {
585  irods::resource_ptr resc;
586  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
587  if ( !ret.ok() ) {
588  result = PASSMSG( "passthru_file_sync_to_arch_plugin - failed getting the first child resource pointer.", ret );
589  }
590  else {
591  ret = resc->call<const char*>( _ctx.comm(), irods::RESOURCE_OP_SYNCTOARCH, _ctx.fco(), _cache_file_name );
592 
593  result = PASSMSG( "passthru_file_sync_to_arch_plugin - failed calling child synctoarch.", ret );
594  }
595  }
596  return result;
597 } // passthru_file_sync_to_arch_plugin
598 
602  irods::plugin_context& _ctx ) {
603  irods::error result = SUCCESS();
604  irods::error ret;
605 
606  ret = passthru_check_params( _ctx );
607  if ( !ret.ok() ) {
608  result = PASSMSG( "bad params.", ret );
609  }
610  else {
611  irods::resource_ptr resc;
612  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
613  if ( !ret.ok() ) {
614  result = PASSMSG( "failed getting the first child resource pointer.", ret );
615  }
616  else {
617  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_REGISTERED, _ctx.fco() );
618 
619  result = PASSMSG( "failed calling child registered.", ret );
620  }
621  }
622  return result;
623 } // passthru_file_registered
624 
628  irods::plugin_context& _ctx ) {
629  irods::error result = SUCCESS();
630  irods::error ret;
631 
632  ret = passthru_check_params( _ctx );
633  if ( !ret.ok() ) {
634  result = PASSMSG( "bad params.", ret );
635  }
636  else {
637  irods::resource_ptr resc;
638  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
639  if ( !ret.ok() ) {
640  result = PASSMSG( "failed getting the first child resource pointer.", ret );
641  }
642  else {
643  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_UNREGISTERED, _ctx.fco() );
644 
645  result = PASSMSG( "failed calling child unregistered.", ret );
646  }
647  }
648  return result;
649 } // passthru_file_unregistered
650 
654  irods::plugin_context& _ctx ) {
655  irods::error result = SUCCESS();
656  irods::error ret;
657 
658  ret = passthru_check_params( _ctx );
659  if ( !ret.ok() ) {
660  result = PASSMSG( "bad params.", ret );
661  }
662  else {
663  irods::resource_ptr resc;
664  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
665  if ( !ret.ok() ) {
666  result = PASSMSG( "failed getting the first child resource pointer.", ret );
667  }
668  else {
669  ret = resc->call( _ctx.comm(), irods::RESOURCE_OP_MODIFIED, _ctx.fco() );
670 
671  result = PASSMSG( "failed calling child modified.", ret );
672  }
673  }
674  return result;
675 } // passthru_file_modified
676 
678  irods::plugin_context& _ctx,
679  const std::string& _type,
680  double& _weight) {
681  _weight = 1.0;
682  std::string results = _ctx.rule_results();
683  if (!results.empty()) {
684 
685  std::vector< std::string > props;
686  irods::kvp_map_t kvp;
688  results,
689  kvp );
690 
691  // =-=-=-=-=-=-=-
692  // copy the properties from the context to the prop map
693  irods::kvp_map_t::iterator itr = kvp.begin();
694  for( ; itr != kvp.end(); ++itr ) {
695  if (itr->first == _type) {
696  irods::error ret = irods::lexical_cast<double>(itr->second, _weight);
697  if (!ret.ok()) {
698  irods::log(PASS(ret));
699  _weight = 1.0;
700  } else {
701  // Overriding the resource's context string settings
702  return SUCCESS();
703  }
704  }
705  } // for itr
706  }
707 
708  if ( _ctx.prop_map().has_entry( _type ) ) {
709  irods::error ret = _ctx.prop_map().get<double>(
710  _type,
711  _weight );
712  if ( !ret.ok() ) {
713  return PASS(ret);
714  }
715  }
716 
717  return SUCCESS();
718 }
719 
720 // =-=-=-=-=-=-=-
721 // unixRedirectPlugin - used to allow the resource to determine which host
722 // should provide the requested operation
724  irods::plugin_context& _ctx,
725  const std::string* _opr,
726  const std::string* _curr_host,
727  irods::hierarchy_parser* _out_parser,
728  float* _out_vote ) {
729  // =-=-=-=-=-=-=-
730  // check incoming parameters
731  irods::error result = SUCCESS();
732  irods::error ret = passthru_check_params( _ctx );
733  if ( !ret.ok() ) {
734  result = PASSMSG( "passthru_file_resolve_hierarchy - invalid resource context.", ret );
735  }
736  if ( !_opr ) {
737  return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_file_resolve_hierarchy - null operation" );
738  }
739  if ( !_curr_host ) {
740  return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_file_resolve_hierarchy - null operation" );
741  }
742  if ( !_out_parser ) {
743  return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_file_resolve_hierarchy - null outgoing hier parser" );
744  }
745  if ( !_out_vote ) {
746  return ERROR( SYS_INVALID_INPUT_PARAM, "passthru_file_resolve_hierarchy - null outgoing vote" );
747  }
748 
749  // =-=-=-=-=-=-=-
750  // get the name of this resource
751  std::string resc_name;
752  ret = _ctx.prop_map().get< std::string >( irods::RESOURCE_NAME, resc_name );
753  if ( !ret.ok() ) {
754  std::stringstream msg;
755  msg << "passthru_file_resolve_hierarchy - failed in get property for name";
756  return ERROR( -1, msg.str() );
757  }
758 
759  // =-=-=-=-=-=-=-
760  // add ourselves to the hierarchy parser by default
761  _out_parser->add_child( resc_name );
762 
763  irods::resource_ptr resc;
764  ret = passthru_get_first_child_resc( _ctx.prop_map(), resc );
765  if ( !ret.ok() ) {
766  return PASSMSG( "passthru_file_resolve_hierarchy - failed getting the first child resource pointer.", ret );
767  }
768 
769  irods::error final_ret = resc->call <
770  const std::string*,
771  const std::string*,
773  float* > (
774  _ctx.comm(),
776  _ctx.fco(),
777  _opr,
778  _curr_host,
779  _out_parser,
780  _out_vote );
781 
782  double orig_vote = *_out_vote;
783  if ( irods::OPEN_OPERATION == ( *_opr ) ) {
784  double read_weight = 1.0;
785  irods::error ret = capture_weight(_ctx, READ_WEIGHT_KW, read_weight);
786  if ( !ret.ok() ) {
787  irods::log( PASS( ret ) );
788  }
789  else {
790  ( *_out_vote ) *= read_weight;
791  }
792 
793  }
794  else if ( ( irods::CREATE_OPERATION == ( *_opr ) ||
795  irods::WRITE_OPERATION == ( *_opr ) ) ) {
796  double write_weight = 1.0;
797  irods::error ret = capture_weight(_ctx, WRITE_WEIGHT_KW, write_weight);
798  if ( !ret.ok() ) {
799  irods::log( PASS( ret ) );
800  }
801  else {
802  ( *_out_vote ) *= write_weight;
803  }
804  }
805 
806  rodsLog(
807  LOG_DEBUG,
808  "passthru_file_resolve_hierarchy - [%s] : %f - %f",
809  _opr->c_str(),
810  orig_vote,
811  *_out_vote );
812 
813  return final_ret;
814 
815 } // passthru_file_resolve_hierarchy
816 
817 // =-=-=-=-=-=-=-
818 // passthru_file_rebalance - code which would rebalance the subtree
820  irods::plugin_context& _ctx ) {
821  // =-=-=-=-=-=-=-
822  // forward request for rebalance to children
823  irods::resource_child_map* cmap_ref;
826  cmap_ref );
827 
828  irods::error result = SUCCESS();
829  irods::resource_child_map::iterator itr = cmap_ref->begin();
830  for ( ; itr != cmap_ref->end(); ++itr ) {
831  irods::error ret = itr->second.second->call(
832  _ctx.comm(),
834  _ctx.fco() );
835  if ( !ret.ok() ) {
836  irods::log( PASS( ret ) );
837  result = ret;
838  }
839  }
840 
841  if ( !result.ok() ) {
842  return PASS( result );
843  }
844 
845  return SUCCESS();
846 
847 } // passthru_file_rebalance
848 
849 // =-=-=-=-=-=-=-
850 // passthru_file_rebalance - code which would notify the subtree of a change
852  irods::plugin_context& _ctx,
853  const std::string* _opr ) {
854 
855  irods::resource_child_map* cmap_ref;
858  cmap_ref );
859 
860  // =-=-=-=-=-=-=-
861  // forward request for notify to children
862  irods::error result = SUCCESS();
863  irods::resource_child_map::iterator itr = cmap_ref->begin();
864  for ( ; itr != cmap_ref->end(); ++itr ) {
865  irods::error ret = itr->second.second->call(
866  _ctx.comm(),
868  _ctx.fco(),
869  _opr );
870  if ( !ret.ok() ) {
871  irods::log( PASS( ret ) );
872  result = ret;
873  }
874  }
875 
876  return result;
877 
878 } // passthru_file_notify
879 
880 
881 // =-=-=-=-=-=-=-
882 // 3. create derived class to handle passthru file system resources
883 // necessary to do custom parsing of the context string to place
884 // any useful values into the property map for reference in later
885 // operations. semicolon is the preferred delimiter
887  public:
889  const std::string& _inst_name,
890  const std::string& _context ) :
891  irods::resource(
892  _inst_name,
893  _context ) {
894  irods::kvp_map_t kvp_map;
895  if ( !_context.empty() ) {
897  _context,
898  kvp_map );
899  if ( !ret.ok() ) {
900  rodsLog(
901  LOG_ERROR,
902  "invalid context [%s] : %d",
903  _context.c_str(),
904  _context.size() );
905  return;
906  }
907 
908  if ( kvp_map.find( WRITE_WEIGHT_KW ) != kvp_map.end() ) {
909  try {
910  double write_weight = boost::lexical_cast< double >( kvp_map[ WRITE_WEIGHT_KW ] );
911  properties_.set< double >( WRITE_WEIGHT_KW, write_weight );
912  }
913  catch ( const boost::bad_lexical_cast& ) {
914  std::stringstream msg;
915  msg << "failed to cast weight for write ["
916  << kvp_map[ WRITE_WEIGHT_KW ]
917  << "]";
918  irods::log(
919  ERROR(
921  msg.str() ) );
922  }
923  }
924 
925  if ( kvp_map.find( READ_WEIGHT_KW ) != kvp_map.end() ) {
926  try {
927  double read_weight = boost::lexical_cast< double >( kvp_map[ READ_WEIGHT_KW ] );
928  properties_.set< double >( READ_WEIGHT_KW, read_weight );
929  }
930  catch ( const boost::bad_lexical_cast& ) {
931  std::stringstream msg;
932  msg << "failed to cast weight for read ["
933  << kvp_map[ READ_WEIGHT_KW ]
934  << "]";
935  irods::log(
936  ERROR(
938  msg.str() ) );
939  }
940  }
941 
942  } // if !empty
943 
944  } // ctor
945 
946 }; // class passthru_resource
947 
948 // =-=-=-=-=-=-=-
949 // 4. create the plugin factory function which will return a dynamically
950 // instantiated object of the previously defined derived resource. use
951 // the add_operation member to associate a 'call name' to the interfaces
952 // defined above. for resource plugins these call names are standardized
953 // as used by the irods facing interface defined in
954 // server/drivers/src/fileDriver.c
955 extern "C"
956 irods::resource* plugin_factory( const std::string& _inst_name, const std::string& _context ) {
957 
958  // =-=-=-=-=-=-=-
959  // 4a. create passthru_resource
960  passthru_resource* resc = new passthru_resource( _inst_name, _context );
961 
962  // =-=-=-=-=-=-=-
963  // 4b. map function names to operations. this map will be used to load
964  // the symbols from the shared object in the delay_load stage of
965  // plugin loading.
966  using namespace irods;
967  using namespace std;
968  resc->add_operation(
970  function<error(plugin_context&)>(
972 
973  resc->add_operation(
975  function<error(plugin_context&)>(
976  passthru_file_open ) );
977 
978  resc->add_operation<void*,int>(
980  std::function<
981  error(irods::plugin_context&,void*,int)>(
982  passthru_file_read ) );
983 
984  resc->add_operation<void*,int>(
986  function<error(plugin_context&,void*,int)>(
988 
989  resc->add_operation(
991  function<error(plugin_context&)>(
993 
994  resc->add_operation(
996  function<error(plugin_context&)>(
998 
999  resc->add_operation<struct stat*>(
1001  function<error(plugin_context&, struct stat*)>(
1002  passthru_file_stat ) );
1003 
1004  resc->add_operation(
1006  function<error(plugin_context&)>(
1007  passthru_file_mkdir ) );
1008 
1009  resc->add_operation(
1011  function<error(plugin_context&)>(
1013 
1014  resc->add_operation<struct rodsDirent**>(
1016  function<error(plugin_context&,struct rodsDirent**)>(
1018 
1019  resc->add_operation<const char*>(
1021  function<error(plugin_context&, const char*)>(
1023 
1024  resc->add_operation(
1026  function<error(plugin_context&)>(
1028 
1029  resc->add_operation<long long, int>(
1031  function<error(plugin_context&, long long, int)>(
1032  passthru_file_lseek ) );
1033 
1034  resc->add_operation(
1036  function<error(plugin_context&)>(
1037  passthru_file_rmdir ) );
1038 
1039  resc->add_operation(
1041  function<error(plugin_context&)>(
1043 
1044  resc->add_operation<const char*>(
1046  function<error(plugin_context&, const char*)>(
1048 
1049  resc->add_operation<const char*>(
1051  function<error(plugin_context&, const char*)>(
1053 
1054  resc->add_operation(
1056  function<error(plugin_context&)>(
1058 
1059  resc->add_operation(
1061  function<error(plugin_context&)>(
1063 
1064  resc->add_operation(
1066  function<error(plugin_context&)>(
1068 
1069  resc->add_operation<const std::string*>(
1071  function<error(plugin_context&, const std::string*)>(
1073 
1074  resc->add_operation(
1076  function<error(plugin_context&)>(
1078 
1079  resc->add_operation<const std::string*, const std::string*, irods::hierarchy_parser*, float*>(
1081  function<error(plugin_context&,const std::string*, const std::string*, irods::hierarchy_parser*, float*)>(
1083 
1084  resc->add_operation(
1086  function<error(plugin_context&)>(
1088 
1089  // =-=-=-=-=-=-=-
1090  // set some properties necessary for backporting to iRODS legacy code
1091  resc->set_property< int >( irods::RESOURCE_CHECK_PATH_PERM, 2 );//DO_CHK_PATH_PERM );
1092  resc->set_property< int >( irods::RESOURCE_CREATE_PATH, 1 );//CREATE_PATH );
1093 
1094  // =-=-=-=-=-=-=-
1095  // 4c. return the pointer through the generic interface of an
1096  // irods::resource pointer
1097  return dynamic_cast<irods::resource*>( resc );
1098 
1099 } // plugin_factory
1100 
1101 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods::lookup_table< boost::any >
irods::RESOURCE_NAME
const std::string RESOURCE_NAME("resource_property_name")
irods::RESOURCE_OP_STAT
const std::string RESOURCE_OP_STAT("resource_stat")
passthru_file_unregistered
irods::error passthru_file_unregistered(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:627
msParam.h
irods::plugin_context::valid
virtual error valid()
Definition: irods_plugin_context.hpp:77
irods::resource
Definition: irods_resource_plugin.hpp:25
irods::RESOURCE_CHECK_PATH_PERM
const std::string RESOURCE_CHECK_PATH_PERM("resource_property_check_path_perm")
irods::RESOURCE_OP_MODIFIED
const std::string RESOURCE_OP_MODIFIED("resource_modified")
passthru_file_rebalance
irods::error passthru_file_rebalance(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:819
irods_file_object.hpp
irods::RESOURCE_OP_CLOSEDIR
const std::string RESOURCE_OP_CLOSEDIR("resource_closedir")
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
irods_collection_object.hpp
irods::resource_ptr
boost::shared_ptr< resource > resource_ptr
Definition: irods_resource_types.hpp:11
passthru_file_sync_to_arch
irods::error passthru_file_sync_to_arch(irods::plugin_context &_ctx, const char *_cache_file_name)
Definition: libpassthru.cpp:574
irods::RESOURCE_OP_RESOLVE_RESC_HIER
const std::string RESOURCE_OP_RESOLVE_RESC_HIER("resource_resolve_hierarchy")
irods::RESOURCE_OP_READDIR
const std::string RESOURCE_OP_READDIR("resource_readdir")
irods::hierarchy_parser
Definition: irods_hierarchy_parser.hpp:14
passthru_file_create
irods::error passthru_file_create(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:132
irods::lookup_table::begin
iterator begin()
Definition: irods_lookup_table.hpp:53
irods::RESOURCE_OP_READ
const std::string RESOURCE_OP_READ("resource_read")
irods::RESOURCE_OP_FREESPACE
const std::string RESOURCE_OP_FREESPACE("resource_freespace")
irods::lookup_table< std::pair< std::string, resource_ptr > >::iterator
irods_hash_map::iterator iterator
Definition: irods_lookup_table.hpp:31
passthru_file_closedir
irods::error passthru_file_closedir(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:416
passthru_file_rmdir
irods::error passthru_file_rmdir(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:366
irods::RESOURCE_OP_LSEEK
const std::string RESOURCE_OP_LSEEK("resource_lseek")
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
passthru_file_modified
irods::error passthru_file_modified(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:653
irods::plugin_context
Definition: irods_plugin_context.hpp:18
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
irods::lookup_table::get
error get(const std::string &_key, ValueType &_val)
Definition: irods_lookup_table.hpp:71
irods_resource_redirect.hpp
irods::resource::resource
resource(const std::string &_inst, const std::string &_ctx)
Definition: irods_resource_plugin.hpp:29
irods::plugin_base::set_property
error set_property(const std::string &_key, const T &_val)
Definition: irods_plugin_base.hpp:304
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
passthru_file_unlink
irods::error passthru_file_unlink(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:263
passthru_file_readdir
irods::error passthru_file_readdir(irods::plugin_context &_ctx, struct rodsDirent **_dirent_ptr)
Definition: libpassthru.cpp:441
irods::lookup_table::size
int size() const
Definition: irods_lookup_table.hpp:38
irods_resource_plugin.hpp
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::plugin_context::comm
virtual rsComm_t * comm()
Definition: irods_plugin_context.hpp:95
irods::RESOURCE_OP_TRUNCATE
const std::string RESOURCE_OP_TRUNCATE("resource_truncate")
irods_string_tokenize.hpp
irods::RESOURCE_OP_RENAME
const std::string RESOURCE_OP_RENAME("resource_rename")
irods::OPEN_OPERATION
const std::string OPEN_OPERATION("OPEN")
passthru_file_write
irods::error passthru_file_write(irods::plugin_context &_ctx, void *_buf, int _len)
Definition: libpassthru.cpp:210
passthru_resource::passthru_resource
passthru_resource(const std::string &_inst_name, const std::string &_context)
Definition: libpassthru.cpp:888
passthru_file_read
irods::error passthru_file_read(irods::plugin_context &_ctx, void *_buf, int _len)
Definition: libpassthru.cpp:183
irods.pypyodbc.long
long
Definition: pypyodbc.py:43
passthru_file_stage_to_cache
irods::error passthru_file_stage_to_cache(irods::plugin_context &_ctx, const char *_cache_file_name)
Definition: libpassthru.cpp:546
irods::plugin_context::prop_map
virtual irods::plugin_property_map & prop_map()
Definition: irods_plugin_context.hpp:99
passthru_file_notify
irods::error passthru_file_notify(irods::plugin_context &_ctx, const std::string *_opr)
Definition: libpassthru.cpp:851
passthru_resource
Definition: libpassthru.cpp:886
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
irods::plugin_base::properties_
plugin_property_map properties_
Definition: irods_plugin_base.hpp:332
irods::hierarchy_parser::add_child
error add_child(const std::string &_resc)
Definition: irods_hierarchy_parser.cpp:88
passthru_file_opendir
irods::error passthru_file_opendir(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:391
irods::RESOURCE_OP_CREATE
const std::string RESOURCE_OP_CREATE("resource_create")
irods
Definition: apiHandler.hpp:35
irods::RESOURCE_OP_NOTIFY
const std::string RESOURCE_OP_NOTIFY("resource_notify")
capture_weight
static irods::error capture_weight(irods::plugin_context &_ctx, const std::string &_type, double &_weight)
Definition: libpassthru.cpp:677
irods::RESOURCE_CREATE_PATH
const std::string RESOURCE_CREATE_PATH("resource_property_create_path")
irods::RESOURCE_OP_WRITE
const std::string RESOURCE_OP_WRITE("resource_write")
passthru_file_open
irods::error passthru_file_open(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:158
irods::lookup_table::has_entry
bool has_entry(KeyType _k) const
Definition: irods_lookup_table.hpp:41
irods::RESOURCE_OP_CLOSE
const std::string RESOURCE_OP_CLOSE("resource_close")
passthru_file_close
irods::error passthru_file_close(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:237
passthru_file_mkdir
irods::error passthru_file_mkdir(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:341
irods::log
void log(const error &)
Definition: irods_log.cpp:13
irods::RESC_CHILD_MAP_PROP
const std::string RESC_CHILD_MAP_PROP("resource_child_map_property")
rodsDirent
Definition: rodsType.h:70
READ_WEIGHT_KW
const std::string READ_WEIGHT_KW("read")
irods::RESOURCE_OP_UNLINK
const std::string RESOURCE_OP_UNLINK("resource_unlink")
irods::RESOURCE_OP_RMDIR
const std::string RESOURCE_OP_RMDIR("resource_rmdir")
irods::lookup_table::end
iterator end()
Definition: irods_lookup_table.hpp:56
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::RESOURCE_OP_UNREGISTERED
const std::string RESOURCE_OP_UNREGISTERED("resource_unregistered")
irods::error
Definition: irods_error.hpp:23
passthru_check_params
irods::error passthru_check_params(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:115
run_tests.results
def results
Definition: run_tests.py:154
miscServerFunct.hpp
irods_lexical_cast.hpp
plugin_factory
irods::resource * plugin_factory(const std::string &_inst_name, const std::string &_context)
Definition: libpassthru.cpp:956
irods::RESOURCE_OP_REGISTERED
const std::string RESOURCE_OP_REGISTERED("resource_registered")
irods_hierarchy_parser.hpp
irods::parse_kvp_string
error parse_kvp_string(const std::string &_str, kvp_map_t &_kvp, const std::string &_association=KVP_DEF_ASSOCIATION, const std::string &_delimeter=KVP_DEF_DELIMITER)
Definition: irods_kvp_string_parser.cpp:69
passthru_file_rename
irods::error passthru_file_rename(irods::plugin_context &_ctx, const char *_new_file_name)
Definition: libpassthru.cpp:467
passthru_file_resolve_hierarchy
irods::error passthru_file_resolve_hierarchy(irods::plugin_context &_ctx, const std::string *_opr, const std::string *_curr_host, irods::hierarchy_parser *_out_parser, float *_out_vote)
Definition: libpassthru.cpp:723
passthru_get_first_child_resc
irods::error passthru_get_first_child_resc(irods::plugin_property_map &_props, irods::resource_ptr &_resc)
Definition: libpassthru.cpp:89
irods::RESOURCE_OP_MKDIR
const std::string RESOURCE_OP_MKDIR("resource_mkdir")
WRITE_WEIGHT_KW
const std::string WRITE_WEIGHT_KW("write")
irods::plugin_context::rule_results
virtual const std::string rule_results()
Definition: irods_plugin_context.hpp:105
irods::RESOURCE_OP_OPENDIR
const std::string RESOURCE_OP_OPENDIR("resource_opendir")
irods::RESOURCE_OP_STAGETOCACHE
const std::string RESOURCE_OP_STAGETOCACHE("resource_stagetocache")
error
int error
Definition: filesystem.cpp:101
irods::WRITE_OPERATION
const std::string WRITE_OPERATION("WRITE")
irods::plugin_base::add_operation
error add_operation(const std::string &_op, std::function< error(plugin_context &)> _f)
Definition: irods_plugin_base.hpp:122
irods::plugin_context::fco
virtual first_class_object_ptr fco()
Definition: irods_plugin_context.hpp:102
irods::RESOURCE_OP_SYNCTOARCH
const std::string RESOURCE_OP_SYNCTOARCH("resource_synctoarch")
passthru_file_stat
irods::error passthru_file_stat(irods::plugin_context &_ctx, struct stat *_statbuf)
Definition: libpassthru.cpp:288
irods_kvp_string_parser.hpp
irods_error.hpp
passthru_file_registered
irods::error passthru_file_registered(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:601
irods::RESOURCE_OP_REBALANCE
const std::string RESOURCE_OP_REBALANCE("resource_rebalance")
irods::lookup_table::set
error set(const std::string &_key, const ValueType &_val)
Definition: irods_lookup_table.hpp:83
irods::kvp_map_t
std::map< std::string, std::string > kvp_map_t
Definition: irods_kvp_string_parser.hpp:30
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::RESOURCE_OP_OPEN
const std::string RESOURCE_OP_OPEN("resource_open")
irods::CREATE_OPERATION
const std::string CREATE_OPERATION("CREATE")
passthru_file_truncate
irods::error passthru_file_truncate(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:493
passthru_file_getfs_freespace
irods::error passthru_file_getfs_freespace(irods::plugin_context &_ctx)
Definition: libpassthru.cpp:519
passthru_file_lseek
irods::error passthru_file_lseek(irods::plugin_context &_ctx, long long _offset, int _whence)
Definition: libpassthru.cpp:314