As for David's son, God assures David that he will benefit from a special providence from Him. This providential relationship is expressed through a father-son metaphor. God will be like a father to him and David's son will be like a son to Him. Specifically, in so far as if he becomes corrupt God will chastise him with the 'rod of men' and the afflictions of humans. And, even if he does become corrupt God's chesed - literally: kindness, often used to refer to a b'rit, covenant in 1 & 2 Samuel - would not depart from his line - meaning, David's dynasty would continue uninterrupted in perpetuity.
As for the "son" metaphor I think the sense is clear from Psalms (2):
5. Then He speaks to them in His wrath; and He frightens them with His sore displeasure.Commenting on "You are My son", Rashi writes:
6. "But I have enthroned My king on Zion, My holy mount."
7. I will tell of the decree; The Lord said to me, "You are My son; this day have I begotten you.
8. Request of Me, and I will make nations your inheritance, and the ends of the earth your possession.
9. You shall break them with an iron rod; like a potter's vessel you shall shatter them."
You are My son, the head of Israel, who are called in the Torah (Exodus, 4:22), "My firstborn son", and they will endure through you, as is stated concerning Abner (I2 Sam. 3:18): “for God said, etc., ‘By the hand of My servant David shall I save My people Israel.’”, and for their sake, you are before Me as a son, because they are all dependent upon you.
Rashi sounds somewhat convoluted at first. The more obvious interpretation is that the king is called a son because he shares a special providential relationship with God. However, Rashi is reminding us that this simple interpretation would be ignoring God's relationship with all of His people and the true origin of the "son" metaphor. Israel emerged out of a society that deified their king and viewed him as either a son or an incarnation of a god. God tells Moshe (in Exodus, 4:22) that in response to Pharaoh hardening his heart he is to tell him, "My firstborn son is Israel." Though, in a sense, all of humanity and all nations are God's "children" in regards to His providence - Israel is the firstborn - the one God has chosen to impart His inheritance and show special favor. Rashi is saying that the king's status as "son" must be viewed within this context. The king is only a "son" for the sake of the people.
In summary, to understand the "son" metaphor we must take note of the following: a son shares a privileged status: favor, when the son is virtuous (as in Psalms 2 and Exodus 4); chastisement, when he is corrupt (as in 2 Samuel 7); and even the corrupt son does not lose his father's chesed - meaning, the relationship (in 2 Samuel, the Davidic covenant) will never be absolutely severed.