@@ -622,125 +622,176 @@ func (r *result) adjustHooks(hooks *Hooks, plugin string) error {
622622	return  nil 
623623}
624624
625- func  (r  * result ) adjustResources ( resources   * LinuxResources , plugin  string ) error  {
626- 	if  resources  ==  nil  {
625+ func  (r  * result ) adjustMemoryResource ( mem ,  targetContainer ,  targetReply   * LinuxMemory ,  id , plugin  string ) error  {
626+ 	if  mem  ==  nil  {
627627		return  nil 
628628	}
629629
630- 	create , id  :=  r .request .create , r .request .create .Container .Id 
631- 	container  :=  create .Container .Linux .Resources 
632- 	reply  :=  r .reply .adjust .Linux .Resources 
633- 
634- 	if  mem  :=  resources .Memory ; mem  !=  nil  {
635- 		if  v  :=  mem .GetLimit (); v  !=  nil  {
636- 			if  err  :=  r .owners .ClaimMemLimit (id , plugin ); err  !=  nil  {
637- 				return  err 
638- 			}
639- 			container .Memory .Limit  =  Int64 (v .GetValue ())
640- 			reply .Memory .Limit  =  Int64 (v .GetValue ())
630+ 	if  v  :=  mem .GetLimit (); v  !=  nil  {
631+ 		if  err  :=  r .owners .ClaimMemLimit (id , plugin ); err  !=  nil  {
632+ 			return  err 
641633		}
642- 		if  v  :=  mem .GetReservation (); v  !=  nil  {
643- 			if  err  :=  r .owners .ClaimMemReservation (id , plugin ); err  !=  nil  {
644- 				return  err 
645- 			}
646- 			container .Memory .Reservation  =  Int64 (v .GetValue ())
647- 			reply .Memory .Reservation  =  Int64 (v .GetValue ())
634+ 		targetContainer .Limit  =  Int64 (v .GetValue ())
635+ 		if  targetReply  !=  nil  {
636+ 			targetReply .Limit  =  Int64 (v .GetValue ())
648637		}
649- 		if  v  :=  mem .GetSwap (); v  !=  nil  {
650- 			if  err  :=  r .owners .ClaimMemSwapLimit (id , plugin ); err  !=  nil  {
651- 				return  err 
652- 			}
653- 			container .Memory .Swap  =  Int64 (v .GetValue ())
654- 			reply .Memory .Swap  =  Int64 (v .GetValue ())
638+ 	}
639+ 	if  v  :=  mem .GetReservation (); v  !=  nil  {
640+ 		if  err  :=  r .owners .ClaimMemReservation (id , plugin ); err  !=  nil  {
641+ 			return  err 
655642		}
656- 		if  v  :=  mem .GetKernel (); v  !=  nil  {
657- 			if  err  :=  r .owners .ClaimMemKernelLimit (id , plugin ); err  !=  nil  {
658- 				return  err 
659- 			}
660- 			container .Memory .Kernel  =  Int64 (v .GetValue ())
661- 			reply .Memory .Kernel  =  Int64 (v .GetValue ())
643+ 		targetContainer .Reservation  =  Int64 (v .GetValue ())
644+ 		if  targetReply  !=  nil  {
645+ 			targetReply .Reservation  =  Int64 (v .GetValue ())
662646		}
663- 		if  v  :=  mem .GetKernelTcp (); v  !=  nil  {
664- 			if  err  :=  r .owners .ClaimMemTCPLimit (id , plugin ); err  !=  nil  {
665- 				return  err 
666- 			}
667- 			container .Memory .KernelTcp  =  Int64 (v .GetValue ())
668- 			reply .Memory .KernelTcp  =  Int64 (v .GetValue ())
647+ 	}
648+ 	if  v  :=  mem .GetSwap (); v  !=  nil  {
649+ 		if  err  :=  r .owners .ClaimMemSwapLimit (id , plugin ); err  !=  nil  {
650+ 			return  err 
669651		}
670- 		if  v  :=  mem .GetSwappiness (); v  !=  nil  {
671- 			if  err  :=  r .owners .ClaimMemSwappiness (id , plugin ); err  !=  nil  {
672- 				return  err 
673- 			}
674- 			container .Memory .Swappiness  =  UInt64 (v .GetValue ())
675- 			reply .Memory .Swappiness  =  UInt64 (v .GetValue ())
652+ 		targetContainer .Swap  =  Int64 (v .GetValue ())
653+ 		if  targetReply  !=  nil  {
654+ 			targetReply .Swap  =  Int64 (v .GetValue ())
676655		}
677- 		if  v  :=  mem .GetDisableOomKiller (); v  !=  nil  {
678- 			if  err  :=  r .owners .ClaimMemDisableOomKiller (id , plugin ); err  !=  nil  {
679- 				return  err 
680- 			}
681- 			container .Memory .DisableOomKiller  =  Bool (v .GetValue ())
682- 			reply .Memory .DisableOomKiller  =  Bool (v .GetValue ())
656+ 	}
657+ 	if  v  :=  mem .GetKernel (); v  !=  nil  {
658+ 		if  err  :=  r .owners .ClaimMemKernelLimit (id , plugin ); err  !=  nil  {
659+ 			return  err 
683660		}
684- 		if  v  :=  mem .GetUseHierarchy (); v  !=  nil  {
685- 			if  err  :=  r .owners .ClaimMemUseHierarchy (id , plugin ); err  !=  nil  {
686- 				return  err 
687- 			}
688- 			container .Memory .UseHierarchy  =  Bool (v .GetValue ())
689- 			reply .Memory .UseHierarchy  =  Bool (v .GetValue ())
661+ 		targetContainer .Kernel  =  Int64 (v .GetValue ())
662+ 		if  targetReply  !=  nil  {
663+ 			targetReply .Kernel  =  Int64 (v .GetValue ())
690664		}
691665	}
692- 	if  cpu  :=  resources .Cpu ; cpu  !=  nil  {
693- 		if  v  :=  cpu .GetShares (); v  !=  nil  {
694- 			if  err  :=  r .owners .ClaimCPUShares (id , plugin ); err  !=  nil  {
695- 				return  err 
696- 			}
697- 			container .Cpu .Shares  =  UInt64 (v .GetValue ())
698- 			reply .Cpu .Shares  =  UInt64 (v .GetValue ())
666+ 	if  v  :=  mem .GetKernelTcp (); v  !=  nil  {
667+ 		if  err  :=  r .owners .ClaimMemTCPLimit (id , plugin ); err  !=  nil  {
668+ 			return  err 
699669		}
700- 		if  v  :=  cpu .GetQuota (); v  !=  nil  {
701- 			if  err  :=  r .owners .ClaimCPUQuota (id , plugin ); err  !=  nil  {
702- 				return  err 
703- 			}
704- 			container .Cpu .Quota  =  Int64 (v .GetValue ())
705- 			reply .Cpu .Quota  =  Int64 (v .GetValue ())
670+ 		targetContainer .KernelTcp  =  Int64 (v .GetValue ())
671+ 		if  targetReply  !=  nil  {
672+ 			targetReply .KernelTcp  =  Int64 (v .GetValue ())
706673		}
707- 		if  v  :=  cpu .GetPeriod (); v  !=  nil  {
708- 			if  err  :=  r .owners .ClaimCPUPeriod (id , plugin ); err  !=  nil  {
709- 				return  err 
710- 			}
711- 			container .Cpu .Period  =  UInt64 (v .GetValue ())
712- 			reply .Cpu .Period  =  UInt64 (v .GetValue ())
674+ 	}
675+ 	if  v  :=  mem .GetSwappiness (); v  !=  nil  {
676+ 		if  err  :=  r .owners .ClaimMemSwappiness (id , plugin ); err  !=  nil  {
677+ 			return  err 
713678		}
714- 		if  v  :=  cpu .GetRealtimeRuntime (); v  !=  nil  {
715- 			if  err  :=  r .owners .ClaimCPURealtimeRuntime (id , plugin ); err  !=  nil  {
716- 				return  err 
717- 			}
718- 			container .Cpu .RealtimeRuntime  =  Int64 (v .GetValue ())
719- 			reply .Cpu .RealtimeRuntime  =  Int64 (v .GetValue ())
679+ 		targetContainer .Swappiness  =  UInt64 (v .GetValue ())
680+ 		if  targetReply  !=  nil  {
681+ 			targetReply .Swappiness  =  UInt64 (v .GetValue ())
720682		}
721- 		if  v  :=  cpu .GetRealtimePeriod (); v  !=  nil  {
722- 			if  err  :=  r .owners .ClaimCPURealtimePeriod (id , plugin ); err  !=  nil  {
723- 				return  err 
724- 			}
725- 			container .Cpu .RealtimePeriod  =  UInt64 (v .GetValue ())
726- 			reply .Cpu .RealtimePeriod  =  UInt64 (v .GetValue ())
683+ 	}
684+ 	if  v  :=  mem .GetDisableOomKiller (); v  !=  nil  {
685+ 		if  err  :=  r .owners .ClaimMemDisableOomKiller (id , plugin ); err  !=  nil  {
686+ 			return  err 
727687		}
728- 		if  v  :=  cpu .GetCpus (); v  !=  ""  {
729- 			if  err  :=  r .owners .ClaimCPUSetCPUs (id , plugin ); err  !=  nil  {
730- 				return  err 
731- 			}
732- 			container .Cpu .Cpus  =  v 
733- 			reply .Cpu .Cpus  =  v 
688+ 		targetContainer .DisableOomKiller  =  Bool (v .GetValue ())
689+ 		if  targetReply  !=  nil  {
690+ 			targetReply .DisableOomKiller  =  Bool (v .GetValue ())
734691		}
735- 		if  v  :=  cpu .GetMems (); v  !=  ""  {
736- 			if  err  :=  r .owners .ClaimCPUSetMems (id , plugin ); err  !=  nil  {
737- 				return  err 
738- 			}
739- 			container .Cpu .Mems  =  v 
740- 			reply .Cpu .Mems  =  v 
692+ 	}
693+ 	if  v  :=  mem .GetUseHierarchy (); v  !=  nil  {
694+ 		if  err  :=  r .owners .ClaimMemUseHierarchy (id , plugin ); err  !=  nil  {
695+ 			return  err 
696+ 		}
697+ 		targetContainer .UseHierarchy  =  Bool (v .GetValue ())
698+ 		if  targetReply  !=  nil  {
699+ 			targetReply .UseHierarchy  =  Bool (v .GetValue ())
700+ 		}
701+ 	}
702+ 
703+ 	return  nil 
704+ }
705+ 
706+ func  (r  * result ) adjustCPUResource (cpu , targetContainer , targetReply  * LinuxCPU , id , plugin  string ) error  {
707+ 	if  cpu  ==  nil  {
708+ 		return  nil 
709+ 	}
710+ 
711+ 	if  v  :=  cpu .GetShares (); v  !=  nil  {
712+ 		if  err  :=  r .owners .ClaimCPUShares (id , plugin ); err  !=  nil  {
713+ 			return  err 
714+ 		}
715+ 		targetContainer .Shares  =  UInt64 (v .GetValue ())
716+ 		if  targetReply  !=  nil  {
717+ 			targetReply .Shares  =  UInt64 (v .GetValue ())
718+ 		}
719+ 	}
720+ 	if  v  :=  cpu .GetQuota (); v  !=  nil  {
721+ 		if  err  :=  r .owners .ClaimCPUQuota (id , plugin ); err  !=  nil  {
722+ 			return  err 
723+ 		}
724+ 		targetContainer .Quota  =  Int64 (v .GetValue ())
725+ 		if  targetReply  !=  nil  {
726+ 			targetReply .Quota  =  Int64 (v .GetValue ())
727+ 		}
728+ 	}
729+ 	if  v  :=  cpu .GetPeriod (); v  !=  nil  {
730+ 		if  err  :=  r .owners .ClaimCPUPeriod (id , plugin ); err  !=  nil  {
731+ 			return  err 
732+ 		}
733+ 		targetContainer .Period  =  UInt64 (v .GetValue ())
734+ 		if  targetReply  !=  nil  {
735+ 			targetReply .Period  =  UInt64 (v .GetValue ())
736+ 		}
737+ 	}
738+ 	if  v  :=  cpu .GetRealtimeRuntime (); v  !=  nil  {
739+ 		if  err  :=  r .owners .ClaimCPURealtimeRuntime (id , plugin ); err  !=  nil  {
740+ 			return  err 
741+ 		}
742+ 		targetContainer .RealtimeRuntime  =  Int64 (v .GetValue ())
743+ 		if  targetReply  !=  nil  {
744+ 			targetReply .RealtimeRuntime  =  Int64 (v .GetValue ())
745+ 		}
746+ 	}
747+ 	if  v  :=  cpu .GetRealtimePeriod (); v  !=  nil  {
748+ 		if  err  :=  r .owners .ClaimCPURealtimePeriod (id , plugin ); err  !=  nil  {
749+ 			return  err 
750+ 		}
751+ 		targetContainer .RealtimePeriod  =  UInt64 (v .GetValue ())
752+ 		if  targetReply  !=  nil  {
753+ 			targetReply .RealtimePeriod  =  UInt64 (v .GetValue ())
754+ 		}
755+ 	}
756+ 	if  v  :=  cpu .GetCpus (); v  !=  ""  {
757+ 		if  err  :=  r .owners .ClaimCPUSetCPUs (id , plugin ); err  !=  nil  {
758+ 			return  err 
759+ 		}
760+ 		targetContainer .Cpus  =  v 
761+ 		if  targetReply  !=  nil  {
762+ 			targetReply .Cpus  =  v 
763+ 		}
764+ 	}
765+ 	if  v  :=  cpu .GetMems (); v  !=  ""  {
766+ 		if  err  :=  r .owners .ClaimCPUSetMems (id , plugin ); err  !=  nil  {
767+ 			return  err 
768+ 		}
769+ 		targetContainer .Mems  =  v 
770+ 		if  targetReply  !=  nil  {
771+ 			targetReply .Mems  =  v 
741772		}
742773	}
743774
775+ 	return  nil 
776+ }
777+ 
778+ func  (r  * result ) adjustResources (resources  * LinuxResources , plugin  string ) error  {
779+ 	if  resources  ==  nil  {
780+ 		return  nil 
781+ 	}
782+ 
783+ 	create , id  :=  r .request .create , r .request .create .Container .Id 
784+ 	container  :=  create .Container .Linux .Resources 
785+ 	reply  :=  r .reply .adjust .Linux .Resources 
786+ 
787+ 	if  err  :=  r .adjustMemoryResource (resources .Memory , container .Memory , reply .Memory , id , plugin ); err  !=  nil  {
788+ 		return  err 
789+ 	}
790+ 
791+ 	if  err  :=  r .adjustCPUResource (resources .Cpu , container .Cpu , reply .Cpu , id , plugin ); err  !=  nil  {
792+ 		return  err 
793+ 	}
794+ 
744795	for  _ , l  :=  range  resources .HugepageLimits  {
745796		if  err  :=  r .owners .ClaimHugepageLimit (id , l .PageSize , plugin ); err  !=  nil  {
746797			return  err 
@@ -886,99 +937,12 @@ func (r *result) updateResources(reply, u *ContainerUpdate, plugin string) error
886937		resources  =  reply .Linux .Resources .Copy ()
887938	}
888939
889- 	if  mem  :=  u .Linux .Resources .Memory ; mem  !=  nil  {
890- 		if  v  :=  mem .GetLimit (); v  !=  nil  {
891- 			if  err  :=  r .owners .ClaimMemLimit (id , plugin ); err  !=  nil  {
892- 				return  err 
893- 			}
894- 			resources .Memory .Limit  =  Int64 (v .GetValue ())
895- 		}
896- 		if  v  :=  mem .GetReservation (); v  !=  nil  {
897- 			if  err  :=  r .owners .ClaimMemReservation (id , plugin ); err  !=  nil  {
898- 				return  err 
899- 			}
900- 			resources .Memory .Reservation  =  Int64 (v .GetValue ())
901- 		}
902- 		if  v  :=  mem .GetSwap (); v  !=  nil  {
903- 			if  err  :=  r .owners .ClaimMemSwapLimit (id , plugin ); err  !=  nil  {
904- 				return  err 
905- 			}
906- 			resources .Memory .Swap  =  Int64 (v .GetValue ())
907- 		}
908- 		if  v  :=  mem .GetKernel (); v  !=  nil  {
909- 			if  err  :=  r .owners .ClaimMemKernelLimit (id , plugin ); err  !=  nil  {
910- 				return  err 
911- 			}
912- 			resources .Memory .Kernel  =  Int64 (v .GetValue ())
913- 		}
914- 		if  v  :=  mem .GetKernelTcp (); v  !=  nil  {
915- 			if  err  :=  r .owners .ClaimMemTCPLimit (id , plugin ); err  !=  nil  {
916- 				return  err 
917- 			}
918- 			resources .Memory .KernelTcp  =  Int64 (v .GetValue ())
919- 		}
920- 		if  v  :=  mem .GetSwappiness (); v  !=  nil  {
921- 			if  err  :=  r .owners .ClaimMemSwappiness (id , plugin ); err  !=  nil  {
922- 				return  err 
923- 			}
924- 			resources .Memory .Swappiness  =  UInt64 (v .GetValue ())
925- 		}
926- 		if  v  :=  mem .GetDisableOomKiller (); v  !=  nil  {
927- 			if  err  :=  r .owners .ClaimMemDisableOomKiller (id , plugin ); err  !=  nil  {
928- 				return  err 
929- 			}
930- 			resources .Memory .DisableOomKiller  =  Bool (v .GetValue ())
931- 		}
932- 		if  v  :=  mem .GetUseHierarchy (); v  !=  nil  {
933- 			if  err  :=  r .owners .ClaimMemUseHierarchy (id , plugin ); err  !=  nil  {
934- 				return  err 
935- 			}
936- 			resources .Memory .UseHierarchy  =  Bool (v .GetValue ())
937- 		}
940+ 	if  err  :=  r .adjustMemoryResource (u .Linux .Resources .Memory , resources .Memory , nil , id , plugin ); err  !=  nil  {
941+ 		return  err 
938942	}
939- 	if  cpu  :=  u .Linux .Resources .Cpu ; cpu  !=  nil  {
940- 		if  v  :=  cpu .GetShares (); v  !=  nil  {
941- 			if  err  :=  r .owners .ClaimCPUShares (id , plugin ); err  !=  nil  {
942- 				return  err 
943- 			}
944- 			resources .Cpu .Shares  =  UInt64 (v .GetValue ())
945- 		}
946- 		if  v  :=  cpu .GetQuota (); v  !=  nil  {
947- 			if  err  :=  r .owners .ClaimCPUQuota (id , plugin ); err  !=  nil  {
948- 				return  err 
949- 			}
950- 			resources .Cpu .Quota  =  Int64 (v .GetValue ())
951- 		}
952- 		if  v  :=  cpu .GetPeriod (); v  !=  nil  {
953- 			if  err  :=  r .owners .ClaimCPUPeriod (id , plugin ); err  !=  nil  {
954- 				return  err 
955- 			}
956- 			resources .Cpu .Period  =  UInt64 (v .GetValue ())
957- 		}
958- 		if  v  :=  cpu .GetRealtimeRuntime (); v  !=  nil  {
959- 			if  err  :=  r .owners .ClaimCPURealtimeRuntime (id , plugin ); err  !=  nil  {
960- 				return  err 
961- 			}
962- 			resources .Cpu .RealtimeRuntime  =  Int64 (v .GetValue ())
963- 		}
964- 		if  v  :=  cpu .GetRealtimePeriod (); v  !=  nil  {
965- 			if  err  :=  r .owners .ClaimCPURealtimePeriod (id , plugin ); err  !=  nil  {
966- 				return  err 
967- 			}
968- 			resources .Cpu .RealtimePeriod  =  UInt64 (v .GetValue ())
969- 		}
970- 		if  v  :=  cpu .GetCpus (); v  !=  ""  {
971- 			if  err  :=  r .owners .ClaimCPUSetCPUs (id , plugin ); err  !=  nil  {
972- 				return  err 
973- 			}
974- 			resources .Cpu .Cpus  =  v 
975- 		}
976- 		if  v  :=  cpu .GetMems (); v  !=  ""  {
977- 			if  err  :=  r .owners .ClaimCPUSetMems (id , plugin ); err  !=  nil  {
978- 				return  err 
979- 			}
980- 			resources .Cpu .Mems  =  v 
981- 		}
943+ 
944+ 	if  err  :=  r .adjustCPUResource (u .Linux .Resources .Cpu , resources .Cpu , nil , id , plugin ); err  !=  nil  {
945+ 		return  err 
982946	}
983947
984948	for  _ , l  :=  range  u .Linux .Resources .HugepageLimits  {
0 commit comments